-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.rb
56 lines (46 loc) · 1.9 KB
/
progress.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
# Gets how many cumulative completed increments there were per practice session
def progress_data(practice_sessions, select_proc=nil)
progress_data = {
"TK": [],
"LIK": []
}
practice_sessions.sort { |ps1, ps2| ps1.number <=> ps2.number }.each do |ps|
completed_increments = practice_session_completed_increments(ps)
if select_proc
completed_increments.select! { |ci| select_proc.call(ci) }
end
completed_increment_count = completed_increments.count
acronym = find(:keyboards, ps.keyboard).acronym.to_sym
cumulative_completed_increment_count = progress_data[acronym].last ? progress_data[acronym].last + completed_increment_count : completed_increment_count
progress_data[acronym].push(cumulative_completed_increment_count)
end
labels = practice_sessions.sort { |ps1, ps2| ps1.number <=> ps2.number }.map(&:number).uniq
# We can do this for tighter ones.
# labels = labels.map { |label| label.to_i % 2 == 0 ? label : ""}
return {
series: [progress_data[:TK], progress_data[:LIK]],
labels: labels,
}
end
def all_progress
progress_data(data.practice_sessions)
end
def progress_until_practice_session(practice_session)
final_number = practice_session.number
practice_sessions = data.practice_sessions.select { |ps| ps.number <= final_number }
progress_data(practice_sessions)
end
def domain_progress(domain, practice_sessions=data.practice_sessions)
# if practice_sessions.nil?
# practice_sessions = data.practice_sessions
# end
select_proc = proc { |ci| find(:domains, ci.domain) == domain }
progress_data(practice_sessions, select_proc)
end
def exercise_set_progress(exercise_set, practice_sessions=data.practice_sessions)
# if practice_sessions.nil?
# practice_sessions = data.practice_sessions
# end
select_proc = proc { |ci| find(:exercise_sets, ci.exercise_set) == exercise_set }
progress_data(practice_sessions, select_proc)
end