mps 1.0.0 → 1.0.1

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: f8ae3859e4782a907b27a5e50e630cb9a4f4c1ee4cb6a995302144ff7e710b5d
4
- data.tar.gz: e28971415998d6ab59761c48b148e4209e4adfe3b11cca0549a468a09fcc35a0
3
+ metadata.gz: 96b0eac30435621ea7ca9d0575d3a3285a074cb2707d453075ced7e1535ca288
4
+ data.tar.gz: 647d49ad9cffd798858318dd712d4653df718e37d05a8f52803be367e423c17c
5
5
  SHA512:
6
- metadata.gz: 4a991ff844ef540c3e155e8d676b1ca6602367dfe7be385d5cbef2cce6478b850cf63e4fdf6a314f09913e2d5f6fc367c40def4236d6b1d3cb52992295a2a8ee
7
- data.tar.gz: 69891a0155275f35a0060dc5bada88fb124d13c6d5b1b22dff84308db38c48b2d7371d304de6d1dd93eb9da8b75018c5a2853afaa8e483ae15aac93b30358640
6
+ metadata.gz: e1204e48c493e45f0dc226b1a7a4de0751b4821774ab5984c54f56cf53e91ac99cb09a17fb5cf777de0cf665ebefd69289913de935baf5655d3afd76f80da9bf
7
+ data.tar.gz: bbb938d0b337b652c07cca9983949a830c13fd9180ab037df87bd75feda68a6e11dfbc091689fa96546edc1e6f5f02e770b98a6d896c32b90de2b95b0fcaae00
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mps (1.0.0)
4
+ mps (1.0.1)
5
5
  chronic (~> 0.10.2)
6
6
  cli-ui (~> 2.2)
7
7
  thor (~> 1.3)
@@ -20,11 +20,16 @@ MPS::CLI::MPS.class_eval do
20
20
  def list(datesign = "today")
21
21
  init
22
22
  begin
23
- dates = if options[:all]
24
- store.all_files.map { |f| Date.strptime(File.basename(f)[0, 8], "%Y%m%d") }.uniq.sort
23
+ all_dates = store.all_files
24
+ .map { |f| Date.strptime(File.basename(f)[0, 8], "%Y%m%d") }
25
+ .uniq.sort
26
+ dates = if options[:all] && options[:since]
27
+ since_date = ::MPS.get_date(options[:since]).to_date
28
+ all_dates.select { |d| d >= since_date }
29
+ elsif options[:all]
30
+ all_dates
25
31
  elsif options[:since]
26
- date = ::MPS.get_date(datesign)
27
- date_range(options[:since], date)
32
+ date_range(options[:since], ::MPS.get_date(datesign))
28
33
  else
29
34
  [::MPS.get_date(datesign).to_date]
30
35
  end
@@ -2,13 +2,25 @@
2
2
 
3
3
  MPS::CLI::MPS.class_eval do
4
4
  desc "stats [DATESIGN]", "Show element counts and log durations"
5
- method_option :since, type: :string, aliases: "-S",
6
- desc: "Stats from SINCE up to DATESIGN"
5
+ method_option :since, type: :string, aliases: "-S", desc: "Stats from SINCE up to DATESIGN"
6
+ method_option :all, type: :boolean, aliases: "-a", default: false,
7
+ desc: "Stats across all dates"
7
8
  def stats(datesign = "today")
8
9
  init
9
10
  begin
10
- date = ::MPS.get_date(datesign)
11
- dates = options[:since] ? date_range(options[:since], date) : [date.to_date]
11
+ dates = if options[:all] && options[:since]
12
+ since_date = ::MPS.get_date(options[:since]).to_date
13
+ store.all_files.map { |f| Date.strptime(File.basename(f)[0, 8], "%Y%m%d") }
14
+ .uniq.sort.select { |d| d >= since_date }
15
+ elsif options[:all]
16
+ store.all_files.map { |f| Date.strptime(File.basename(f)[0, 8], "%Y%m%d") }.uniq.sort
17
+ elsif options[:since]
18
+ date = ::MPS.get_date(datesign)
19
+ date_range(options[:since], date)
20
+ else
21
+ date = ::MPS.get_date(datesign)
22
+ [date.to_date]
23
+ end
12
24
 
13
25
  total = Hash.new(0)
14
26
  total_log_mins = 0
@@ -1,17 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  MPS::CLI::MPS.class_eval do
4
- desc "tags [DATESIGN]", "Show tag usage counts (equivalent to mps list tags)"
5
- method_option :type, type: :string, aliases: "-t", desc: "Filter by element type"
6
- method_option :since, type: :string, aliases: "-S", desc: "From SINCE up to DATESIGN"
7
- method_option :status, type: :string, aliases: "-s", desc: "Filter tasks by status"
4
+ desc "tags [DATESIGN]", "Show tag usage table with frequency bars"
5
+ method_option :type, type: :string, aliases: "-t", desc: "Filter by element type"
6
+ method_option :since, type: :string, aliases: "-S", desc: "From SINCE up to DATESIGN"
7
+ method_option :status, type: :string, aliases: "-s", desc: "Filter tasks by status"
8
+ method_option :all, type: :boolean, aliases: "-a", default: false,
9
+ desc: "Count tags across all dates"
8
10
  def tags(datesign = "today")
9
11
  init
10
12
  begin
