Module: Commands::List

Included in:
LogTime
Defined in:
lib/commands/list.rb,
lib/app/commands/list.rb

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/commands/list.rb', line 3

def self.included(thor)
    thor.class_eval do
        option :active, :type => :boolean, :default => true
        #option :tag, :type => :string, :alias => '-t'
        desc "ls", "list time series"
        def ls(tag='')
            logs = Log.where(active: options[:active]).includes(:series).includes(:tags)
            logs = logs.tagged(tag) if !tag.blank?

            creep_stats = Statistics.new
            table = [['#', 'name', 'active', 'tags', 'series', 'time', 'estimate', 'creep %']] # header
            logs.each do |log|

                # tags
                tags = log.tags.map do |t|
                    t.tag
                end

                # only show logs with tag, if selected
                # if !tag.blank?
                #     next unless tags.include? tag
                # end

                # active text
                active = "ACTIVE" if log.active == "t"

                # total counter
                total_time = (log.total/3600).round(2)

                # estimation creep
                if log.estimation
                    creep = (total_time/log.estimation)*100
                    creep_stats << creep
                    creep = creep.round(3)
                    estimation = (log.estimation/3600).round(3) # log estimation to hours
                end

                table << [log.id,
                    log.name,
                    active || '',
                    tags,
                    log.series.count || '',
                    total_time || '',
                    estimation || '',
                    creep || '']
            end

            if logs.count == 0
                puts ""
                say "No logs found", :red
                puts ""
                exit
            else
                puts ""
                print_table table
                puts ""
                say [logs.count.to_s, "logs out of", Log.count.to_s].join(' '), :cyan
                say [creep_stats.count, "estimations"].join(' '), :cyan
                say [creep_stats.mean.round(2), "percent mean creep"].join(' '), :cyan
            end
        end
    end
end