summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2014-08-30 22:34:38 +0200
committerChris Schlaeger <chris@linux.com>2014-08-30 22:34:38 +0200
commitb7055f4c4b3522aeef095baf6ec464679f28d88d (patch)
tree15d82985edbea6110bb53a87a015364fb8720d1c /lib
parent7d0f1effd35a6b65bec9e65cff9ccbe1d6ad02ea (diff)
downloadpostrunner-b7055f4c4b3522aeef095baf6ec464679f28d88d.zip
Only show pace for running, speed otherwise.
Diffstat (limited to 'lib')
-rw-r--r--lib/postrunner/Activity.rb6
-rw-r--r--lib/postrunner/ActivityListView.rb6
-rw-r--r--lib/postrunner/ActivitySummary.rb36
-rw-r--r--lib/postrunner/ChartView.rb15
4 files changed, 44 insertions, 19 deletions
diff --git a/lib/postrunner/Activity.rb b/lib/postrunner/Activity.rb
index de4396b..87c1daa 100644
--- a/lib/postrunner/Activity.rb
+++ b/lib/postrunner/Activity.rb
@@ -23,7 +23,7 @@ module PostRunner
# This is a list of variables that provide data from the fit file. To
# speed up access to it, we cache the data in the activity database.
- @@CachedVariables = %w( timestamp total_distance total_timer_time
+ @@CachedVariables = %w( sport timestamp total_distance total_timer_time
avg_speed )
def initialize(db, fit_file, fit_activity, name = nil)
@@ -45,6 +45,8 @@ module PostRunner
@db = db
@html_dir = File.join(@db.db_dir, 'html')
@html_file = File.join(@html_dir, "#{@fit_file[0..-5]}.html")
+ #@fit_activity = load_fit_file
+ #@sport = @fit_activity.sessions[0].sport
end
def check
@@ -69,7 +71,7 @@ module PostRunner
end
def encode_with(coder)
- attr_ignore = %w( @db @fit_activity )
+ attr_ignore = %w( @db @fit_activity @html_dir @html_file )
instance_variables.each do |v|
v = v.to_s
diff --git a/lib/postrunner/ActivityListView.rb b/lib/postrunner/ActivityListView.rb
index 61275da..3c9f473 100644
--- a/lib/postrunner/ActivityListView.rb
+++ b/lib/postrunner/ActivityListView.rb
@@ -134,7 +134,7 @@ EOT
i = @page_no < 0 ? 0 : @page_no * @page_size
t = FlexiTable.new
t.head
- t.row(%w( Ref. Activity Start Distance Duration Pace ),
+ t.row(%w( Ref. Activity Start Distance Duration Speed/Pace ),
{ :halign => :left })
t.set_column_attributes([
{ :halign => :right },
@@ -155,7 +155,9 @@ EOT
local_value(a.total_distance, 'm', '%.2f',
{ :metric => 'km', :statute => 'mi' }),
secsToHMS(a.total_timer_time),
- pace(a.avg_speed) ])
+ a.sport == 'running' ? pace(a.avg_speed) :
+ local_value(a.avg_speed, 'm/s', '%.1f',
+ { :metric => 'km/h', :statute => 'mph' }) ])
end
t
diff --git a/lib/postrunner/ActivitySummary.rb b/lib/postrunner/ActivitySummary.rb
index c1f5771..ed4cbf5 100644
--- a/lib/postrunner/ActivitySummary.rb
+++ b/lib/postrunner/ActivitySummary.rb
@@ -29,16 +29,12 @@ module PostRunner
end
def to_s
- session = @fit_activity.sessions[0]
-
- summary(session).to_s + "\n" + laps.to_s
+ summary.to_s + "\n" + laps.to_s
end
def to_html(doc)
- session = @fit_activity.sessions[0]
-
frame(doc, "Activity: #{@name}") {
- summary(session).to_html(doc)
+ summary.to_html(doc)
}
frame(doc, 'Laps') {
laps.to_html(doc)
@@ -47,7 +43,9 @@ module PostRunner
private
- def summary(session)
+ def summary
+ session = @fit_activity.sessions[0]
+
t = FlexiTable.new
t.enable_frame(false)
t.body
@@ -56,7 +54,13 @@ module PostRunner
local_value(session, 'total_distance', '%.2f %s',
{ :metric => 'km', :statute => 'mi'}) ])
t.row([ 'Time:', secsToHMS(session.total_timer_time) ])
- t.row([ 'Avg. Pace:', pace(session, 'avg_speed') ])
+ if session.sport == 'running'
+ t.row([ 'Avg. Pace:', pace(session, 'avg_speed') ])
+ else
+ t.row([ 'Avg. Speed:',
+ local_value(session, 'avg_speed', '%.1f %s',
+ { :metric => 'km/h', :statute => 'mph' }) ])
+ end
t.row([ 'Total Ascent:',
local_value(session, 'total_ascent', '%.0f %s',
{ :metric => 'm', :statute => 'ft' }) ])
@@ -91,18 +95,26 @@ module PostRunner
end
def laps
+ session = @fit_activity.sessions[0]
+
t = FlexiTable.new
t.head
- t.row([ 'Lap', 'Duration', 'Distance', 'Avg. Pace', 'Stride', 'Cadence',
- 'Avg. HR', 'Max. HR' ])
+ t.row([ 'Lap', 'Duration', 'Distance',
+ session.sport == 'running' ? 'Avg. Pace' : 'Avg. Speed',
+ 'Stride', 'Cadence', 'Avg. HR', 'Max. HR' ])
t.set_column_attributes(Array.new(8, { :halign => :right }))
t.body
- @fit_activity.sessions[0].laps.each.with_index do |lap, index|
+ session.laps.each.with_index do |lap, index|
t.cell(index + 1)
t.cell(secsToHMS(lap.total_timer_time))
t.cell(local_value(lap, 'total_distance', '%.2f',
{ :metric => 'km', :statute => 'mi' }))
- t.cell(pace(lap, 'avg_speed', false))
+ if session.sport == 'running'
+ t.cell(pace(lap, 'avg_speed', false))
+ else
+ t.cell(local_value(lap, 'avg_speed', '%.1f',
+ { :metric => 'km/h', :statute => 'mph' }))
+ end
t.cell(local_value(lap, 'avg_stride_length', '%.2f',
{ :metric => 'm', :statute => 'ft' }))
t.cell(lap.avg_running_cadence && lap.avg_fractional_cadence ?
diff --git a/lib/postrunner/ChartView.rb b/lib/postrunner/ChartView.rb
index c0aac30..208bc17 100644
--- a/lib/postrunner/ChartView.rb
+++ b/lib/postrunner/ChartView.rb
@@ -20,6 +20,7 @@ module PostRunner
def initialize(activity, unit_system)
@activity = activity
+ @sport = activity.fit_activity.sessions[0].sport
@unit_system = unit_system
@empty_charts = {}
end
@@ -35,7 +36,11 @@ module PostRunner
end
def div(doc)
- chart_div(doc, 'pace', "Pace (#{select_unit('min/km')})")
+ if @sport == 'running'
+ chart_div(doc, 'pace', "Pace (#{select_unit('min/km')})")
+ else
+ chart_div(doc, 'speed', "Speed (#{select_unit('km/h')})")
+ end
chart_div(doc, 'altitude', "Elevation (#{select_unit('m')})")
chart_div(doc, 'heart_rate', 'Heart Rate (bpm)')
chart_div(doc, 'run_cadence', 'Run Cadence (spm)')
@@ -51,7 +56,7 @@ module PostRunner
when :metric
metric_unit
when :statute
- { 'min/km' => 'min/mi', 'm' => 'ft', 'cm' => 'in',
+ { 'min/km' => 'min/mi', 'm' => 'ft', 'cm' => 'in', 'km/h' => 'mph',
'bpm' => 'bpm', 'spm' => 'spm', 'ms' => 'ms' }[metric_unit]
else
Log.fatal "Unknown unit system #{@unit_system}"
@@ -92,7 +97,11 @@ EOT
s = "$(function() {\n"
s << tooltip_div
- s << line_graph('pace', 'Pace', 'min/km', '#0A7BEE' )
+ if @sport == 'running'
+ s << line_graph('pace', 'Pace', 'min/km', '#0A7BEE' )
+ else
+ s << line_graph('speed', 'Speed', 'km/h', '#0A7BEE' )
+ end
s << line_graph('altitude', 'Elevation', 'm', '#5AAA44')
s << line_graph('heart_rate', 'Heart Rate', 'bpm', '#900000')
s << point_graph('run_cadence', 'Run Cadence', 'spm',