obst 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/obst +4 -0
- data/lib/obst/chart.rb +71 -0
- data/lib/obst/daily_gauge.rb +35 -0
- data/lib/obst/daily_increment.rb +19 -0
- data/lib/obst/group_by_days.rb +2 -0
- data/lib/obst/pack_log.rb +31 -17
- data/lib/obst/touched_files.rb +20 -7
- data/lib/obst/version.rb +1 -1
- data/lib/obst.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 242b86d9f4b9803a8ec4b2bf0b6f607fe2c96fce7c6e866e33cb6d825bdd4034
|
4
|
+
data.tar.gz: 1185c3a07dfebee41587ca1798162f91d5ad4b8523e37ba2fb666736249ed9af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd6a577d0285df5afdbc8001b054da94085a94430bc2b71cb0c720582bfd3a14b319d8741d3635bcff8ed5cf078370d33c296a3a445f1dcb0d79612b80021fb9
|
7
|
+
data.tar.gz: f9cc2c8f792fef0a4b043e7065b2e4db232fcbd01be8c9287e8bb081b68f5a6953cb73d910b9160ec3a81ac6daeaa459c5ce04c77bf1f806aaf6154d559e39d4
|
data/exe/obst
CHANGED
@@ -11,5 +11,9 @@ end
|
|
11
11
|
|
12
12
|
obst_md = File.join(path, 'obst.md')
|
13
13
|
File.open(obst_md, 'w') do |f|
|
14
|
+
f.puts Obst::Chart::DailyCount.new(C: path).to_s
|
15
|
+
f.puts "\n"
|
16
|
+
f.puts Obst::Chart::DailyChange.new(C: path).to_s
|
17
|
+
f.puts "\n"
|
14
18
|
f.puts Obst::TouchedFiles.new(C: path).to_s
|
15
19
|
end
|
data/lib/obst/chart.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module Obst
|
2
|
+
class Chart
|
3
|
+
class DailyCount
|
4
|
+
def initialize(**opts)
|
5
|
+
@daily_gauge = Obst::DailyGauge.new(C: opts[:C]).lazy
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
labels, data = [], []
|
10
|
+
@daily_gauge.take(28 * 3).each do |time_count|
|
11
|
+
labels << time_count.time.strftime('%F %a')
|
12
|
+
data << time_count.count
|
13
|
+
end
|
14
|
+
|
15
|
+
<<~EOF
|
16
|
+
# Daily count
|
17
|
+
|
18
|
+
```chart
|
19
|
+
type: line
|
20
|
+
width: 98%
|
21
|
+
legendPosition: bottom
|
22
|
+
labels: #{labels.reverse!}
|
23
|
+
series:
|
24
|
+
- title: current #{data[0]}
|
25
|
+
data: #{data.reverse!}
|
26
|
+
```
|
27
|
+
EOF
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class DailyChange
|
32
|
+
def initialize(**opts)
|
33
|
+
@daily = Obst::GroupByDays.new(C: opts[:C]).lazy
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
labels = []
|
38
|
+
datas = {a: [], m: [], d: [], nil => []}
|
39
|
+
|
40
|
+
@daily.take(28 * 3).each do |record|
|
41
|
+
labels << record.date_wday
|
42
|
+
datas.each_value{ |data| data << 0 }
|
43
|
+
|
44
|
+
record.file_changes.each_value do |changes|
|
45
|
+
datas[changes.final][-1] += 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
<<~EOF
|
50
|
+
# Daily change
|
51
|
+
|
52
|
+
```chart
|
53
|
+
type: line
|
54
|
+
width: 98%
|
55
|
+
legendPosition: bottom
|
56
|
+
labels: #{labels.reverse!}
|
57
|
+
series:
|
58
|
+
- title: del
|
59
|
+
data: #{datas[:d].reverse!}
|
60
|
+
- title: nil
|
61
|
+
data: #{datas[nil].reverse!}
|
62
|
+
- title: mod
|
63
|
+
data: #{datas[:m].reverse!}
|
64
|
+
- title: new
|
65
|
+
data: #{datas[:a].reverse!}
|
66
|
+
```
|
67
|
+
EOF
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "open3"
|
2
|
+
require "obst/daily_increment"
|
3
|
+
|
4
|
+
module Obst
|
5
|
+
class DailyGauge
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def initialize(**opts)
|
9
|
+
@path = opts[:C] || '.'
|
10
|
+
end
|
11
|
+
|
12
|
+
ONE_DAY = 60 * 60 * 24
|
13
|
+
TimeCount = Struct.new(:time, :count)
|
14
|
+
|
15
|
+
def each(&block)
|
16
|
+
return self unless block
|
17
|
+
|
18
|
+
time = Time.parse(Time.now.strftime('%F'))
|
19
|
+
tot = total_now
|
20
|
+
block.call(TimeCount.new(time, tot))
|
21
|
+
|
22
|
+
DailyIncrement.new(C: @path).each do |incr|
|
23
|
+
time -= ONE_DAY
|
24
|
+
tot -= incr
|
25
|
+
block.call(TimeCount.new(time, tot))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def total_now
|
30
|
+
total = 0
|
31
|
+
Open3.pipeline_r(['git', '-C', @path, 'ls-files'], ['wc', '-l']){ |stdout| total = stdout.read.to_i }
|
32
|
+
total
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "obst/group_by_days"
|
2
|
+
|
3
|
+
module Obst
|
4
|
+
class DailyIncrement
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(**opts)
|
8
|
+
@group_by_day = GroupByDays.new(**opts)
|
9
|
+
end
|
10
|
+
|
11
|
+
def each(&block)
|
12
|
+
return self unless block
|
13
|
+
|
14
|
+
@group_by_day.each do |pack_log_record|
|
15
|
+
block.call(pack_log_record.increment)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/obst/group_by_days.rb
CHANGED
data/lib/obst/pack_log.rb
CHANGED
@@ -9,7 +9,7 @@ module Obst
|
|
9
9
|
@time_fix = block
|
10
10
|
end
|
11
11
|
|
12
|
-
class
|
12
|
+
class Changes
|
13
13
|
def <<(st)
|
14
14
|
@arr ||= []
|
15
15
|
@arr << st if @arr.last != st
|
@@ -20,34 +20,48 @@ module Obst
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def final
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
if @arr[0] == :d
|
24
|
+
return @arr[-1] == :a ? nil : :d
|
25
|
+
end
|
26
|
+
|
27
|
+
@arr[-1] == :a ? :a : :m
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
Record = Struct.new(:time, :
|
30
|
-
def
|
31
|
-
|
32
|
-
statuses.each_value do |status|
|
33
|
-
sum[status.final] += 1
|
34
|
-
end
|
35
|
-
sum
|
31
|
+
Record = Struct.new(:time, :file_changes) do
|
32
|
+
def date_wday
|
33
|
+
Time.parse(time).strftime('%F %a')
|
36
34
|
end
|
37
35
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def increment
|
37
|
+
file_changes.each_value.reduce(0) do |sum, changes|
|
38
|
+
sum +=
|
39
|
+
case changes.final
|
40
|
+
when :a
|
41
|
+
1
|
42
|
+
when :d
|
43
|
+
-1
|
44
|
+
else
|
45
|
+
0
|
46
|
+
end
|
42
47
|
end
|
43
|
-
sb.join(', ')
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
51
|
+
# yield PackLog::Record(
|
52
|
+
# time:Any,
|
53
|
+
# file_changes:Hash{
|
54
|
+
# name1 => [:m, :a],
|
55
|
+
# name2 => [:d, :m],
|
56
|
+
# ...
|
57
|
+
# }
|
58
|
+
# )
|
47
59
|
def each(&block)
|
60
|
+
return self unless block
|
61
|
+
|
48
62
|
current_time = nil
|
49
63
|
renames = {}
|
50
|
-
files_in_one_day = Hash.new{ |files, name| files[name] =
|
64
|
+
files_in_one_day = Hash.new{ |files, name| files[name] = Changes.new }
|
51
65
|
|
52
66
|
@commits.each do |commit|
|
53
67
|
committed_at = @time_fix.call(commit.committed_at)
|
data/lib/obst/touched_files.rb
CHANGED
@@ -20,8 +20,7 @@ module Obst
|
|
20
20
|
@buffer << "# Last 7 days\n"
|
21
21
|
|
22
22
|
GroupByDays.new(C: @path).take(7).each do |record|
|
23
|
-
|
24
|
-
@buffer << "- #{record.time} #{wday} (#{record.statuses.size})"
|
23
|
+
@buffer << "- #{record.date_wday} (#{record.file_changes.count})"
|
25
24
|
list_files(record)
|
26
25
|
end
|
27
26
|
end
|
@@ -32,7 +31,7 @@ module Obst
|
|
32
31
|
@buffer << "# 3 weeks earlier\n"
|
33
32
|
|
34
33
|
GroupByDays.new(C: @path, before: before, days: 7).take(3).each do |record|
|
35
|
-
@buffer << "- #{record.time} (#{record.
|
34
|
+
@buffer << "- #{record.time} (#{record.file_changes.count})"
|
36
35
|
list_files(record)
|
37
36
|
end
|
38
37
|
end
|
@@ -43,16 +42,30 @@ module Obst
|
|
43
42
|
@buffer << "# 1 month earlier\n"
|
44
43
|
|
45
44
|
GroupByDays.new(C: @path, before: before, days: 28).take(2).each do |record|
|
46
|
-
@buffer << "- #{record.time} (#{record.
|
45
|
+
@buffer << "- #{record.time} (#{record.file_changes.count})"
|
47
46
|
list_files(record)
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
50
|
def list_files(record)
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
group_by_final_status = Hash.new{ |h, k| h[k] = [] }
|
52
|
+
record.file_changes.each_pair{ |file, status| group_by_final_status[status.final] << file }
|
53
|
+
|
54
|
+
[
|
55
|
+
[:new, :a, '#2db7b5'],
|
56
|
+
[:mod, :m, '#d3be03'],
|
57
|
+
[:del, :d, '#c71585'],
|
58
|
+
[:nil, nil, 'grey']
|
59
|
+
].each do |long, short, color|
|
60
|
+
files = group_by_final_status[short]
|
61
|
+
next if files.empty?
|
62
|
+
inline_str = inline(files)
|
63
|
+
@buffer << "\t- <font color='#{color}'>#{long} #{files.count}:</font> #{inline_str}"
|
55
64
|
end
|
56
65
|
end
|
66
|
+
|
67
|
+
def inline(files)
|
68
|
+
files.sort!.map{ |name| "[[#{name}]]" }.join(' / ')
|
69
|
+
end
|
57
70
|
end
|
58
71
|
end
|
data/lib/obst/version.rb
CHANGED
data/lib/obst.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obst
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -29,6 +29,9 @@ files:
|
|
29
29
|
- bin/setup
|
30
30
|
- exe/obst
|
31
31
|
- lib/obst.rb
|
32
|
+
- lib/obst/chart.rb
|
33
|
+
- lib/obst/daily_gauge.rb
|
34
|
+
- lib/obst/daily_increment.rb
|
32
35
|
- lib/obst/git_log.rb
|
33
36
|
- lib/obst/group_by_days.rb
|
34
37
|
- lib/obst/pack_log.rb
|