11
- date = ::MPS.get_date(datesign)
12
- dates = options[:since] ? date_range(options[:since], date) : [date.to_date]
13
- q = ::MPS::Query.new(options)
13
+ dates = if options[:all] && options[:since]
14
+ since_date = ::MPS.get_date(options[:since]).to_date
15
+ store.all_files.map { |f| Date.strptime(File.basename(f)[0, 8], "%Y%m%d") }
16
+ .uniq.sort.select { |d| d >= since_date }
17
+ elsif options[:all]
18
+ store.all_files.map { |f| Date.strptime(File.basename(f)[0, 8], "%Y%m%d") }.uniq.sort
19
+ elsif options[:since]
20
+ date_range(options[:since], ::MPS.get_date(datesign))
21
+ else
22
+ [::MPS.get_date(datesign).to_date]
23
+ end
14
24
 
25
+ q = ::MPS::Query.new(options)
15
26
  counts = Hash.new(0)
16
27
  dates.each do |d|
17
28
  q.apply(store.parse_date(d)).each_value do |el|
@@ -21,11 +32,24 @@ MPS::CLI::MPS.class_eval do
21
32
 
22
33
  if counts.empty?
23
34
  say set_color("(no tags found)", :yellow)
24
- else
25
- counts.sort_by { |_, v| -v }.each do |tag, n|
26
- say " #{set_color(tag, :white)} (#{n})"
27
- end
35
+ return
36
+ end
37
+
38
+ sorted = counts.sort_by { |_, v| -v }
39
+ max_cnt = sorted.first[1]
40
+ max_tag = sorted.map(&:first).map(&:length).max
41
+ bar_max = 24
42
+
43
+ say set_color(" #{"Tag".ljust(max_tag)} Count Frequency", :white)
44
+ say set_color(" #{"-" * max_tag} ----- #{"-" * bar_max}", :white)
45
+ sorted.each do |tag, n|
46
+ bar_len = (n.to_f / max_cnt * bar_max).ceil
47
+ bar = set_color("█" * bar_len, :cyan)
48
+ say " #{set_color(tag.ljust(max_tag), :white)} #{n.to_s.rjust(5)} #{bar}"
28
49
  end
50
+ total = counts.values.sum
51
+ say ""
52
+ say set_color(" #{sorted.size} tag#{sorted.size == 1 ? '' : 's'}, #{total} total uses", :white)
29
53
  rescue StandardError => e
30
54
  raise Thor::Error, e
31
55
  end
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Collect all schema-declared attribute flags for the update command.
4
- # This runs at class-load time so options are available to Thor.
5
- _all_schema_attrs = ::MPS::Elements.constants
6
- .map { |k| ::MPS::Elements.const_get(k) }
7
- .select { |x| x.class == Class }
8
- .flat_map { |klass| klass.schema.to_a }
9
- .uniq { |name, _| name }
10
- .select { |_, defn| defn[:flag] }
11
-
12
3
  MPS::CLI::MPS.class_eval do
4
+ # Returns all schema-declared attribute definitions across every element type.
5
+ # Called at class-load time (for method_option registration) and at call time
6
+ # (inside the update method body). A class method survives both contexts.
7
+ def self._schema_update_attrs
8
+ ::MPS::Elements.constants
9
+ .map { |k| ::MPS::Elements.const_get(k) }
10
+ .select { |x| x.class == Class }
11
+ .flat_map { |klass| klass.schema.to_a }
12
+ .uniq { |name, _| name }
13
+ .select { |_, defn| defn[:flag] }
14
+ end
15
+
13
16
  desc "update REFPATH", "Update an element's attributes in-place"
14
- _all_schema_attrs.each do |_name, defn|
17
+ _schema_update_attrs.each do |_name, defn|
15
18
  method_option defn[:flag], type: :string, desc: "Set #{defn[:flag]}"
16
19
  end
17
20
  method_option :date, type: :string, aliases: "-d",
@@ -21,7 +24,7 @@ MPS::CLI::MPS.class_eval do
21
24
  begin
22
25
  date = options[:date] ? ::MPS.get_date(options[:date]).to_date : Date.today
23
26
  new_attrs = {}
24
- _all_schema_attrs.each do |name, defn|
27
+ self.class._schema_update_attrs.each do |name, defn|
25
28
  flag_sym = defn[:flag].tr("-", "_").to_sym
26
29
  new_attrs[name] = options[flag_sym] if options[flag_sym]
27
30
  end
data/lib/mps/mps.rb CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  module MPS
4
4
  def self.get_date(str)
5
- Chronic.parse(str).to_date
5
+ result = Chronic.parse(str)
6
+ raise ArgumentError, "Cannot parse date: #{str.inspect}" unless result
7
+ result.to_date
6
8
  end
7
9
 
8
10
  def self.get_filename_from_date(date)
@@ -56,6 +56,7 @@ module MPS
56
56
  next if depth <= 0 # skip synthetic root wrapper
57
57
 
58
58
  if depth == 1
59
+ next if el.is_a?(Engines::Parser::Unknown)
59
60
  type_name = el.class::SIGNATURE_STAMP
60
61
  type_counters[type_name] += 1
61
62
  human = "#{type_name}-#{type_counters[type_name]}"
data/lib/mps/store.rb CHANGED
@@ -140,7 +140,7 @@ module MPS
140
140
  new_args = (new_attr_parts + existing_tags).join(", ")
141
141
 
142
142
  if raw.empty?
143
- old_pat = /@#{Regexp.escape(type)}\s*\{/
143
+ old_pat = /@#{Regexp.escape(type)}(?:\[\])?\s*\{/
144
144
  new_open = "@#{type}[#{new_args}]{"
145
145
  else
146
146
  old_pat = /@#{Regexp.escape(type)}\[#{Regexp.escape(raw)}\]\s*\{/
data/lib/mps/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MPS
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mps
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mash-97