This repository has been archived by the owner on Dec 23, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
/
dashboard_worker.rb
56 lines (48 loc) · 1.5 KB
/
dashboard_worker.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
module DashboardWorker # mixin
include TimeNow
def animals_progress
animals = { }
avatars.active.each do |avatar|
animals[avatar.name] = {
colour: avatar.lights[-1].colour,
progress: most_recent_progress(avatar)
}
end
animals
end
def gather
@kata = kata
@minute_columns = bool('minute_columns')
@auto_refresh = bool('auto_refresh')
all_lights = Hash[
@kata.avatars.active.each.collect{|avatar| [avatar.name, avatar.lights]}
]
max_seconds_uncollapsed = seconds_per_column * 5
gapper = TdGapper.new(@kata.created, seconds_per_column, max_seconds_uncollapsed)
@gapped = gapper.fully_gapped(all_lights, time_now)
@progress = @kata.language.progress_regexs != [ ]
@avatar_names = @kata.avatars.active.map{|avatar| avatar.name}.sort
end
def bool(attribute)
tf = params[attribute]
tf == 'false' ? tf : 'true'
end
def seconds_per_column
flag = params['minute_columns']
# default is that time-gaps are on
return 60 if flag.nil? || flag == 'true'
return 60*60*24*365*1000
end
def most_recent_progress(avatar)
regexs = avatar.kata.language.progress_regexs
non_amber = avatar.lights.reverse.find{ |light|
[:red,:green].include?(light.colour)
}
output = (non_amber != nil) ? non_amber.tag.output : ''
matches = regexs.map{|regex| Regexp.new(regex).match(output)}
return {
text: matches.join,
colour: (matches[0] != nil ? 'red' : 'green')
}
end
end