-
Notifications
You must be signed in to change notification settings - Fork 1
/
addID-Video.rb
52 lines (47 loc) · 1.21 KB
/
addID-Video.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'Datavyu_API'
require 'securerandom'
$inputDir = "~/Documents/Projects/Bergelson Lab/annotation/video_with_pho"
$outputDir = "~/Documents/Projects/Bergelson Lab/annotation/video_with_pho_output"
def randomID
randID = SecureRandom.uuid
return randID[0..7] + randID[9]
end
def printCode(*code)
columnName = get_column_list[0]
theColumn = get_column(columnName)
for cell in theColumn.cells
p cell.get_codes(code)
end
end
def addID(dir, file, outDir)
$db, $pj = load_db(File.join(dir, file))
columnName = get_column_list[0]
theColumn = get_column(columnName)
theColumn.add_code('id')
for cell in theColumn.cells
cell.change_code('id', randomID)
end
set_column(theColumn)
save_db(File.join(outDir, file))
end
begin
outDir = File.expand_path($outputDir)
dataDir = File.expand_path($inputDir)
files = Dir.new(dataDir).entries.sort
counter = 0
errorFile = Array.new
for file in files
if file.end_with? ('.opf')
begin
addID(dataDir, file, outDir)
rescue
errorFile << file
print("Error with file: ", file, "\n")
end
end
counter += 1
print("Finished: ", counter/(files.size.to_f-2)*100, "\n")
end
print("Had problem with: \n")
p errorFile
end