-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dataset.jl
55 lines (47 loc) · 1.27 KB
/
Dataset.jl
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
53
54
struct Dataset
name::String
eventmap::Dict{String,Tuple{Int64,Int64}}
Dataset(n) = new(n,Dict{String,Tuple{Int64,Int64}}())
end
function addFile(d::Dataset,f::String)
if !haskey(d.eventmap,f)
d.eventmap[f] = (0,0)
end
end
function addFile(d::Dataset,f::String,l::Tuple{Int64,Int64})
if !haskey(d.eventmap,f)
d.eventmap[f] = l
end
end
function setEventRange(d::Dataset,f::String,l::Tuple{Int64,Int64})
d.eventmap[f] = l
end
function print(d::Dataset)
println(d.name)
for (key,val) in d.eventmap
println(string(key,": events ", val[1], " - ",val[2]))
end
end
function writeToFile(d::Dataset,fname::String)
open(fname, "w") do f
i = 0
for (key,val) in d.eventmap
if i == 0
write(f, string(key,",", val[1], ",",val[2]))
else
write(f, string("\n",key,",", val[1], ",",val[2]))
end
i+=1
end
end
end
function hasFile(d::Dataset,fname::String)
return haskey(d.eventmap,fname)
end
function setData(d::Dataset,fname::String)
#read dataset file to load dataset
for line in readlines(fname)
data = split(line,",")
addFile(d,String(data[1]),(parse(Int64,data[2]),parse(Int64,data[3])))
end
end