gitwakatime 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/gitwakatime/cli.rb +4 -2
- data/lib/gitwakatime/commit.rb +1 -1
- data/lib/gitwakatime/durations.rb +19 -13
- data/lib/gitwakatime/mapper.rb +2 -2
- data/lib/gitwakatime/query.rb +8 -5
- data/lib/gitwakatime/version.rb +1 -1
- data/spec/durations_spec.rb +18 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87b1a52859dcdf8ad54d5be75e5c981961e56fab
|
4
|
+
data.tar.gz: e8c3f862a72c6e6717eaaa553624e51cce2b9d4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92157e1509a6f4f05b3ce58b86df8a13c0f4ffd9788204ad82b69b2cdb4850952723cc997ccb9c592702d9144c5872b5a32c02656a498bab6410d03df8b47d54
|
7
|
+
data.tar.gz: 44b4acdc179a5d4d976e56bd43758d52f09320fa6c12b62d6e6907f81c617051de062f36803c4dab86eb1726f2ed3637e784848cd51d55447693bc02d3b2fb4c
|
data/README.md
CHANGED
@@ -39,6 +39,11 @@ Hard reset of the local cache database, if you are getting odd numbers
|
|
39
39
|
|
40
40
|
$ gitwakatime reset
|
41
41
|
|
42
|
+
## Assumptions
|
43
|
+
|
44
|
+
There a currently a few limitations with this model
|
45
|
+
|
46
|
+
* Merges are free, (no time is attributed a merge). This is true for most merges but conflict resolution will be attributed to git parent commit of that file for that merge.
|
42
47
|
|
43
48
|
## Output
|
44
49
|
Total Recorded time 1 day 9 hrs 13 mins 32 secs
|
data/lib/gitwakatime/cli.rb
CHANGED
@@ -50,9 +50,11 @@ module GitWakaTime
|
|
50
50
|
GitWakaTime.config.load_config_yaml
|
51
51
|
GitWakaTime.config.git = Git.open(path)
|
52
52
|
@git_map = Mapper.new(start_at: date)
|
53
|
-
@
|
53
|
+
@project = File.basename(GitWakaTime.config.git.dir.path)
|
54
|
+
@relevant_commits = Commit.where('date > ? and project = ?', date, @project).all
|
55
|
+
@actions = Query.new(@relevant_commits, File.basename(path)).get
|
54
56
|
|
55
|
-
@timer = Timer.new(
|
57
|
+
@timer = Timer.new(@relevant_commits, @actions, File.basename(path)).process
|
56
58
|
|
57
59
|
@timer.each do |date, commits|
|
58
60
|
Log.new format('%-40s %-40s'.blue,
|
data/lib/gitwakatime/commit.rb
CHANGED
@@ -13,7 +13,7 @@ module GitWakaTime
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def load_actions
|
16
|
-
unless cached?
|
16
|
+
unless cached?
|
17
17
|
|
18
18
|
Log.new "querying WakaTime actions for #{@project}"
|
19
19
|
time = Benchmark.realtime do
|
@@ -27,34 +27,40 @@ module GitWakaTime
|
|
27
27
|
|
28
28
|
Log.new "API took #{time}s"
|
29
29
|
persist_actions_localy(@actions)
|
30
|
-
|
30
|
+
end
|
31
31
|
true
|
32
32
|
end
|
33
33
|
|
34
34
|
def persist_actions_localy(actions)
|
35
|
-
actions.
|
36
|
-
|
37
|
-
Action.find_or_create(uuid: action['id']) do |c|
|
35
|
+
sterile_actions = actions.map do |action|
|
38
36
|
action['uuid'] = action['id']
|
39
37
|
action['time'] = Time.at(action['time'])
|
40
38
|
action.delete('id')
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
Action.find_or_create(uuid: action['uuid']) do |a|
|
40
|
+
a.update(action)
|
41
|
+
end
|
44
42
|
end
|
43
|
+
|
45
44
|
end
|
46
45
|
|
47
|
-
def cached?
|
46
|
+
def cached?
|
48
47
|
# Check to see if this date range might be stale?
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
if cached_actions.count > 0
|
49
|
+
max_local_timetamp = (Time.parse(cached_actions.max(:time)) + 3.day).to_date
|
50
|
+
!(@args[:start].to_date..@args[:end].to_date).include?(max_local_timetamp)
|
51
|
+
else
|
52
|
+
false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def cached_actions
|
57
|
+
Action.where('time >= ?',@args[:end]).where(project: @project)
|
52
58
|
end
|
53
59
|
|
54
60
|
def actions_to_durations(_project = nil, timeout = 15)
|
55
61
|
durations = []
|
56
62
|
current = nil
|
57
|
-
|
63
|
+
|
58
64
|
@actions.each do | action |
|
59
65
|
# the first action just sets state and does nothing
|
60
66
|
unless current.nil?
|
data/lib/gitwakatime/mapper.rb
CHANGED
@@ -10,8 +10,8 @@ module GitWakaTime
|
|
10
10
|
logs = g.log(commits).since(start_at).until(Date.today)
|
11
11
|
|
12
12
|
@commits = logs.map do |git_c|
|
13
|
-
|
14
13
|
next if git_c.author.name != GitWakaTime.config.user_name
|
14
|
+
next if git_c.parents.size > 1
|
15
15
|
Commit.find_or_create(
|
16
16
|
sha: git_c.sha,
|
17
17
|
project: project
|
@@ -19,7 +19,7 @@ module GitWakaTime
|
|
19
19
|
c.update(
|
20
20
|
author: git_c.author.name,
|
21
21
|
message: git_c.message,
|
22
|
-
date: git_c.date
|
22
|
+
date: git_c.date.utc
|
23
23
|
)
|
24
24
|
end
|
25
25
|
end.compact
|
data/lib/gitwakatime/query.rb
CHANGED
@@ -7,7 +7,7 @@ module GitWakaTime
|
|
7
7
|
class Query
|
8
8
|
def initialize(commits, project, _path = nil)
|
9
9
|
@commits = commits
|
10
|
-
@api_limit =
|
10
|
+
@api_limit = 35
|
11
11
|
@project = project
|
12
12
|
@requests = time_params
|
13
13
|
end
|
@@ -29,17 +29,20 @@ module GitWakaTime
|
|
29
29
|
commits = @commits.map(&:date)
|
30
30
|
d_commits = CommitedFile.select(:dependent_date).all.map { |f| f.values[:dependent_date] }.compact
|
31
31
|
timestamps = (commits + d_commits.flatten).uniq.sort
|
32
|
-
|
32
|
+
|
33
|
+
# Don't query before the Wakatime Epoch
|
34
|
+
@start_at = timestamps.first >= Time.new(2013, 5, 1) ? timestamps.first : Time.new(2013, 5, 1)
|
33
35
|
@end_at = timestamps.last
|
36
|
+
|
34
37
|
# Always have a date range great than 1 as the num request will be 0/1 otherwise
|
35
|
-
num_requests = ((
|
38
|
+
num_requests = ((@end_at.to_date + 1) - @start_at.to_date) / @api_limit
|
36
39
|
i = 0
|
37
40
|
|
38
41
|
request_params = num_requests.to_f.ceil.times.map do
|
39
42
|
|
40
43
|
params = {
|
41
|
-
start: (
|
42
|
-
end: (
|
44
|
+
start: (@start_at.to_date + (i * @api_limit)).to_time.beginning_of_day,
|
45
|
+
end: (@start_at.to_date + ((i + 1) * @api_limit)).to_time.end_of_day,
|
43
46
|
project: @project,
|
44
47
|
show: 'file,branch,project,time,id'
|
45
48
|
}
|
data/lib/gitwakatime/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'description' do
|
4
|
+
# let (:git) { Git.open(@wdir) }
|
5
|
+
before(:each) do
|
6
|
+
# GitWakaTime.config.git = git
|
7
|
+
# GitWakaTime::Mapper.new(start_at: Date.new(2015, 1, 28))
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'checks cached state' do
|
11
|
+
pending
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'calculates durations of actions' do
|
15
|
+
pending
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitwakatime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Osborne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -271,6 +271,7 @@ files:
|
|
271
271
|
- spec/dummy/dot_git/sourcetreeconfig
|
272
272
|
- spec/dummy/hi
|
273
273
|
- spec/dummy/readme
|
274
|
+
- spec/durations_spec.rb
|
274
275
|
- spec/fixtures/actions.json
|
275
276
|
- spec/mapper_spec.rb
|
276
277
|
- spec/query_spec.rb
|
@@ -352,9 +353,9 @@ test_files:
|
|
352
353
|
- spec/dummy/dot_git/sourcetreeconfig
|
353
354
|
- spec/dummy/hi
|
354
355
|
- spec/dummy/readme
|
356
|
+
- spec/durations_spec.rb
|
355
357
|
- spec/fixtures/actions.json
|
356
358
|
- spec/mapper_spec.rb
|
357
359
|
- spec/query_spec.rb
|
358
360
|
- spec/spec_helper.rb
|
359
361
|
- spec/timer_spec.rb
|
360
|
-
has_rdoc:
|