logtime 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +0,0 @@
1
- module Commands
2
- module List
3
- def self.included(thor)
4
- thor.class_eval do
5
- option :active, :type => :boolean, :default => true
6
- option :tag, :type => :boolean, :alias => '-t'
7
- desc "ls", "list time series"
8
- def ls()
9
- logs = Log.where(active: options[:active]).includes(:series)
10
- # logs = Tag.where(tag: options[:tag]).logs if options[:tag]
11
-
12
-
13
- creep_stats = Statistics.new
14
- table = [['#', 'name', 'active', 'tags', 'series', 'time', 'estimate', 'creep %']] # header
15
- logs.each do |log|
16
-
17
- # tags
18
- tags = log.tags.map do |t|
19
- t.tag
20
- end
21
-
22
- # active text
23
- active = "ACTIVE" if log.active == "t"
24
-
25
- # total counter
26
- total_time = (log.total/3600).round(2)
27
-
28
- # estimation creep
29
- if log.estimation
30
- creep = (total_time/log.estimation)*100
31
- creep_stats << creep
32
- creep = creep.round(3)
33
- estimation = (log.estimation/3600).round(3) # log estimation to hours
34
- end
35
-
36
- table << [log.id,
37
- log.name,
38
- active || '',
39
- tags,
40
- log.series.count || '',
41
- total_time || '',
42
- estimation || '',
43
- creep || '']
44
- end
45
- puts ""
46
- print_table table
47
- puts ""
48
-
49
- say [logs.count.to_s, "logs out of", Log.count.to_s].join(' '), :cyan
50
- say [creep_stats.count, "estimations"].join(' '), :cyan
51
- say [creep_stats.mean.round(3), "avg creep"].join(' '), :cyan
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,28 +0,0 @@
1
- module Commands
2
- module Start
3
- def self.included(thor)
4
- thor.class_eval do
5
- desc "start [NAME]", "start new timer"
6
- def start(name)
7
-
8
- # not found
9
- if Log.where(name: name).count == 0
10
- say name.to_s + " not found", :red
11
- exit
12
- end
13
-
14
- log = Log.find_by(name: name)
15
-
16
- # already active?
17
- if log.active == "t"
18
- say name.to_s + " already active", :red
19
- exit
20
- end
21
-
22
- # begin new series, activate log
23
- series = Series.begin(log_id: log.id) and log.activate
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,29 +0,0 @@
1
- module Commands
2
- module Stop
3
- def self.included(thor)
4
- thor.class_eval do
5
- desc "stop [NAME]", "stop active timer"
6
- def stop(name)
7
- if Log.where(name: name).count == 0
8
- say name.to_s + " not found", :red
9
- exit
10
- end
11
-
12
- log = Log.find_by(name: name)
13
- if log.active == "f"
14
- say name.to_s + " not active", :red
15
- exit
16
- end
17
-
18
- series = log.series.last
19
- if series.stop and log.deactivate
20
- say name + " stopped!", :green
21
-
22
- # this_series = log.series.last
23
- say (series.total/3600).round(3).to_s + " hours out of " + (log.total/3600).round(3).to_s, :cyan
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,13 +0,0 @@
1
- module EstimateHelper
2
- class Estimate
3
- def initialize(time=0)
4
- @time = time
5
- end
6
-
7
- def difference(estimate=false)
8
- if !estimate
9
- estimate = Time.now
10
- end
11
- end
12
- end
13
- end
@@ -1,45 +0,0 @@
1
- module StatisticsHelper
2
- class Series < Array
3
- def sum
4
- inject(0.0) { |result, el| result + el }
5
- end
6
-
7
- def mean
8
- sum / size
9
- end
10
-
11
- alias :average :mean
12
- end
13
-
14
- class Statistics
15
- def initialize
16
- @statistics = Series.new
17
- end
18
-
19
- def add(statistic)
20
- @statistics << statistic
21
- end
22
-
23
- def count
24
- @statistics.count
25
- end
26
-
27
- def mean
28
- @statistics.mean
29
- end
30
-
31
- def <<(statistic)
32
- add(statistic)
33
- end
34
-
35
- def +(statistics)
36
- @statistics = @statistics + statistics.data
37
- end
38
-
39
- def data
40
- @statistics
41
- end
42
-
43
- alias :average :mean
44
- end
45
- end
@@ -1,33 +0,0 @@
1
- module TimeToWordsHelper
2
- def time_to_words_ago(time)
3
- a = (Time.now-time).to_i
4
- case a
5
- when 0 then 'just now'
6
- when 1 then 'a second ago'
7
- when 2..59 then a.to_s+' seconds ago'
8
- when 60..119 then 'a minute ago' # 120 = 2 minutes
9
- when 120..3540 then (a/60).to_i.to_s+' minutes ago'
10
- when 3541..7100 then 'an hour ago' # 3600 = 1 hour
11
- when 7101..82800 then ((a+99)/3600).to_i.to_s+' hours ago'
12
- when 82801..172000 then 'a day ago' # 86400 = 1 day
13
- when 172001..518400 then ((a+800)/(60*60*24)).to_i.to_s+' days ago'
14
- when 518400..1036800 then 'a week ago'
15
- else ((a+180000)/(60*60*24*7)).to_i.to_s+' weeks ago'
16
- end
17
- end
18
-
19
- def time_to_words(seconds)
20
- seconds
21
- case a
22
- when 0..60 then 'seconds'
23
- when 60..69 then 'minute'
24
- when 70..3600 then 'minutes'
25
- when 3600..7199 then 'day'
26
- when 7200..107999 then 'days' # 3600 = 1 hour
27
- when 108000..215999 then 'month'
28
- when 216000..1296000 then 'months'
29
- when 1296000..1296000 then 'year'
30
- else 'years'
31
- end
32
- end
33
- end
data/lib/app/logtime.rb DELETED
@@ -1,67 +0,0 @@
1
- require '../config/initialisation'
2
-
3
- # require models
4
- models_path = '../app/models'
5
- if Dir.exists?(models_path)
6
- Dir.entries(models_path).each do |file|
7
- require File.join(models_path, file) if file =~ /^(.*)\.rb$/
8
- end
9
- end
10
-
11
- # require helpers
12
- helpers_path = '../app/helpers'
13
- if Dir.exists?(helpers_path)
14
- Dir.entries(helpers_path).each do |file|
15
- next unless file =~ /^(.*)\.rb$/
16
-
17
- require File.join(helpers_path, file)
18
-
19
- # helper name
20
- load = file.split '_'
21
- load = load.each { |h| h.capitalize! }
22
- load = load.join
23
- load = load[0..-4] # '.rb'
24
- load = load + "Helper"
25
-
26
- # load helper
27
- # begin
28
- send(:include, load.constantize)
29
- # rescue
30
- # ActiveRecord::Base.logger.warn "Failed to load " + load
31
- # end
32
- end
33
- end
34
-
35
- # require commands
36
- commands_path = '../app/commands'
37
- if Dir.exists?(commands_path)
38
- Dir.entries(commands_path).each do |file|
39
- require File.join(commands_path, file) if file =~ /^(.*)\.rb$/
40
- end
41
- end
42
-
43
- # require subcommands
44
- subcommands_path = '../app/subcommands'
45
- if Dir.exists?(subcommands_path)
46
- Dir.entries(subcommands_path).each do |file|
47
- require File.join(subcommands_path, file) if file =~ /^(.*)\.rb$/
48
- end
49
- end
50
-
51
- # Application
52
- class LogTime < Thor
53
-
54
- # commands
55
- include Commands::List
56
- include Commands::Add
57
- # include Commands::Remove
58
- include Commands::Start
59
- include Commands::Stop
60
-
61
- # subcommands
62
- desc "series", ""
63
- subcommand "series", SubCommands::Series
64
-
65
- desc "tags", ""
66
- subcommand "tags", SubCommands::Tags
67
- end
@@ -1,42 +0,0 @@
1
- #
2
- # Logs
3
- #
4
-
5
- class Log < ActiveRecord::Base
6
- scope :active, -> { where(active: true) }
7
- scope :inactive, -> { where(active: false) }
8
- scope :estimated, -> { where("estimation is not null") }
9
-
10
- validates :name, uniqueness: true
11
-
12
- has_many :series
13
- has_and_belongs_to_many :tags
14
-
15
- def tag(tags)
16
- tags.split(',').each do |t|
17
- self.tags << Tag.where(tag: t).first_or_create
18
- end
19
-
20
- return self
21
- end
22
-
23
- def activate
24
- self.active = true
25
- self.save
26
- end
27
-
28
- def deactivate
29
- self.active = false
30
- self.save
31
- end
32
-
33
- def total
34
- difference = 0
35
- self.series.each do |s|
36
- ending = s.end || Time.now
37
- # next unless s.start and s.end
38
- difference = difference + s.start.difference(ending)
39
- end
40
- difference
41
- end
42
- end
@@ -1,35 +0,0 @@
1
- #
2
- # Series
3
- #
4
-
5
- class Series < ActiveRecord::Base
6
- belongs_to :log
7
-
8
- def self.begin(options = {})
9
- attributes = {
10
- start: Time.now
11
- }.merge! options
12
-
13
- create(attributes)
14
- end
15
-
16
- def begin
17
- self.start = Time.now
18
- self.save
19
- end
20
-
21
- def stop
22
- self.end = Time.now
23
- self.save
24
- end
25
-
26
- def finished?
27
- !self.end.blank?
28
- end
29
-
30
- def total
31
- return false if self.end.blank? or self.start.blank?
32
-
33
- self.start.difference(self.end)
34
- end
35
- end
@@ -1,9 +0,0 @@
1
- #
2
- # Tags
3
- #
4
-
5
- class Tag < ActiveRecord::Base
6
- validates :tag, uniqueness: true
7
- validates_format_of :tag, :with => /[-a-z]+/
8
- has_and_belongs_to_many :logs
9
- end
@@ -1,214 +0,0 @@
1
- class Keywords < Thor
2
- # desc "add <account> <keyword>", "Add a new <keyword> to an <account>"
3
- # option :interactive, :type => :boolean, :alias => :i
4
- # def add(account, keyword=nil)
5
- # account = Account.find_by(:name => account)
6
-
7
- # if account.blank?
8
- # say 'no account found', :red
9
- # else
10
- # if options[:interactive]
11
- # say "To stop adding keywords type exit", :cyan
12
- # while true
13
- # keyword = ask ':'
14
- # break if keyword == 'exit'
15
- # if Keyword.new(:keyword => keyword, :account_id => account.id).save
16
- # say 'added', :green
17
- # else
18
- # say 'failed', :red
19
- # end
20
- # end
21
- # else
22
- # keyword.split(',').each do |k|
23
- # k = Keyword.new(:keyword => k, :account_id => account.id)
24
-
25
- # if k.save
26
- # say k.keyword + ' keyword added', :green
27
- # else
28
- # say 'could not add keyword!', :red
29
- # error k.errors.first[0].to_s + ' ' + k.errors.first[1]
30
- # end
31
- # end
32
- # end
33
- # end
34
- # end
35
-
36
- # desc "delete <account> <keyword>", "Removes <keyword> on an <account>"
37
- # def delete(account, keyword)
38
- # account = Account.search(account)
39
-
40
- # if account.blank?
41
- # say 'no account found', :red
42
- # else
43
- # keyword.split(',').each do |k|
44
- # k = Keyword.search(k)
45
-
46
- # if k.blank?
47
- # say 'could not find keyword!', :red
48
- # else
49
- # say k.keyword + ' removed', :green if k.destroy
50
- # end
51
- # end
52
- # end
53
- # end
54
-
55
- # desc "list", "Lists keywords belonging to an <account>"
56
- # option :account
57
- # def list(account=nil)
58
- # if account.nil?
59
- # keywords = Keyword.all
60
-
61
- # table = [['# Keyword', '# Position', '']] # header
62
- # keywords.each do |k|
63
- # stat = k.keyword_statistics.last unless k.keyword_statistics.empty?
64
- # table << [k.keyword, stat.position || '', stat.created_at.pretty ] # row
65
- # end
66
-
67
- # say ''
68
- # print_table table
69
- # say ''
70
- # else
71
- # account = Account.search(account)
72
- # if account.blank?
73
- # say 'no account found', :red
74
- # elsif account.keywords.empty?
75
- # say 'no keywords exist for that account yet', :red
76
- # else
77
- # table = [['# Keyword', '# Position', '']] # header
78
- # account.keywords.each do |k|
79
- # stat = k.keyword_statistics.last unless k.keyword_statistics.empty?
80
- # table << [k.keyword, stat.position || '', stat.created_at.pretty] # row
81
- # end
82
-
83
- # say ''
84
- # print_table table
85
- # say ''
86
- # end
87
- # end
88
- # end
89
-
90
- # desc "stats", "Compare keywords over time"
91
- # option :search, :default => 'year', :banner => 'year,month,week,day'
92
- # option :length, :type => :numeric, :default => 1
93
- # option :engine, :default => :google
94
- # def stats(account)
95
- # account = Account.search(account)
96
-
97
- # if account.blank?
98
- # say 'no account found', :red
99
- # elsif account.keywords.empty?
100
- # say 'no keywords exist for that account yet', :red
101
- # else
102
-
103
- # table = [['# Keyword', 'n', 'High', 'Low', 'Current', 'Delta']] # header
104
- # searched = 0;
105
- # account.keywords.each do |k|
106
- # stats = KeywordStatistic.send options[:search], k.id, options[:length], options[:engine]
107
- # stats.order(:position)
108
-
109
- # if !stats.empty?
110
- # delta = stats.last.position - stats.first.position
111
- # delta = '' if delta == 0
112
- # table << [k.keyword, stats.size, stats.last.position, stats.first.position, stats.last.position, delta] # row
113
- # searched = searched + stats.size
114
- # end
115
- # end
116
-
117
- # if searched == 0
118
- # say 'these keywords have not been indexed yet', :red
119
- # else
120
- # say ''
121
- # say account.name + ' has ' + searched.to_s + ' recorded positions for ' + account.keywords.size.to_s + ' keywords', :green
122
- # say ''
123
- # print_table table
124
- # say ''
125
- # end
126
- # end
127
- # end
128
-
129
- # #desc "import", "imports csv file"
130
- # #options :file
131
- # #def import(file)
132
-
133
- # #end
134
-
135
- # desc "index", "gets keyword position and saves it for later use"
136
- # def index(account)
137
- # account = Account.search(account)
138
- # if account.blank?
139
- # say 'no account found', :red
140
- # else
141
- # table = [['# Keyword', '# Google', '# GoogleUS']] # header
142
- # account.keywords.each do |k|
143
- # # Google
144
- # google = ::Ranking.new(:keyword => k.keyword, :url => account.domain, :limit =>100).from_googleAU
145
- # if !google.blank?
146
- # KeywordStatistic.new(:keyword_id => k.id, :engine => :google, :position => google).save
147
- # say '.', :green, false
148
- # else
149
- # say '.', :red, false
150
- # end
151
-
152
- # # GoogleUS
153
- # googleUS = ::Ranking.new(:keyword => k.keyword, :url => account.domain, :limit =>100).from_googleUS
154
- # if !googleUS.blank?
155
- # KeywordStatistic.new(:keyword_id => k.id, :engine => :googleUS, :position => googleUS).save
156
- # say '.', :green, false
157
- # else
158
- # say '.', :red, false
159
- # end
160
-
161
- # # Bing
162
- # # bing = ::Ranking.new(:keyword => k.keyword, :url => account.domain, :limit =>100).from_bingAU
163
- # # if !bing.blank?
164
- # # KeywordStatistic.new(:keyword_id => k.id, :engine => :bing, :position => bing).save
165
- # # say '.', :green, false
166
- # # else
167
- # # say '.', :red, false
168
- # # end
169
-
170
-
171
- # # Yahoo
172
- # # yahoo = ::Ranking.new(:keyword => k.keyword, :url => account.domain, :limit =>100).from_yahooAU
173
- # # if !yahoo.blank?
174
- # # KeywordStatistic.new(:keyword_id => k.id, :engine => :yahoo, :position => yahoo).save
175
- # # say '.', :green, false
176
- # # else
177
- # # say '.', :red, false
178
- # # end
179
-
180
- # table << [k.keyword, google, googleUS]
181
- # end
182
-
183
- # say ''
184
- # print_table table
185
- # say ''
186
- # end
187
- # end
188
-
189
- # desc "export", "export keywords with positions"
190
- # option :file
191
- # def export(account)
192
- # account = Account.search(account)
193
- # if account.blank?
194
- # say 'no account found', :red
195
- # else
196
- # table = [['# Date', '# Keyword', '# Position']] # header
197
-
198
- # options[:file] = 'export.csv' unless options.includes? :file
199
- # CSV.open(options[:file], 'w') do |csv|
200
- # account.keywords.each do |keyword|
201
- # keyword.keyword_statistics.each do |stat|
202
- # row = [stat.created_at, keyword.keyword, stat.position]
203
- # table << row
204
- # csv << row
205
- # end
206
- # end
207
- # end
208
-
209
- # say ''
210
- # print_table table
211
- # say ''
212
- # end
213
- # end
214
- end
@@ -1,58 +0,0 @@
1
- module SubCommands
2
- class Series < Thor
3
- desc "ls", "list series"
4
- option :order, :type => :string, :default => "updated_at"
5
- def ls
6
- series = ::Series.all.order(options[:order].to_sym => :desc)
7
-
8
- series_stats = Statistics.new
9
- table = [['#', 'log', 'start', 'end', 'hours']] # header
10
- series.each do |s|
11
- next if s.log_id.blank?
12
-
13
- start = s.start
14
- finish = s.end
15
-
16
- # total time
17
- series_stats << timer = start.difference(finish || Time.now)
18
-
19
- start = start.display if start
20
- finish = finish.display if finish
21
-
22
- table << [s.id,
23
- Log.find(s.log_id).name,
24
- start, finish || "active",
25
- (timer/3600).round(2).to_s] # row
26
- end
27
- puts ''
28
- print_table table
29
- puts ''
30
-
31
- say [series.count.to_s, "series out of", ::Series.count].join(' '), :cyan
32
- say [(series_stats.mean/3600).round(2), " hours avg"].join(' '), :cyan
33
- end
34
-
35
- desc "rm [ID]", "remove series"
36
- option :confirm, :type => :boolean, :default => false, :alias => '-y'
37
- def rm(id)
38
- if ::Series.where(id: id).count == 0
39
- say "Series #" + id.to_s + " not found", :red
40
- exit
41
- end
42
-
43
- series = ::Series.find(id)
44
-
45
- if !options[:confirm]
46
- say "You must --confirm before removing this series", :red
47
- exit
48
- end
49
-
50
- if !series.finished?
51
- series.log.deactivate
52
- end
53
-
54
- destroyed = series.destroy
55
- say "Series #" + id.to_s + " has been destroyed", :green
56
- end
57
- end
58
- end