Class: PostRunner::Activity
- Inherits:
-
Object
- Object
- PostRunner::Activity
- Defined in:
- lib/postrunner/Activity.rb
Constant Summary collapse
- @@CachedVariables =
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.
%w( timestamp total_distance total_timer_time avg_speed )
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
-
#fit_activity ⇒ Object
readonly
Returns the value of attribute fit_activity.
-
#fit_file ⇒ Object
readonly
Returns the value of attribute fit_file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #check ⇒ Object
- #dump(filter) ⇒ Object
- #encode_with(coder) ⇒ Object
-
#initialize(db, fit_file, fit_activity, name = nil) ⇒ Activity
constructor
A new instance of Activity.
- #register_records(db) ⇒ Object
- #rename(name) ⇒ Object
- #show ⇒ Object
- #summary ⇒ Object
- #yaml_initialize(tag, value) ⇒ Object
Constructor Details
#initialize(db, fit_file, fit_activity, name = nil) ⇒ Activity
Returns a new instance of Activity.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/postrunner/Activity.rb', line 18 def initialize(db, fit_file, fit_activity, name = nil) @db = db @fit_file = fit_file @fit_activity = fit_activity @name = name || fit_file @@CachedVariables.each do |v| v_str = "@#{v}" instance_variable_set(v_str, fit_activity.send(v)) self.class.send(:attr_reader, v.to_sym) end end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
11 12 13 |
# File 'lib/postrunner/Activity.rb', line 11 def db @db end |
#fit_activity ⇒ Object (readonly)
Returns the value of attribute fit_activity.
10 11 12 |
# File 'lib/postrunner/Activity.rb', line 10 def fit_activity @fit_activity end |
#fit_file ⇒ Object (readonly)
Returns the value of attribute fit_file.
10 11 12 |
# File 'lib/postrunner/Activity.rb', line 10 def fit_file @fit_file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/postrunner/Activity.rb', line 10 def name @name end |
Instance Method Details
#check ⇒ Object
31 32 33 34 |
# File 'lib/postrunner/Activity.rb', line 31 def check @fit_activity = load_fit_file Log.info "FIT file #{@fit_file} is OK" end |
#dump(filter) ⇒ Object
36 37 38 |
# File 'lib/postrunner/Activity.rb', line 36 def dump(filter) @fit_activity = load_fit_file(filter) end |
#encode_with(coder) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/postrunner/Activity.rb', line 52 def encode_with(coder) attr_ignore = %w( @db @fit_activity ) instance_variables.each do |v| v = v.to_s next if attr_ignore.include?(v) coder[v[1..-1]] = instance_variable_get(v) end end |
#register_records(db) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/postrunner/Activity.rb', line 81 def register_records(db) @fit_activity.personal_records.each do |r| if r.longest_distance == 1 # In case longest_distance is 1 the distance is stored in the # duration field in 10-th of meters. db.register_result(r.duration * 10.0 , 0, r.start_time, @fit_file) else db.register_result(r.distance, r.duration, r.start_time, @fit_file) end end end |
#rename(name) ⇒ Object
77 78 79 |
# File 'lib/postrunner/Activity.rb', line 77 def rename(name) @name = name end |
#show ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/postrunner/Activity.rb', line 63 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 end |
#summary ⇒ Object
72 73 74 75 |
# File 'lib/postrunner/Activity.rb', line 72 def summary @fit_activity = load_fit_file unless @fit_activity puts ActivityReport.new(@fit_activity).to_s end |
#yaml_initialize(tag, value) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/postrunner/Activity.rb', line 40 def yaml_initialize(tag, value) # Create attr_readers for cached variables. @@CachedVariables.each { |v| self.class.send(:attr_reader, v.to_sym) } # Load all attributes and assign them to instance variables. value.each do |a, v| instance_variable_set("@" + a, v) end # Use the FIT file name as activity name if none has been set yet. @name = @fit_file unless @name end |