Class: PostRunner::ChartView

Inherits:
Object
  • Object
show all
Defined in:
lib/postrunner/ChartView.rb

Instance Method Summary collapse

Constructor Details

#initialize(activity, unit_system) ⇒ ChartView

Returns a new instance of ChartView.



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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/postrunner/ChartView.rb', line 19

def initialize(activity, unit_system)
  @activity = activity
  @sport = activity.sport
  @unit_system = unit_system
  @empty_charts = {}
  @hrv_analyzer = HRV_Analyzer.new(@activity.fit_activity)

  @charts = [
    {
      :id => 'pace',
      :label => 'Pace',
      :unit => select_unit('min/km'),
      :graph => :line_graph,
      :colors => '#0A7BEE',
      :show => @sport == 'running' || @sport = 'multisport',
    },
    {
      :id => 'speed',
      :label => 'Speed',
      :unit => select_unit('km/h'),
      :graph => :line_graph,
      :colors => '#0A7BEE',
      :show => @sport != 'running'
    },
    {
      :id => 'altitude',
      :label => 'Elevation',
      :unit => select_unit('m'),
      :graph => :line_graph,
      :colors => '#5AAA44',
      :show => @activity.sub_sport != 'treadmill'
    },
    {
      :id => 'heart_rate',
      :label => 'Heart Rate',
      :unit => 'bpm',
      :graph => :line_graph,
      :colors => '#900000',
      :show => true
    },
    {
      :id => 'hrv',
      :label => 'Heart Rate Variability',
      :short_label => 'HRV',
      :unit => 'ms',
      :graph => :line_graph,
      :colors => '#900000',
      :show => @hrv_analyzer.has_hrv_data?
    },
    {
      :id => 'hrv_score',
      :label => 'HRV Score (30s Window)',
      :short_label => 'HRV Score',
      :graph => :line_graph,
      :colors => '#900000',
      :show => false
    },
    {
      :id => 'run_cadence',
      :label => 'Run Cadence',
      :unit => 'spm',
      :graph => :point_graph,
      :colors => [ [ '#EE3F2D', 151 ], [ '#F79666', 163 ],
                   [ '#A0D488', 174 ], [ '#96D7DE', 185 ],
                   [ '#A88BBB', nil ] ],
      :show => @sport == 'running' || @sport == 'multisport'
    },
    {
      :id => 'stride_length',
      :label => 'Stride Length',
      :unit => select_unit('m'),
      :graph => :point_graph,
      :colors => [ ['#506DE1', nil ] ],
      :show => @sport == 'running' || @sport == 'multisport'
    },
    {
      :id => 'vertical_oscillation',
      :label => 'Vertical Oscillation',
      :short_label => 'Vert. Osc.',
      :unit => select_unit('cm'),
      :graph => :point_graph,
      :colors => [ [ '#A88BBB', 67 ], [ '#96D7DE', 84 ],
                   [ '#A0D488', 101 ], [ '#F79666', 118 ],
                   [ '#EE3F2D', nil ] ],
      :show => @sport == 'running' || @sport == 'multisport'
    },
    {
      :id => 'vertical_ratio',
      :label => 'Vertical Ratio',
      :unit => '%',
      :graph => :point_graph,
      :colors => [ [ '#CF45BD', 6.1 ], [ '#4FBEED', 7.4 ],
                   [ '#6AB03A', 8.6 ], [ '#EDA14F', 10.1 ],
                   [ '#FF5558', nil ] ],
      :show => @sport == 'running' || @sport == 'multisport'
    },
    {
      :id => 'stance_time',
      :label => 'Ground Contact Time',
      :short_label => 'GCT',
      :unit => 'ms',
      :graph => :point_graph,
      :colors => [ [ '#A88BBB', 208 ], [ '#96D7DE', 241 ],
                   [ '#A0D488', 273 ], [ '#F79666', 305 ],
                   [ '#EE3F2D', nil ] ],
      :show => @sport == 'running' || @sport == 'multisport'
    },
    {
      :id => 'gct_balance',
      :label => 'Ground Contact Time Balance',
      :short_label => 'GCT Balance',
      :unit => '%',
      :graph => :point_graph,
      :colors => [ [ '#FF5558', 47.8 ], [ '#EDA14F', 49.2 ],
                   [ '#6AB03A', 50.7 ], [ '#EDA14F', 52.2 ],
                   [ '#FF5558', nil ] ],
      :show => @sport == 'running' || @sport == 'multisport'
    },
    {
      :id => 'cadence',
      :label => 'Cadence',
      :unit => 'rpm',
      :graph => :line_graph,
      :colors => '#A88BBB',
      :show => @sport == 'cycling'
    },
    {
      :id => 'temperature',
      :label => 'Temperature',
      :short_label => 'Temp.',
      :unit => 'C',
      :graph => :line_graph,
      :colors => '#444444',
      :show => true
    }
  ]
end

Instance Method Details

#to_html(doc) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/postrunner/ChartView.rb', line 157

def to_html(doc)
  doc.unique(:chartview_style) {
    doc.head {
      doc.style(style)
    }
  }
  doc.script(java_script)
  @charts.each do |chart|
    label = chart[:label] + (chart[:unit] ? " (#{chart[:unit]})" : '')
    chart_div(doc, chart[:id], label) if chart[:show]
  end
end