summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/postrunner/ActivitiesDB.rb8
-rw-r--r--lib/postrunner/Activity.rb25
-rw-r--r--lib/postrunner/ActivityView.rb13
3 files changed, 24 insertions, 22 deletions
diff --git a/lib/postrunner/ActivitiesDB.rb b/lib/postrunner/ActivitiesDB.rb
index e4f8b6b..759bec6 100644
--- a/lib/postrunner/ActivitiesDB.rb
+++ b/lib/postrunner/ActivitiesDB.rb
@@ -46,11 +46,11 @@ module PostRunner
Log.fatal "The archive file '#{@archive_file}' is corrupted"
end
- # The reference to this object is needed inside Activity object but is
- # not stored in the archive file. We have to retrofit the Activity
- # instances with this data.
+ # Not all instance variables of Activity are stored in the file. The
+ # normal constructor is not run during YAML::load_file. We have to
+ # initialize those instance variables in a secondary step.
@activities.each do |a|
- a.db = self
+ a.late_init(self)
end
@records = PersonalRecords.new(self)
diff --git a/lib/postrunner/Activity.rb b/lib/postrunner/Activity.rb
index 5a7607f..3fe0bfd 100644
--- a/lib/postrunner/Activity.rb
+++ b/lib/postrunner/Activity.rb
@@ -19,7 +19,7 @@ module PostRunner
class Activity
- attr_reader :fit_file, :name, :fit_activity
+ attr_reader :fit_file, :name, :fit_activity, :html_dir, :html_file
attr_accessor :db
# This is a list of variables that provide data from the fit file. To
@@ -28,10 +28,10 @@ module PostRunner
avg_speed )
def initialize(db, fit_file, fit_activity, name = nil)
- @db = db
@fit_file = fit_file
@fit_activity = fit_activity
@name = name || fit_file
+ late_init(db)
@@CachedVariables.each do |v|
v_str = "@#{v}"
@@ -40,9 +40,17 @@ module PostRunner
end
end
+ def late_init(db)
+ @db = db
+ @html_dir = File.join(@db.db_dir, 'html')
+ @html_file = File.join(@html_dir, "#{@fit_file[0..-5]}.html")
+ end
+
def check
@fit_activity = load_fit_file
Log.info "FIT file #{@fit_file} is OK"
+ # Re-generate the HTML file for this activity
+ ActivityView.new(self)
end
def dump(filter)
@@ -74,11 +82,14 @@ module PostRunner
def show
@fit_activity = load_fit_file unless @fit_activity
- view = ActivityView.new(self, File.join(@db.db_dir, 'html'))
- #view = TrackView.new(self, '../../html')
- #view.generate_html
- #chart = ChartView.new(self, '../../html')
- #chart.generate_html
+
+ ActivityView.new(self) unless File.exists?(@html_file)
+
+ cmd = "#{ENV['BROWSER'] || 'firefox'} \"#{@html_file}\" &"
+ unless system(cmd)
+ Log.fatal "Failed to execute the following shell command: #{$cmd}\n" +
+ "#{$!}"
+ end
end
def summary
diff --git a/lib/postrunner/ActivityView.rb b/lib/postrunner/ActivityView.rb
index 4abed85..43e8461 100644
--- a/lib/postrunner/ActivityView.rb
+++ b/lib/postrunner/ActivityView.rb
@@ -24,9 +24,9 @@ module PostRunner
include ViewWidgets
- def initialize(activity, output_dir)
+ def initialize(activity)
@activity = activity
- @output_dir = output_dir
+ @output_dir = activity.html_dir
@output_file = nil
ensure_output_dir
@@ -34,7 +34,6 @@ module PostRunner
@doc = HTMLBuilder.new
generate_html(@doc)
write_file
- show_in_browser
end
private
@@ -143,14 +142,6 @@ EOT
end
end
- def show_in_browser
- cmd = "#{ENV['BROWSER'] || 'firefox'} \"#{@output_file}\" &"
- unless system(cmd)
- Log.fatal "Failed to execute the following shell command: #{$cmd}\n" +
- "#{$!}"
- end
- end
-
end
end