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
66
67
68
69
70
71
72
|
# File 'lib/commands/list.rb', line 3
def self.included(thor)
thor.class_eval do
option :active, :type => :boolean, :default => true
option :order, :type => :string, :default => "updated_at"
desc "ls", "List time series"
def ls(search='')
logs = Log.where(active: options[:active]).includes(:series).includes(:tags)
logs = logs.order(options[:order].to_sym => :desc)
logs = logs.tagged(search) if !search.blank?
creep_stats = Statistics.new
table = [['#', 'name', '', 'tags', 'series', 'time', 'start', 'stop', 'estimate', 'creep %']] logs.each do |log|
tags = log.tags.map do |t|
t.tag
end
tags = tags.join ' '
active = "ACTIVE" if log.active == "t"
total_time = (log.total_time/3600).round(2) total_time = "#{total_time} hours"
start = time_display(log.series.first.start) if log.series.first
stop = time_display(log.series.last.end) if log.series.last
if log.estimation
creep = log.creep creep_stats << creep
creep = creep.round(2) estimation = (log.estimation/3600).round(2) end
table << [log.id,
log.name,
active || '',
tags,
log.series.count || '',
total_time || '',
start || '',
stop || '',
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
|