class Devlog::Parsing
The parsing object
Attributes
this is the total time, but each session has these same params
this is the total time, but each session has these same params
this is the total time, but each session has these same params
Public Class Methods
# File lib/devlog.rb, line 425 def initialize(viewing_time_current_date = DateTime.now) @viewing_time_current_date = viewing_time_current_date @zezzions = [] # backward compatible object with Tajm, from devlog 0.0.0 @coding_session_time = 0.0 @com_session_time = 0.0 @payed_time = 0.0 @devlog_file = '' end
Public Instance Methods
# File lib/devlog.rb, line 441 def add_zezzion(zezzion) @zezzions << zezzion end
total charge time in hours, coding plus communication sessions
# File lib/devlog.rb, line 494 def charge_time (coding_session_time + com_session_time).round(2) end
global devlog start, first entry
# File lib/devlog.rb, line 446 def devlog_begin @zezzions.last.zzbegin end
how many days devlog spans
# File lib/devlog.rb, line 466 def devlog_days count_time( :days => 1) # (self.devlog_end - self.devlog_begin).to_i + 1 #counting days like this, would not account for daylight saving changes end
global devlog end, last entry
# File lib/devlog.rb, line 451 def devlog_end @zezzions.first.zzend end
# File lib/devlog.rb, line 476 def devlog_months count_time( :months => 1) end
return all sessions
# File lib/devlog.rb, line 567 def devlog_sessions @zezzions end
how many weeks devlog spans
# File lib/devlog.rb, line 472 def devlog_weeks (devlog_days/7.0).round(2) end
# File lib/devlog.rb, line 562 def first_session @zezzions.last # devlog_end end
# File lib/devlog.rb, line 437 def has_info? @zezzions.any? end
return hours worked for the last X days, from current_time
# File lib/devlog.rb, line 504 def hours_for_last(days, current_time = DateTime.now) endTime = current_time.to_time - days.days selected_zezzions = @zezzions.select { |z| z.zzbegin.to_time < current_time && z.zzend >= endTime } #puts("Selected sessons from #{current_time} to #{endTime}: #{selected_zezzions.size}") selected_zezzions.inject(0) { |time, z| time + z.session_time }.round(2) end
# File lib/devlog.rb, line 558 def last_session @zezzions.first # devlog_begin end
# File lib/devlog.rb, line 534 def longest_session @zezzions.max_by(&:session_time) end
# File lib/devlog.rb, line 542 def negative_sessions @zezzions.select{|zezzion| zezzion.session_time<0} end
# File lib/devlog.rb, line 554 def negative_sessions_to_s sessions_to_s(negative_sessions) end
hours per day
# File lib/devlog.rb, line 481 def per_day (self.session_time/self.devlog_days).round(2) end
# File lib/devlog.rb, line 489 def per_month (self.session_time/self.devlog_months).round(2) end
# File lib/devlog.rb, line 485 def per_week (self.session_time/self.devlog_weeks).round(2) end
from time to time select some zezzions
# File lib/devlog.rb, line 512 def select_zezzions(from_time, to_time) @zezzions.select { |z| z.zzbegin.to_time > from_time && z.zzend.to_time <= to_time } end
how much time between first session begin and last session end in seconds def devlog_time
(self.devlog_end.to_time - self.devlog_begin.to_time)/60.0/60.0
end
# File lib/devlog.rb, line 461 def session_time @zezzions.inject(0) { |time, zezzion| time + zezzion.session_time }.round(2) end
# File lib/devlog.rb, line 538 def shortest_session @zezzions.min_by(&:session_time) end
# File lib/devlog.rb, line 577 def to_info_string(short=false) s = '' s << "\nSession::Time: = #{self.session_time} [h]\n" s << ("\nCodingSession::Time = %.1f [h]\n" % self.coding_session_time) s << ("\nComSession::Time = %.1f [h]\n" % self.com_session_time) s << ("\nCharge::Time = #{self.charge_time} [h]\n") s << ("\nUnpayed::Time = #{self.unpayed_time.to_s} [h]\n") s << ("\n") unless short s << ("Num of Sessions = #{self.devlog_sessions.size}\n") s << ("Hours per Day = #{self.per_day} [h]\n") s << ("Hours per Week = #{self.per_week} [h]\n") s << ("Hours per Month = #{self.per_month} [h]\n") s << ("Hours last 7 days = #{self.hours_for_last(7)} [h]\n") s << ("Hours last 14 days = #{self.hours_for_last(14)} [h]\n") s << ("Hours last 28 days = #{self.hours_for_last(28)} [h]\n") s << ("\n") s << ("Devlog Time = #{self.devlog_days * 24} [h]\n") s << ("Devlog Days = #{self.devlog_days} [days]\n") s << ("Devlog Weeks = #{self.devlog_weeks} [weeks]\n") s << ("Devlog Months = #{self.devlog_months} [months]\n") if self.negative_sessions.any? s << ("\n") s << ("#{'Negative Sessions'.red} = #{self.negative_sessions_to_s}\n") end if self.zero_sessions.any? s << ("\n") s << ("#{'Zero Sessions'.blue} = #{self.zero_sessions_to_s}\n") end s << ("\n") s << ("Longest Session = #{self.longest_session.to_s}\n") s << ("Shortest Session = #{self.shortest_session.to_s}\n") s << ("Last Session = #{self.devlog_end.ago_in_words}, duration: #{self.last_session.session_time.round(3)} [h]") s << ("\n") s << ("Weekly Sessions\n") s << ("\n") sevendays = Sevendays.new(zezzions_for_week) sevendays_total = 0 Sevendays::DAYS.each do |day| current_day = sevendays.send(day.to_sym) dayname = day.upcase if current_day.any? current_day_total_hours = current_day.total_hours sevendays_total += current_day_total_hours s << ("#{dayname.upcase}\n") s << ("begins at: #{current_day.begins_at}\n") s << ("breaks: #{current_day.breaks_at}\n") s << ("end_at: #{current_day.ends_at}\n") s << ("sum: #{current_day_total_hours}\n") s << ("\n") end end s << ("Weekly sessions total: #{sevendays_total}\n") end s end
total charge time in hours, coding plus communication sessions - payed hours
# File lib/devlog.rb, line 499 def unpayed_time (coding_session_time + com_session_time + payed_time).round(2) end
# File lib/devlog.rb, line 571 def validation_string vs = '' vs << (@zezzions.any? ? '' : "No sessions recorded, add some first...\n".red) vs << (File.exist?(devlog_file) ? '' : "No such file #{devlog_file}...\n".red) end
# File lib/devlog.rb, line 546 def zero_sessions @zezzions.select{|zezzion| zezzion.session_time==0.0} end
# File lib/devlog.rb, line 550 def zero_sessions_to_s sessions_to_s(zero_sessions) end
# File lib/devlog.rb, line 526 def zezzions_for_month(fromnow = 0, current_time = DateTime.current_time) moment = current_time - (fromnow).months begin_time = moment.beginning_of_month end_time = moment.end_of_month select_zezzions(begin_time, end_time) end
returns zezzions recorded during beginning of week and end of week fromnow - how many weeks into the past
# File lib/devlog.rb, line 518 def zezzions_for_week(fromnow = 0, current_time = DateTime.current) moment = current_time - (7 * fromnow).days begin_time = moment.beginning_of_week end_time = moment.end_of_week select_zezzions(begin_time, end_time) end
Private Instance Methods
count :weeks=>1, or :days=>1, or :years=>1
# File lib/devlog.rb, line 641 def count_time(options) num = 0 cur = self.devlog_begin while cur < self.devlog_end num += 1 cur = cur.advance(options) end num end
# File lib/devlog.rb, line 636 def sessions_to_s(sessions) "\n" + sessions.collect{|session| " " + session.to_s}.join("\n") end