Class: Devlog::Parsing

Inherits:
Object
  • Object
show all
Defined in:
lib/devlog.rb

Overview

The parsing object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(viewing_time_current_date = DateTime.now) ⇒ Parsing

Returns a new instance of Parsing.



433
434
435
436
437
438
439
440
441
442
443
# File 'lib/devlog.rb', line 433

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_timeObject

this is the total time, but each session has these same params



429
430
431
# File 'lib/devlog.rb', line 429

def coding_session_time
  @coding_session_time
end

#com_session_timeObject

this is the total time, but each session has these same params



429
430
431
# File 'lib/devlog.rb', line 429

def com_session_time
  @com_session_time
end

#devlog_fileObject

Returns the value of attribute devlog_file.



431
432
433
# File 'lib/devlog.rb', line 431

def devlog_file
  @devlog_file
end

#payed_timeObject

this is the total time, but each session has these same params



429
430
431
# File 'lib/devlog.rb', line 429

def payed_time
  @payed_time
end

#zezzionsObject

Returns the value of attribute zezzions.



431
432
433
# File 'lib/devlog.rb', line 431

def zezzions
  @zezzions
end

Instance Method Details

#add_zezzion(zezzion) ⇒ Object



449
450
451
# File 'lib/devlog.rb', line 449

def add_zezzion(zezzion)
  @zezzions << zezzion
end

#charge_timeObject

total charge time in hours, coding plus communication sessions



513
514
515
# File 'lib/devlog.rb', line 513

def charge_time
  coding_session_time + com_session_time
end

#charge_time_hObject



517
518
519
# File 'lib/devlog.rb', line 517

def charge_time_h
  charge_time.rounded_hours
end

#coding_session_time_hObject



602
603
604
# File 'lib/devlog.rb', line 602

def coding_session_time_h
  coding_session_time.rounded_hours
end

#com_session_time_hObject



606
607
608
# File 'lib/devlog.rb', line 606

def com_session_time_h
  com_session_time.rounded_hours
end

#devlog_beginObject

global devlog start, first entry



454
455
456
# File 'lib/devlog.rb', line 454

def devlog_begin
  @zezzions.last.zzbegin
end

#devlog_daysObject

how many days devlog spans



473
474
475
476
# File 'lib/devlog.rb', line 473

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_endObject

global devlog end, last entry



459
460
461
# File 'lib/devlog.rb', line 459

def devlog_end
  @zezzions.first.zzend
end

#devlog_monthsObject



483
484
485
# File 'lib/devlog.rb', line 483

def devlog_months
  count_time( :months => 1)
end

#devlog_sessionsObject

return all sessions



598
599
600
# File 'lib/devlog.rb', line 598

def devlog_sessions
  @zezzions
end

#devlog_weeksObject

how many weeks devlog spans



479
480
481
# File 'lib/devlog.rb', line 479

def devlog_weeks
  (devlog_days/7.0).round(2)
end

#first_sessionObject



589
590
591
# File 'lib/devlog.rb', line 589

def first_session
  @zezzions.last # devlog_end
end

#has_info?Boolean

Returns:

  • (Boolean)


445
446
447
# File 'lib/devlog.rb', line 445

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



531
532
533
534
535
536
# File 'lib/devlog.rb', line 531

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 }

  selected_zezzions.inject(0) { |time, z| time + z.session_time }.to_f.rounded_hours
end

#last_payed_sessionObject



593
594
595
# File 'lib/devlog.rb', line 593

def last_payed_session
  @zezzions.select{|zezzion| zezzion.payed_time<0}.first
end

#last_sessionObject



585
586
587
# File 'lib/devlog.rb', line 585

def last_session
  @zezzions.first # devlog_begin
end

#longest_sessionObject



561
562
563
# File 'lib/devlog.rb', line 561

def longest_session
  @zezzions.max_by(&:session_time)
end

#negative_sessionsObject



569
570
571
# File 'lib/devlog.rb', line 569

def negative_sessions
  @zezzions.select{|zezzion| zezzion.session_time<0}
end

#negative_sessions_to_sObject



581
582
583
# File 'lib/devlog.rb', line 581

