obst 0.1.7 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc318da9a56d9fd4593627a727f36a2ff01ab2e9ba5d1f4969bc4d299acce702
4
- data.tar.gz: 6f649344c285a743333d35d7bd4cf11844a38f810fee94040c3de7a46e75f8f4
3
+ metadata.gz: 8ceae774176f6f2f1ce1b638f7d3dcfd316405421f4942a5d0bb87f9c45a3e74
4
+ data.tar.gz: 1a4499843d98a6d4b41cb918c9afc7cabf00ab4a1a82bf10ef40af2a22c688f7
5
5
  SHA512:
6
- metadata.gz: 21c1eea8e6a53ba8c9f94d09d3996eee64f522bd503458600d4db87d584ceb1b2496d55fcb031123a8bcd0b3a3b957c9e6b36772921e8f7f71e19f537fe13b98
7
- data.tar.gz: b44b1782a1e95a5d791b90538e2023515a3da8d69432b76a93bd376d5ef65699190972675354c1c6a76a6233b6e5bf1e1bf171c0f78655a0dfd9917df39c0621
6
+ metadata.gz: ee87ab6d88d959604b220cb9a59203f53ade814af0ad0a6449f182785639891ce6dbcc85e6612394f8427a1a1127bea8137d94a0adf510a48049871bf33d95fc
7
+ data.tar.gz: ed0485c9bb2e1b7d07b7efac59ac88819e8290df741878d1e0d5772405690e3722baafb49ffb63d3bf4ad07f335f3567c4c7c95c7f7617d9615b03ad3cf4fa0e
data/README.md CHANGED
@@ -38,6 +38,21 @@ Group by Days
38
38
  Obst::GroupByDays.new(C: '/path/to/local/git/repo', after: '2022-10-20T00:00:00', days: 7)
