summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/postrunner/ActivitiesDB.rb17
-rw-r--r--lib/postrunner/Activity.rb34
-rw-r--r--lib/postrunner/ActivityListView.rb4
-rw-r--r--lib/postrunner/RuntimeConfig.rb12
4 files changed, 51 insertions, 16 deletions
diff --git a/lib/postrunner/ActivitiesDB.rb b/lib/postrunner/ActivitiesDB.rb
index b6516e7..7f75fa6 100644
--- a/lib/postrunner/ActivitiesDB.rb
+++ b/lib/postrunner/ActivitiesDB.rb
@@ -76,9 +76,9 @@ module PostRunner
# files. This method is idempotent and can be called even when directories
# exist already.
def create_directories
- create_directory(@db_dir, 'data')
- create_directory(@fit_dir, 'fit')
- create_directory(@cfg[:html_dir], 'html')
+ @cfg.create_directory(@db_dir, 'data')
+ @cfg.create_directory(@fit_dir, 'fit')
+ @cfg.create_directory(@cfg[:html_dir], 'html')
@auxilliary_dirs.each do |dir|
create_auxdir(dir)
@@ -344,17 +344,6 @@ module PostRunner
ActivityListView.new(self).update_index_pages
end
- def create_directory(dir, name)
- return if Dir.exists?(dir)
-
- Log.info "Creating #{name} directory #{dir}"
- begin
- Dir.mkdir(dir)
- rescue StandardError
- Log.fatal "Cannot create #{name} directory #{dir}: #{$!}"
- end
- end
-
def create_auxdir(dir)
# This file should be in lib/postrunner. The 'misc' directory should be
# found in '../../misc'.
diff --git a/lib/postrunner/Activity.rb b/lib/postrunner/Activity.rb
index b4a38f4..ff36d53 100644
--- a/lib/postrunner/Activity.rb
+++ b/lib/postrunner/Activity.rb
@@ -14,6 +14,8 @@ require 'fit4ruby'
require 'postrunner/ActivitySummary'
require 'postrunner/ActivityView'
+require 'postrunner/Schema'
+require 'postrunner/QueryResult'
module PostRunner
@@ -28,6 +30,19 @@ module PostRunner
# We also store some additional information in the archive index.
@@CachedAttributes = @@CachedActivityValues + %w( fit_file name )
+ @@Schemata = {
+ 'long_date' => Schema.new('long_date', 'Date',
+ { :func => 'timestamp',
+ :column_alignment => :left,
+ :format => 'date_with_weekday' }),
+ 'sub_type' => Schema.new('sub_type', 'Subtype',
+ { :func => 'activity_sub_type',
+ :column_alignment => :left }),
+ 'type' => Schema.new('type', 'Type',
+ { :func => 'activity_type',
+ :column_alignment => :left })
+ }
+
ActivityTypes = {
'generic' => 'Generic',
'running' => 'Running',
@@ -159,6 +174,25 @@ module PostRunner
end
end
+ def query(key)
+ unless @@Schemata.include?(key)
+ raise ArgumentError, "Unknown key '#{key}' requested in query"
+ end
+
+ schema = @@Schemata[key]
+
+ if schema.func
+ value = send(schema.func)
+ else
+ unless instance_variable_defined?(key)
+ raise ArgumentError, "Don't know how to query '#{key}'"
+ end
+ value = instance_variable_get(key)
+ end
+
+ QueryResult.new(value, schema)
+ end
+
def show
generate_html_view #unless File.exists?(@html_file)
diff --git a/lib/postrunner/ActivityListView.rb b/lib/postrunner/ActivityListView.rb
index 8027cb0..8e38b93 100644
--- a/lib/postrunner/ActivityListView.rb
+++ b/lib/postrunner/ActivityListView.rb
@@ -92,8 +92,8 @@ module PostRunner
t.row([
i += 1,
ActivityLink.new(a, true),
- a.activity_type,
- a.timestamp.strftime("%a, %Y %b %d %H:%M"),
+ a.query('type'),
+ a.query('long_date'),
local_value(a.total_distance, 'm', '%.2f',
{ :metric => 'km', :statute => 'mi' }),
secsToHMS(a.total_timer_time),
diff --git a/lib/postrunner/RuntimeConfig.rb b/lib/postrunner/RuntimeConfig.rb
index cd297e0..a090683 100644
--- a/lib/postrunner/RuntimeConfig.rb
+++ b/lib/postrunner/RuntimeConfig.rb
@@ -56,6 +56,18 @@ module PostRunner
save_options
end
+ # Ensure that the requested directory exists.
+ def create_directory(dir, name)
+ return if Dir.exists?(dir)
+
+ Log.info "Creating #{name} directory #{dir}"
+ begin
+ Dir.mkdir(dir)
+ rescue StandardError
+ Log.fatal "Cannot create #{name} directory #{dir}: #{$!}"
+ end
+ end
+
private
def load_options