-
Notifications
You must be signed in to change notification settings - Fork 2
/
statistics.rb
63 lines (53 loc) · 1.09 KB
/
statistics.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
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/ruby
require 'storage'
require 'gnuplot'
exit if ARGV.size != 1
s = Storage.new(ARGV[0])
Gnuplot.open { |gp|
Gnuplot::Plot.new(gp) { |plot|
plot.title "#{ARGV[0]} statistics"
plot.ylabel "Bacteria count"
plot.xlabel "Time"
t = []
vs = []
ls = []
as = []
begin
t.push s.step
print '.'; STDOUT.flush
vsc = 0
lsc = 0
asc = 0
stat = s.stat
stat.each_key { |key|
case key
when CELL_GOOD_RANGE then lsc += stat[key]
when CELL_VIRUS_RANGE then vsc += stat[key]
when CELL_ANTIBODY_RANGE then asc += stat[key]
end
}
vs.push vsc
as.push asc
ls.push lsc
s.get_next_step_if_exists!
end while not s.final_step?
plot.data = [
Gnuplot::DataSet.new( [t, ls] ) { |ds|
ds.with = "linespoints"
ds.title = "Life forms"
ds.linecolor = "2"
},
Gnuplot::DataSet.new( [t, vs] ) { |ds|
ds.with = "linespoints"
ds.title = "Viruses"
ds.linecolor = "1"
},
Gnuplot::DataSet.new( [t, as] ) { |ds|
ds.with = "linespoints"
ds.title = "Antibodies"
ds.linecolor = "6"
}
]
}
}
puts