obst 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1ea9ec553aec1048f197a4313bb6f5bdb82767e78fe793764127e1b798ee5b7
4
- data.tar.gz: 8cfa17989074c75b146f5979cd30e33ea05a062cc3e1347efb1677dd6c4c2a44
3
+ metadata.gz: 242b86d9f4b9803a8ec4b2bf0b6f607fe2c96fce7c6e866e33cb6d825bdd4034
4
+ data.tar.gz: 1185c3a07dfebee41587ca1798162f91d5ad4b8523e37ba2fb666736249ed9af
5
5
  SHA512:
6
- metadata.gz: 13b20ea98bc4cedacfee5a11b267f3f2a263fbcadd9d7a3de83061c17af55257701801dca6cabb687236b2c193bd2accfd99d53a9a8ed121471486e6484473c8
7
- data.tar.gz: a2cda68907af8dd8c15f1f31d00afb977e297e3461bf5bbafc7adbccfc9c06801407dd7a68c0898b19a6585e0c8d6ffa86e598e7be2961e09d5a40cb8d1f8df6
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
@@ -28,6 +28,8 @@ module Obst
28
28
  end
29
29
 
30
30
  def each(&block)
31
+ return self unless block
32
+
31
33
  current_time = @timeline.next
32
34
  record = @log.next
33
35
 
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 Statuses
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
- return :d if @arr[0] == :d
24
- return :a if @arr[-1] == :a
25
- :m
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, :statuses) do
30
- def status_sum
31
- sum = Hash.new{ |h, k| h[k] = 0 }
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 str_status_sum
39
- sb = []
40
- status_sum.each_pair do |st, count|
41
- sb << "#{st}: #{count}"
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] = Statuses.new }
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)
@@ -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
- wday = Time.parse(record.time).strftime('%a')
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.statuses.size})"
34
+ @buffer << "- #{record.time} (#{record.file_changes.count})"
36
35
  list_files(record)
37
36
  end
38
37
  end
@@ -43,19 +42,20 @@ 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.statuses.size})"
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
51
  group_by_final_status = Hash.new{ |h, k| h[k] = [] }
53
- record.statuses.each_pair{ |name, status| group_by_final_status[status.final] << name }
52
+ record.file_changes.each_pair{ |file, status| group_by_final_status[status.final] << file }
54
53
 
55
54
  [
56
55
  [:new, :a, '#2db7b5'],
57
56
  [:mod, :m, '#d3be03'],
58
- [:del, :d, '#c71585']
57
+ [:del, :d, '#c71585'],
58
+ [:nil, nil, 'grey']
59
59
  ].each do |long, short, color|
60
60
  files = group_by_final_status[short]
61
61
  next if files.empty?
data/lib/obst/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Obst
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/obst.rb CHANGED
@@ -2,6 +2,8 @@ require "obst/version"
2
2
  require "obst/git_log"
3
3
  require "obst/group_by_days"
4
4
  require "obst/touched_files"
5
+ require "obst/daily_gauge"
6
+ require "obst/chart"
5
7
 
6
8
  module Obst
7
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
@@ -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