Class: Devlog::Parsing
- Inherits:
-
Object
- Object
- Devlog::Parsing
- Defined in:
- lib/devlog.rb
Overview
The parsing object
Instance Attribute Summary collapse
-
#coding_session_time ⇒ Object
this is the total time, but each session has these same params.
-
#com_session_time ⇒ Object
this is the total time, but each session has these same params.
-
#devlog_file ⇒ Object
Returns the value of attribute devlog_file.
-
#payed_time ⇒ Object
this is the total time, but each session has these same params.
-
#zezzions ⇒ Object
Returns the value of attribute zezzions.
Instance Method Summary collapse
- #add_zezzion(zezzion) ⇒ Object
-
#charge_time ⇒ Object
total charge time in hours, coding plus communication sessions.
-
#devlog_begin ⇒ Object
global devlog start, first entry.
-
#devlog_days ⇒ Object
how many days devlog spans.
-
#devlog_end ⇒ Object
global devlog end, last entry.
- #devlog_months ⇒ Object
-
#devlog_sessions ⇒ Object
return all sessions.
-
#devlog_weeks ⇒ Object
how many weeks devlog spans.
- #first_session ⇒ Object
- #has_info? ⇒ Boolean
-
#hours_for_last(days, current_time = DateTime.now) ⇒ Object
return hours worked for the last X days, from current_time.
-
#initialize(viewing_time_current_date = DateTime.now) ⇒ Parsing
constructor
A new instance of Parsing.
- #last_session ⇒ Object
- #longest_session ⇒ Object
- #negative_sessions ⇒ Object
- #negative_sessions_to_s ⇒ Object
-
#per_day ⇒ Object
hours per day.
- #per_month ⇒ Object
- #per_week ⇒ Object
-
#select_zezzions(from_time, to_time) ⇒ Object
from time to time select some zezzions.
-
#session_time ⇒ Object
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.
- #shortest_session ⇒ Object
- #to_info_string(short = false) ⇒ Object
-
#unpayed_time ⇒ Object
total charge time in hours, coding plus communication sessions - payed hours.
- #validation_string ⇒ Object
- #zero_sessions ⇒ Object
- #zero_sessions_to_s ⇒ Object
- #zezzions_for_month(fromnow = 0, current_time = DateTime.current_time) ⇒ Object
-
#zezzions_for_week(fromnow = 0, current_time = DateTime.current) ⇒ Object
returns zezzions recorded during beginning of week and end of week fromnow - how many weeks into the past.
Constructor Details
#initialize(viewing_time_current_date = DateTime.now) ⇒ Parsing
Returns a new instance of Parsing.
425 426 427 428 429 430 431 432 433 434 435 |
# 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 |
Instance Attribute Details
#coding_session_time ⇒ Object
this is the total time, but each session has these same params
421 422 423 |
# File 'lib/devlog.rb', line 421 def coding_session_time @coding_session_time end |
#com_session_time ⇒ Object
this is the total time, but each session has these same params
421 422 423 |
# File 'lib/devlog.rb', line 421 def com_session_time @com_session_time end |
#devlog_file ⇒ Object
Returns the value of attribute devlog_file.
423 424 425 |
# File 'lib/devlog.rb', line 423 def devlog_file @devlog_file end |
#payed_time ⇒ Object
this is the total time, but each session has these same params
421 422 423 |
# File 'lib/devlog.rb', line 421 def payed_time @payed_time end |
#zezzions ⇒ Object
Returns the value of attribute zezzions.
423 424 425 |
# File 'lib/devlog.rb', line 423 def zezzions @zezzions end |
Instance Method Details
#add_zezzion(zezzion) ⇒ Object
441 442 443 |
# File 'lib/devlog.rb', line 441 def add_zezzion(zezzion) @zezzions << zezzion end |
#charge_time ⇒ Object
total charge time in hours, coding plus communication sessions
494 495 496 |
# File 'lib/devlog.rb', line 494 def charge_time (coding_session_time + com_session_time).round(2) end |
#devlog_begin ⇒ Object
global devlog start, first entry
446 447 448 |
# File 'lib/devlog.rb', line 446 def devlog_begin @zezzions.last.zzbegin end |
#devlog_days ⇒ Object
how many days devlog spans
466 467 468 469 |
# 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 |
#devlog_end ⇒ Object
global devlog end, last entry
451 452 453 |
# File 'lib/devlog.rb', line 451 def devlog_end @zezzions.first.zzend end |
#devlog_months ⇒ Object
476 477 478 |
# File 'lib/devlog.rb', line 476 def devlog_months count_time( :months => 1) end |
#devlog_sessions ⇒ Object
return all sessions
567 568 569 |
# File 'lib/devlog.rb', line 567 def devlog_sessions @zezzions end |
#devlog_weeks ⇒ Object
how many weeks devlog spans
472 473 474 |
# File 'lib/devlog.rb', line 472 def devlog_weeks (devlog_days/7.0).round(2) end |
#first_session ⇒ Object
562 563 564 |
# File 'lib/devlog.rb', line 562 def first_session @zezzions.last # devlog_end end |
#has_info? ⇒ Boolean
437 438 439 |
# File 'lib/devlog.rb', line 437 def has_info? @zezzions.any? end |
#hours_for_last(days, current_time = DateTime.now) ⇒ Object
return hours worked for the last X days, from current_time
504 505 506 507 508 509 |
# 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 |
#last_session ⇒ Object
558 559 560 |
# File 'lib/devlog.rb', line 558 def last_session @zezzions.first # devlog_begin end |
#longest_session ⇒ Object
534 535 536 |
# File 'lib/devlog.rb', line 534 def longest_session @zezzions.max_by(&:session_time) end |
#negative_sessions ⇒ Object
542 543 544 |
# File 'lib/devlog.rb', line 542 def negative_sessions @zezzions.select{|zezzion| zezzion.session_time<0} end |
#negative_sessions_to_s ⇒ Object
554 555 556 |
# File 'lib/devlog.rb', line 554 def negative_sessions_to_s sessions_to_s(negative_sessions) end |
#per_day ⇒ Object
hours per day
481 482 483 |
# File 'lib/devlog.rb', line 481 def per_day (self.session_time/self.devlog_days).round(2) end |
#per_month ⇒ Object
489 490 491 |
# File 'lib/devlog.rb', line 489 def per_month (self.session_time/self.devlog_months).round(2) end |
#per_week ⇒ Object
485 486 487 |
# File 'lib/devlog.rb', line 485 def per_week (self.session_time/self.devlog_weeks).round(2) end |
#select_zezzions(from_time, to_time) ⇒ Object
from time to time select some zezzions
512 513 514 |
# 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 |
#session_time ⇒ Object
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
461 462 463 |
# File 'lib/devlog.rb', line 461 def session_time @zezzions.inject(0) { |time, zezzion| time + zezzion.session_time }.round(2) end |
#shortest_session ⇒ Object
538 539 540 |
# File 'lib/devlog.rb', line 538 def shortest_session @zezzions.min_by(&:session_time) end |
#to_info_string(short = false) ⇒ Object
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
# 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 |
#unpayed_time ⇒ Object
total charge time in hours, coding plus communication sessions - payed hours
499 500 501 |
# File 'lib/devlog.rb', line 499 def unpayed_time (coding_session_time + com_session_time + payed_time).round(2) end |
#validation_string ⇒ Object
571 572 573 574 575 |
# 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 |
#zero_sessions ⇒ Object
546 547 548 |
# File 'lib/devlog.rb', line 546 def zero_sessions @zezzions.select{|zezzion| zezzion.session_time==0.0} end |
#zero_sessions_to_s ⇒ Object
550 551 552 |
# File 'lib/devlog.rb', line 550 def zero_sessions_to_s sessions_to_s(zero_sessions) end |
#zezzions_for_month(fromnow = 0, current_time = DateTime.current_time) ⇒ Object
526 527 528 529 530 531 532 |
# 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 |
#zezzions_for_week(fromnow = 0, current_time = DateTime.current) ⇒ Object
returns zezzions recorded during beginning of week and end of week fromnow - how many weeks into the past
518 519 520 521 522 523 524 |
# 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 |