Class: WatchTower::Server::Project
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WatchTower::Server::Project
- Defined in:
- lib/watch_tower/server/models/project.rb
Class Method Summary collapse
-
.date_range(from, to) ⇒ ActiveRelation
Return an ActiveRelation limited to a date range.
-
.sum_elapsed_time ⇒ Integer
Returns the sum of all elapsed time.
Instance Method Summary collapse
-
#percent ⇒ Object
Return the percent of this file.
-
#recalculate_elapsed_time ⇒ Object
Recalucate the elapsed time.
Class Method Details
.date_range(from, to) ⇒ ActiveRelation
Return an ActiveRelation limited to a date range
29 30 31 32 33 34 35 36 37 |
# File 'lib/watch_tower/server/models/project.rb', line 29 def self.date_range(from, to) from = Date.strptime(from, '%m/%d/%Y') to = Date.strptime(to, '%m/%d/%Y') joins(:durations => :file). where('durations.date >= ?', from). where('durations.date <= ?', to). select('DISTINCT projects.*') end |
.sum_elapsed_time ⇒ Integer
Returns the sum of all elapsed time
42 43 44 |
# File 'lib/watch_tower/server/models/project.rb', line 42 def self.sum_elapsed_time sum(:elapsed_time) end |
Instance Method Details
#percent ⇒ Object
Return the percent of this file
20 21 22 |
# File 'lib/watch_tower/server/models/project.rb', line 20 def percent (elapsed_time * 100) / self.class.sum_elapsed_time end |
#recalculate_elapsed_time ⇒ Object
Recalucate the elapsed time
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/watch_tower/server/models/project.rb', line 47 def recalculate_elapsed_time # Reset the elapsed_time of the project self.elapsed_time = 0 # Save the project self.save! # Operate on all files files.each do |f| # Reset the elapsed_time of the files f.elapsed_time = 0 # Save the file f.save! # Delete all durations f.durations.delete_all # Send calculate_elapsed_time to all time_entries ordered by # their id f.time_entries.order('id ASC').each do |t| t.send(:calculate_elapsed_time) end end end |