39
39
  ```
40
40
 
41
+ ## Config
42
+
43
+ Place .obst.json under dir where you run obst. Content for example:
44
+
45
+ ```json
46
+ {
47
+ // for all stats
48
+ "pathspec": [":!.obsidian", ":!calendar"],
49
+ // for specific stats
50
+ "long_time_no_see": {
51
+ "pathspec": [":!.obsidian", ":!calendar"]
52
+ }
53
+ }
54
+ ```
55
+
41
56
  ## Development
42
57
 
43
58
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/exe/obst CHANGED
@@ -4,18 +4,25 @@ require "obst"
4
4
 
5
5
  path = ARGV[0] || '.'
6
6
 
7
+ # setup .gitignore
7
8
  gitignore = File.join(path, '.gitignore')
8
9
  File.open(gitignore, 'a+') do |f|
9
10
  f.puts("# Obst\nobst.md") unless f.read =~ /# Obst/
10
11
  end
11
12
 
13
+ # read config
14
+ cfg = Obst::Config.new(path)
15
+
16
+ # print stats
12
17
  obst_md = File.join(path, 'obst.md')
13
18
  File.open(obst_md, 'w') do |f|
14
19
  f.puts Obst::Chart::DailyCount.new(C: path).to_s
15
20
  f.puts "\n"
16
- f.puts Obst::Chart::DailyChange.new(C: path).to_s
21
+ f.puts Obst::Chart::DailyChange.new(C: path, cfg: cfg).to_s
22
+ f.puts "\n"
23
+ f.puts Obst::LongTimeNoSee.new(C: path, cfg: cfg).to_s
17
24
  f.puts "\n"
18
- f.puts Obst::LongTimeNoSee.new(C: path).to_s
25
+ f.puts Obst::TouchedFiles.new(C: path, cfg: cfg).to_s
19
26
  f.puts "\n"
20
- f.puts Obst::TouchedFiles.new(C: path).to_s
27
+ f.puts Obst::TagsCount.new(C: path, cfg: cfg).to_s
21
28
  end
data/lib/obst/chart.rb CHANGED
@@ -2,7 +2,8 @@ module Obst
2
2
  class Chart
3
3
  class DailyCount
4
4
  def initialize(**opts)
5
- @daily_gauge = Obst::DailyGauge.new(C: opts[:C]).lazy
5
+ pathspec = opts[:cfg]&.dig_any(['pathspec'], ['chart_daily_count', 'pathspec'])
6
+ @daily_gauge = Obst::DailyGauge.new(C: opts[:C], pathspec: pathspec).lazy
6
7
  end
7
8
 
8
9
  def to_s
@@ -30,7 +31,8 @@ module Obst
30
31
 
31
32
  class DailyChange
32
33
  def initialize(**opts)
33
- @daily = Obst::GroupByDays.new(C: opts[:C]).lazy
34
+ pathspec = opts[:cfg]&.dig_any(['pathspec'], ['chart_daily_change', 'pathspec'])
35
+ @daily = Obst::GroupByDays.new(C: opts[:C], pathspec: pathspec).lazy
34
36
  end
35
37
 
36
38
  def to_s
@@ -0,0 +1,27 @@
1
+ require "json"
2
+
3
+ module Obst
4
+ class Config
5
+ def initialize(dir)
6
+ @cfg = nil
7
+ location = File.join(dir, '.obst.json')
8
+ return @cfg = {} unless File.exist?(location)
9
+
10
+ File.open(location) do |f|
11
+ @cfg = JSON.parse(f.read)
12
+ end
13
+ end
14
+
15
+ def dig(*path)
16
+ @cfg.dig(*path)
17
+ end
18
+
19
+ def dig_any(*paths)
20
+ paths.each do |path|
21
+ v = dig(*path)
22
+ return v if v
23
+ end
24
+ nil
25
+ end
26
+ end
27
+ end
data/lib/obst/git_log.rb CHANGED
@@ -7,6 +7,7 @@ module Obst
7
7
  @cmd = ['git', '-C', path, 'log', '--name-status', '--pretty=format:%ad', "--date=format:'%Y-%m-%dT%H:%M:%S'"]
8
8
  @cmd << '--after' << opts[:after] if opts[:after]
9
9
  @cmd << '--before' << opts[:before] if opts[:before]
10
+ Array(opts[:pathspec]).each{ |s| @cmd << s }
10
11
  end
11
12
 
12
13
  def to_s
@@ -58,6 +59,9 @@ module Obst
58
59
  raise 'fail to loop git log' unless status_thread.value.success?
59
60
  end
60
61
  y << Commit.new(batch)
62
+ rescue => e
63
+ puts @cmd
64
+ raise e
61
65
  end
62
66
  end
63
67
  end
@@ -4,6 +4,9 @@ module Obst
4
4
  class LongTimeNoSee
5
5
  def initialize(**opts)
6
6
  opts = opts.merge(days: 7)
7
+ if cfg = opts[:cfg]
8
+ opts[:pathspec] ||= cfg.dig('long_time_no_see', 'pathspec')
9
+ end
7
10
  @weekly = LastSeen.new(**opts)
8
11
  end
9
12
 
data/lib/obst/notes.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "obst/group_by_days"
2
+
3
+ module Obst
4
+ class Notes
5
+ include Enumerable
6
+
7
+ def initialize(**opts)
8
+ location = opts[:C] || '.'
9
+
10
+ @notes = Enumerator.new do |enum|
11
+ note_klass = Struct.new(:name, :dates, :tags, :refs)
12
+ files = Dir.glob(File.join(location, '*.md')).map{|n| File.basename(n)}.to_set
13
+ file_dates = Hash.new{ |h, k| h[k] = [] }
14
+
15
+ GroupByDays.new(**opts).each do |log|
16
+ log.file_changes.each do |name, op|
17
+ file_dates[name] << log.time if files.include?(name)
18
+ end
19
+ end
20
+
21
+ file_dates.each_pair do |file, dates|
22
+ lines = File.foreach(File.join(location, file))
23
+ tags = lines.first&.scan(/#(\w+)/)&.flatten || []
24
+ refs = lines.each_with_object([]) do |line, arr|
25
+ line.scan(/\[\[(.+?)\]\]/).flatten.each do |n|
26
+ arr << n if files.include?("#{n}.md")
27
+ end
28
+ end
29
+ enum.yield(note_klass.new(file, dates, tags, refs))
30
+ end
31
+ end
32
+ end
33
+
34
+ def each(&block)
35
+ @notes.each(&block)
36
+ end
37
+
38
+ def tags
39
+ @gitlog.map(&:tags).flatten.tally.sort{ |t1, t2| [t2[1], t2[0]] <=> [t1[1], t1[0]] }.to_h
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ require 'obst/notes'
2
+
3
+ module Obst
4
+ class TagsCount
5
+ def initialize(**opts)
6
+ @notes = Notes.new(**opts)
7
+ end
8
+
9
+ def to_s
10
+ buffer = ["# Tags\n"]
11
+ @notes.map(&:tags).flatten.tally.sort{ |t1, t2| [t2[1], t2[0]] <=> [t1[1], t1[0]] }.each do |(tag, count)|
12
+ buffer << "- #{tag}: #{count}"
13
+ end
14
+ buffer.join("\n")
15
+ end
16
+ end
17
+ end
@@ -4,6 +4,12 @@ module Obst
4
4
  class TouchedFiles
5
5
  def initialize(**opts)
6
6
  @path = opts[:C]
7
+
8
+ @pathspec =
9
+ if cfg = opts[:cfg]
10
+ opts[:pathspec] ||= cfg.dig_any(['pathspec'], ['touched_files', 'pathspec'])
11
+ end
12
+
7
13
  @buffer = ["# Touch files in periods\n"]
8
14
  end
9
15
 
@@ -17,7 +23,7 @@ module Obst
17
23
  def last_7_days
18
24
  @buffer << "- Last 7 days"
19
25
 
20
- GroupByDays.new(C: @path).take(7).each do |record|
26
+ GroupByDays.new(C: @path, pathspec: @pathspec).take(7).each do |record|
21
27
  @buffer << "\t- #{record.date_wday} (#{record.file_changes.count})"
22
28
  list_files(record)
23
29
  end
@@ -28,7 +34,7 @@ module Obst
28
34
 
29
35
  @buffer << "- 1 week ago"
30
36
 
31
- GroupByDays.new(C: @path, before: before, days: 7).take(3).each_with_index do |record, i|
37
+ GroupByDays.new(C: @path, before: before, days: 7, pathspec: @pathspec).take(3).each_with_index do |record, i|
32
38
  @buffer << "\t- #{record.time} is #{1+i}.week#{suffix_s(i)}.ago (#{record.file_changes.count})"
33
39
  list_files(record)
34
40
  end
@@ -39,7 +45,7 @@ module Obst
39
45
 
40
46
  @buffer << "- 1 month ago"
41
47
 
42
- GroupByDays.new(C: @path, before: before, days: 28).take(2).each_with_index do |record, i|
48
+ GroupByDays.new(C: @path, before: before, days: 28, pathspec: @pathspec).take(2).each_with_index do |record, i|
43
49
  @buffer << "\t- #{record.time} is #{1+i}.month#{suffix_s(i)}.ago (#{record.file_changes.count})"
44
50
  list_files(record)
45
51
  end
data/lib/obst/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Obst
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/obst.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require "obst/version"
2
+ require "obst/config"
2
3
  require "obst/git_log"
3
4
  require "obst/group_by_days"
4
5
  require "obst/touched_files"
5
6
  require "obst/long_time_no_see"
6
7
  require "obst/daily_gauge"
7
8
  require "obst/chart"
9
+ require "obst/tags_count"
8
10
 
9
11
  module Obst
10
12
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-27 00:00:00.000000000 Z
11
+ date: 2024-02-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email:
15
15
  - block24block@gmail.com
16
16
  executables:
@@ -30,13 +30,16 @@ files:
30
30
  - exe/obst
31
31
  - lib/obst.rb
32
32
  - lib/obst/chart.rb
33
+ - lib/obst/config.rb
33
34
  - lib/obst/daily_gauge.rb
34
35
  - lib/obst/daily_increment.rb
35
36
  - lib/obst/git_log.rb
36
37
  - lib/obst/group_by_days.rb
37
38
  - lib/obst/last_seen.rb
38
39
  - lib/obst/long_time_no_see.rb
40
+ - lib/obst/notes.rb
39
41
  - lib/obst/pack_log.rb
42
+ - lib/obst/tags_count.rb
40
43
  - lib/obst/touched_files.rb
41
44
  - lib/obst/version.rb
42
45
  - obst.gemspec
@@ -44,7 +47,7 @@ homepage: https://github.com/turnon/obst
44
47
  licenses:
45
48
  - MIT
46
49
  metadata: {}
47
- post_install_message:
50
+ post_install_message:
48
51
  rdoc_options: []
49
52
  require_paths:
50
53
  - lib
@@ -59,8 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
62
  - !ruby/object:Gem::Version
60
63
  version: '0'
61
64
  requirements: []
62
- rubygems_version: 3.1.6
63
- signing_key:
65
+ rubygems_version: 3.4.10
66
+ signing_key:
64
67
  specification_version: 4
65
68
  summary: Obsidian stats
66
69
  test_files: []