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_payed_session ⇒ Object
- #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.
429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/devlog.rb', line 429 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
425 426 427 |
# File 'lib/devlog.rb', line 425 def coding_session_time @coding_session_time end |
#com_session_time ⇒ Object
this is the total time, but each session has these same params
425 426 427 |
# File 'lib/devlog.rb', line 425 def com_session_time @com_session_time end |
#devlog_file ⇒ Object
Returns the value of attribute devlog_file.
427 428 429 |
# File 'lib/devlog.rb', line 427 def devlog_file @devlog_file end |
#payed_time ⇒ Object
this is the total time, but each session has these same params
425 426 427 |
# File 'lib/devlog.rb', line 425 def payed_time @payed_time end |
#zezzions ⇒ Object
Returns the value of attribute zezzions.
427 428 429 |
# File 'lib/devlog.rb', line 427 def zezzions @zezzions end |
Instance Method Details
#add_zezzion(zezzion) ⇒ Object
445 446 447 |
# File 'lib/devlog.rb', line 445 def add_zezzion(zezzion) @zezzions << zezzion end |
#charge_time ⇒ Object
total charge time in hours, coding plus communication sessions
498 499 500 |
# File 'lib/devlog.rb', line 498 def charge_time (coding_session_time + com_session_time).round(2) end |
#devlog_begin ⇒ Object
global devlog start, first entry
450 451 452 |
# File 'lib/devlog.rb', line 450 def devlog_begin @zezzions.last.zzbegin end |
#devlog_days ⇒ Object
how many days devlog spans
470 471 472 473 |
# File 'lib/devlog.rb', line 470 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
455 456 457 |
# File 'lib/devlog.rb', line 455 def devlog_end @zezzions.first.zzend end |
#devlog_months ⇒ Object
480 481 482 |
# File 'lib/devlog.rb', line 480 def devlog_months count_time( :months => 1) end |
#devlog_sessions ⇒ Object
return all sessions
575 576 577 |
# File 'lib/devlog.rb', line 575 def devlog_sessions @zezzions end |
#devlog_weeks ⇒ Object
how many weeks devlog spans
476 477 478 |
# File 'lib/devlog.rb', line 476 def devlog_weeks (devlog_days/7.0).round(2) end |
#first_session ⇒ Object
566 567 568 |
# File 'lib/devlog.rb', line 566 def first_session @zezzions.last # devlog_end end |
#has_info? ⇒ Boolean
441 442 443 |
# File 'lib/devlog.rb', line 441 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
508 509 510 511 512 513 |
# File 'lib/devlog.rb', line 508 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_payed_session ⇒ Object
570 571 572 |
# File 'lib/devlog.rb', line 570 def last_payed_session @zezzions.select{|zezzion| zezzion.payed_time<0}.first end |
#last_session ⇒ Object
562 563 564 |
# File 'lib/devlog.rb', line 562 def last_session @zezzions.first # devlog_begin end |
#longest_session ⇒ Object
538 539 540 |
# File 'lib/devlog.rb', line 538 def longest_session @zezzions.max_by(&:session_time) end |
#negative_sessions ⇒ Object
546 547 548 |
# File 'lib/devlog.rb', line 546 def negative_sessions @zezzions.select{|zezzion| zezzion.session_time<0} end |
#negative_sessions_to_s ⇒ Object
558 559 560 |
# File 'lib/devlog.rb', line 558 def negative_sessions_to_s sessions_to_s(negative_sessions) end |
#per_day ⇒ Object
hours per day
485 486 487 |
# File 'lib/devlog.rb', line 485 def per_day (self.session_time/self.devlog_days).round(2) end |
#per_month ⇒ Object
493 494 495 |
# File 'lib/devlog.rb', line 493 def per_month (self.session_time/self.devlog_months).round(2) end |
#per_week ⇒ Object
489 490 491 |
# File 'lib/devlog.rb', line 489 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
516 517 518 |
# File 'lib/devlog.rb', line 516 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
465 466 467 |
# File 'lib/devlog.rb', line 465 def session_time @zezzions.inject(0) { |time, zezzion| time + zezzion.session_time }.round(2) end |
#shortest_session ⇒ Object
542 543 544 |
# File 'lib/devlog.rb', line 542 def shortest_session @zezzions.min_by(&:session_time) end |
#to_info_string(short = false) ⇒ Object
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 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/devlog.rb', line 585 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}h\n") s << ("\n") end end 0.upto(5) do |week| weekly_zezzions = zezzions_for_week(week, DateTime.current) if weekly_zezzions.any? sevendays = Sevendays.new(weekly_zezzions) s << ("#{sevendays.begins_at}->#{sevendays.ends_at}: #{sevendays.total_hours_string}\n") else s << "No weekly sessions for week #{week}.\n" end end s << "Last payed: #{last_payed_session.zzend.to_s(:long)}" if last_payed_session end s end |
#unpayed_time ⇒ Object
total charge time in hours, coding plus communication sessions - payed hours
503 504 505 |
# File 'lib/devlog.rb', line 503 def unpayed_time (coding_session_time + com_session_time + payed_time).round(2) end |
#validation_string ⇒ Object
579 580 581 582 583 |
# File 'lib/devlog.rb', line 579 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
550 551 552 |
# File 'lib/devlog.rb', line 550 def zero_sessions @zezzions.select{|zezzion| zezzion.session_time==0.0} end |
#zero_sessions_to_s ⇒ Object
554 555 556 |
# File 'lib/devlog.rb', line 554 def zero_sessions_to_s sessions_to_s(zero_sessions) end |
#zezzions_for_month(fromnow = 0, current_time = DateTime.current_time) ⇒ Object
530 531 532 533 534 535 536 |
# File 'lib/devlog.rb', line 530 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
522 523 524 525 526 527 528 |
# File 'lib/devlog.rb', line 522 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 |