summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2015-06-14 19:36:39 +0200
committerChris Schlaeger <chris@linux.com>2015-06-14 19:36:39 +0200
commit88e1f74afee93c19f889ce8254f305a1f0ecf664 (patch)
tree93063caf4a2319bbc4af6aa831fc5115828b40fc /lib
parentded02799b9b0285962152fb48816c5ea56744830 (diff)
downloadpostrunner-88e1f74afee93c19f889ce8254f305a1f0ecf664.zip
Fix: Don't crash on temporary pace/speed dropouts.
Diffstat (limited to 'lib')
-rw-r--r--lib/postrunner/ChartView.rb3
-rw-r--r--lib/postrunner/QueryResult.rb36
-rw-r--r--lib/postrunner/Schema.rb62
3 files changed, 101 insertions, 0 deletions
diff --git a/lib/postrunner/ChartView.rb b/lib/postrunner/ChartView.rb
index 54b6a44..a9b408c 100644
--- a/lib/postrunner/ChartView.rb
+++ b/lib/postrunner/ChartView.rb
@@ -163,6 +163,9 @@ EOT
min_value = nil
@activity.fit_activity.records.each do |r|
value = r.get_as(field, select_unit(unit))
+
+ next unless value
+
if field == 'pace'
# Slow speeds lead to very large pace values that make the graph
# hard to read. We cap the pace at 20.0 min/km to keep it readable.
diff --git a/lib/postrunner/QueryResult.rb b/lib/postrunner/QueryResult.rb
new file mode 100644
index 0000000..7341438
--- /dev/null
+++ b/lib/postrunner/QueryResult.rb
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby -w
+# encoding: UTF-8
+#
+# = QueryResult.rb -- PostRunner - Manage the data from your Garmin sport devices.
+#
+# Copyright (c) 2015 by Chris Schlaeger <cs@taskjuggler.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+
+module PostRunner
+
+ # Queries provide an abstract interface to retrieve individual values from
+ # Activities, Laps and so on. The result of a query is returned as a
+ # QueryResult object.
+ class QueryResult
+
+ # Create a QueryResult object.
+ # @param value [any] Result of the query
+ # @param schema [Schema] A reference to the Schema of the queried
+ # attribute.
+ def initialize(value, schema)
+ @value = value
+ @schema = schema
+ end
+
+ # Conver the result into a text String.
+ def to_s
+ @schema.to_s(@value)
+ end
+
+ end
+
+end
diff --git a/lib/postrunner/Schema.rb b/lib/postrunner/Schema.rb
new file mode 100644
index 0000000..629dfc6
--- /dev/null
+++ b/lib/postrunner/Schema.rb
@@ -0,0 +1,62 @@
+#!/usr/bin/env ruby -w
+# encoding: UTF-8
+#
+# = Schema.rb -- PostRunner - Manage the data from your Garmin sport devices.
+#
+# Copyright (c) 2015 by Chris Schlaeger <cs@taskjuggler.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+
+module PostRunner
+
+ # A Schema provides a unified way to query and process diverse data types.
+ class Schema
+
+ attr_reader :key, :name,
+ :func, :column_alignment, :metric_unit, :imperial_unit
+
+ # Create a Schema object.
+ # @param key [Symbol] The globally unique identifier for the object
+ # @param name [String] A human readable name to describe the object
+ # @param opts [Hash] A Hash with values to overwrite the default values
+ # of some instance variables.
+ def initialize(key, name, opts = {})
+ @key = key
+ @name = name
+
+ # Default values for optional variables
+ @func = nil
+ @format = nil
+ @column_alignment = :right
+ @metric_unit = nil
+ @imperial_unit = nil
+
+ # Overwrite the default value for optional variables that have values
+ # provided in opts.
+ opts.each do |on, ov|
+ if instance_variable_defined?('@' + on.to_s)
+ instance_variable_set('@' + on.to_s, ov)
+ else
+ raise ArgumentError, "Unknown instance variable '#{on}'"
+ end
+ end
+ end
+
+ def to_s(value)
+ value = send(@format, value) if @format
+ value.to_s
+ end
+
+ private
+
+ def date_with_weekday(timestamp)
+ timestamp.strftime('%a, %Y %b %d %H:%M')
+ end
+
+ end
+
+end
+