def negative_sessions_to_s
  sessions_to_s(negative_sessions)
end

#payed_time_hObject



610
611
612
# File 'lib/devlog.rb', line 610

def payed_time_h
  payed_time.rounded_hours
end

#per_dayObject

seconds per day



488
489
490
# File 'lib/devlog.rb', line 488

def per_day
  self.session_time/self.devlog_days
end

#per_day_hObject



492
493
494
# File 'lib/devlog.rb', line 492

def per_day_h
  per_day.rounded_hours
end

#per_monthObject



504
505
506
# File 'lib/devlog.rb', line 504

def per_month
  self.session_time/self.devlog_months
end

#per_month_hObject



508
509
510
# File 'lib/devlog.rb', line 508

def per_month_h
  per_month.rounded_hours
end

#per_weekObject



496
497
498
# File 'lib/devlog.rb', line 496

def per_week
  self.session_time/self.devlog_weeks
end

#per_week_hObject



500
501
502
# File 'lib/devlog.rb', line 500

def per_week_h
  per_week.rounded_hours
end

#select_zezzions(from_time, to_time) ⇒ Object

from time to time select some zezzions



539
540
541
# File 'lib/devlog.rb', line 539

def select_zezzions(from_time, to_time)
  @zezzions.select { |z| z.zzbegin.to_time > from_time && z.zzend.to_time <= to_time }
end

#session_timeObject

total session time



464
465
466
# File 'lib/devlog.rb', line 464

def session_time
  @zezzions.inject(0) { |time, zezzion| time + zezzion.session_time }
end

#session_time_hObject



468
469
470
# File 'lib/devlog.rb', line 468

def session_time_h
  session_time.rounded_hours
end

#shortest_sessionObject



565
566
567
# File 'lib/devlog.rb', line 565

def shortest_session
  @zezzions.min_by(&:session_time)
end

#to_info_string(short = false) ⇒ Object



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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/devlog.rb', line 620

def to_info_string(short=false)
  s = ''
  s <<  "\nSession::Time:      = #{session_time_h} [h]\n"
  s << ("\nCodingSession::Time = %.1f [h]\n" % coding_session_time_h)
  s << ("\nComSession::Time    = %.1f [h]\n" % com_session_time_h)
  s << ("\nCharge::Time        = #{charge_time_h} [h]\n")
  s << ("\nUnpayed::Time       = #{unpayed_time_h} [h]\n")
  s << ("\n")
  unless short
    s << ("Num of Sessions     = #{self.devlog_sessions.size}\n")
    s << ("Hours per Day       = #{self.per_day_h} [h]\n")
    s << ("Hours per Week      = #{self.per_week_h} [h]\n")
    s << ("Hours per Month     = #{self.per_month_h} [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_in_seconds}\n")
    s << ("Last Session        = #{self.devlog_end.ago_in_words}, duration: #{self.last_session.in_hours} [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 at: #{current_day.breaks_at}\n")
        s << ("ends 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}" if last_payed_session
  end
  s
end

#unpayed_timeObject

total charge time in hours, coding plus communication sessions - payed hours



522
523
524
# File 'lib/devlog.rb', line 522

def unpayed_time
  coding_session_time + com_session_time + payed_time
end

#unpayed_time_hObject



526
527
528
# File 'lib/devlog.rb', line 526

def unpayed_time_h
  unpayed_time.rounded_hours
end

#validation_stringObject



614
615
616
617
618
# File 'lib/devlog.rb', line 614

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_sessionsObject



573
574
575
# File 'lib/devlog.rb', line 573

def zero_sessions
  @zezzions.select{|zezzion| zezzion.session_time==0.0}
end

#zero_sessions_to_sObject



577
578
579
# File 'lib/devlog.rb', line 577

def zero_sessions_to_s
  sessions_to_s(zero_sessions)
end

#zezzions_for_month(fromnow = 0, current_time = DateTime.current_time) ⇒ Object



553
554
555
556
557
558
559
# File 'lib/devlog.rb', line 553

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



545
546
547
548
549
550
551
# File 'lib/devlog.rb', line 545

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