product-whitespace-map 1.0.0
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 +7 -0
- data/LICENSE +22 -0
- data/README.md +63 -0
- data/bin/product-whitespace-map +18 -0
- data/lib/product_whitespace_map.rb +154 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 727bb39dd501ef3281e4b4a5ac5ab5cf71cd6a03de1af23adc7defb1972eea3e
|
|
4
|
+
data.tar.gz: 6ebe3134d261ac485df0a053c960ab69816d970ee547520e06c7308b46a4e3b4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 26ec82300767f6ab872ac9ffafe98ae947b1be22625420a930c0df1bef6f50c6a6cff200cb636e2e3d90e4461114557c638874a11ae9668c732125f1070a4f39
|
|
7
|
+
data.tar.gz: 050347c72173215e3fd3de92e1e1ec59a483d87de7a4960905c6f0ba1d8bdd1ea5e5aadaf91feda4039b1af40d50773274188e594a80c11ad75a8e6b1b79a288
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OneGTMLab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# product-whitespace-map
|
|
2
|
+
|
|
3
|
+
Ruby command line tool and library. Give it a CSV of the account and product pairs in your own list. It counts the owners of each product, shows the share of accounts that own it and how many do not, lists the "owns Q, not P" pairs, and ranks the accounts missing the most products. With --focus it lists the accounts that own something else but not one product you name.
|
|
4
|
+
|
|
5
|
+
Part of the [OneGTMLab](https://www.onegtmlab.dev) free GTM tools. Background on the idea: [Salesforce](https://www.onegtmlab.dev/tool-directory/crm/salesforce).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
gem install product-whitespace-map
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
CSV columns: account, product. Both are labels from your own list. They are trimmed and compared ignoring upper and lower case, and the first spelling seen is shown. The same account and product pair listed twice counts once, and the number of repeated pairs is printed. Products are sorted by owners, highest first, then by name. The "owns Q, not P" section takes every ordered pair of different products with at least one account owning Q but not P, and shows the top 10 by number of accounts, then by names (the total number of such pairs is printed). The accounts missing the most products are sorted by missing count, highest first, then by account name, and show how many products they own; the top 10 are shown. Option --focus PRODUCT (any case) lists up to 20 accounts, sorted by account name, that own at least one other product but not PRODUCT, with what they own; a product that is not in the file is an error that lists the products found. Percentages are rounded half up to 1 decimal. Whitespace here is only a gap in your own list: it says nothing about whether an account is a fit for a product, and the tool knows no product catalogue and reads no vendor data. A missing file, a missing column, an empty account or product (the row is named), an unknown option or a CSV with no rows stops the run with an error and a non-zero exit code.
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ ruby bin/product-whitespace-map sample.csv --focus Delta
|
|
19
|
+
accounts: 6
|
|
20
|
+
products: 4
|
|
21
|
+
distinct ownership pairs: 12 (repeated pairs counted once: 1)
|
|
22
|
+
accounts owning every product: 1
|
|
23
|
+
|
|
24
|
+
product owners share without it
|
|
25
|
+
Alpha 4 66.7% 2
|
|
26
|
+
Beta 3 50.0% 3
|
|
27
|
+
Gamma 3 50.0% 3
|
|
28
|
+
Delta 2 33.3% 4
|
|
29
|
+
|
|
30
|
+
owns Q but not P (top 10 of 11)
|
|
31
|
+
owns Alpha, not Delta: 3 accounts
|
|
32
|
+
owns Alpha, not Beta: 2 accounts
|
|
33
|
+
owns Alpha, not Gamma: 2 accounts
|
|
34
|
+
owns Beta, not Delta: 2 accounts
|
|
35
|
+
owns Beta, not Gamma: 2 accounts
|
|
36
|
+
owns Gamma, not Beta: 2 accounts
|
|
37
|
+
owns Beta, not Alpha: 1 account
|
|
38
|
+
owns Delta, not Alpha: 1 account
|
|
39
|
+
owns Delta, not Beta: 1 account
|
|
40
|
+
owns Gamma, not Alpha: 1 account
|
|
41
|
+
|
|
42
|
+
accounts missing the most products (top 10 of 6)
|
|
43
|
+
Account 4 missing 3, owns 1
|
|
44
|
+
Account 5 missing 3, owns 1
|
|
45
|
+
Account 2 missing 2, owns 2
|
|
46
|
+
Account 3 missing 2, owns 2
|
|
47
|
+
Account 6 missing 2, owns 2
|
|
48
|
+
Account 1 missing 0, owns 4
|
|
49
|
+
|
|
50
|
+
focus Delta: 4 accounts own another product but not Delta
|
|
51
|
+
Account 2: Alpha, Beta
|
|
52
|
+
Account 3: Alpha, Gamma
|
|
53
|
+
Account 4: Beta
|
|
54
|
+
Account 5: Alpha
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Test
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
ruby test/run.rb
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/product_whitespace_map'
|
|
5
|
+
|
|
6
|
+
if ARGV.empty? || ARGV.include?('-h') || ARGV.include?('--help')
|
|
7
|
+
warn "usage: product-whitespace-map owned.csv [--focus PRODUCT]\n" \
|
|
8
|
+
"CSV columns: account, product. More: https://www.onegtmlab.dev/tool-directory/crm/salesforce"
|
|
9
|
+
exit 2
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
begin
|
|
13
|
+
path, focus = ProductWhitespaceMap.parse_args(ARGV)
|
|
14
|
+
data = ProductWhitespaceMap.from_csv(File.read(path))
|
|
15
|
+
print ProductWhitespaceMap.render(ProductWhitespaceMap.analyze(data, focus: focus))
|
|
16
|
+
rescue ArgumentError, Errno::ENOENT, Errno::EISDIR, CSV::MalformedCSVError => e
|
|
17
|
+
abort "error: #{e.message}"
|
|
18
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'csv'
|
|
4
|
+
require 'set'
|
|
5
|
+
|
|
6
|
+
# Show which products each account in YOUR list owns and where the gaps are.
|
|
7
|
+
# A gap is only a hole in your own list: it says nothing about whether the account is a fit.
|
|
8
|
+
module ProductWhitespaceMap
|
|
9
|
+
# Percentage of n in d, rounded half up to 1 decimal. 0.0 when d is 0.
|
|
10
|
+
def self.pct(n, d)
|
|
11
|
+
return 0.0 if d.zero?
|
|
12
|
+
|
|
13
|
+
Rational(n * 100, d).round(1).to_f
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.sort_key(label)
|
|
17
|
+
[label.downcase, label]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Returns { accounts: {key => label}, products: {key => label}, owns: {account_key => Set[product_key]}, rows:, merged: }.
|
|
21
|
+
# Labels are trimmed and compared ignoring case; the first spelling seen is shown. The same pair twice counts once.
|
|
22
|
+
def self.from_csv(text)
|
|
23
|
+
table = CSV.parse(text.sub(/\A/, ''), headers: true, header_converters: ->(h) { h.to_s.strip.downcase })
|
|
24
|
+
missing = %w[account product] - table.headers.compact
|
|
25
|
+
raise ArgumentError, "missing column(s): #{missing.join(', ')}" unless missing.empty?
|
|
26
|
+
raise ArgumentError, 'no rows in the CSV' if table.empty?
|
|
27
|
+
|
|
28
|
+
accounts = {}
|
|
29
|
+
products = {}
|
|
30
|
+
owns = {}
|
|
31
|
+
merged = 0
|
|
32
|
+
table.each_with_index do |r, i|
|
|
33
|
+
line = i + 2
|
|
34
|
+
account = r['account'].to_s.strip
|
|
35
|
+
product = r['product'].to_s.strip
|
|
36
|
+
raise ArgumentError, "row #{line}: empty account" if account.empty?
|
|
37
|
+
raise ArgumentError, "row #{line}: empty product" if product.empty?
|
|
38
|
+
|
|
39
|
+
ak = account.downcase
|
|
40
|
+
pk = product.downcase
|
|
41
|
+
accounts[ak] ||= account
|
|
42
|
+
products[pk] ||= product
|
|
43
|
+
set = (owns[ak] ||= Set.new)
|
|
44
|
+
merged += 1 if set.include?(pk)
|
|
45
|
+
set << pk
|
|
46
|
+
end
|
|
47
|
+
{ accounts: accounts, products: products, owns: owns, rows: table.size, merged: merged }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# focus: product label (any case) or nil. Raises ArgumentError for an unknown product.
|
|
51
|
+
def self.analyze(data, focus: nil)
|
|
52
|
+
accounts = data[:accounts]
|
|
53
|
+
products = data[:products]
|
|
54
|
+
owns = data[:owns]
|
|
55
|
+
n_acc = accounts.size
|
|
56
|
+
n_prod = products.size
|
|
57
|
+
|
|
58
|
+
per_product = products.map do |pk, label|
|
|
59
|
+
owners = owns.count { |_a, set| set.include?(pk) }
|
|
60
|
+
{ label: label, owners: owners, share: pct(owners, n_acc), without: n_acc - owners }
|
|
61
|
+
end
|
|
62
|
+
per_product.sort_by! { |p| [-p[:owners], *sort_key(p[:label])] }
|
|
63
|
+
|
|
64
|
+
pairs = []
|
|
65
|
+
products.each do |qk, qlabel|
|
|
66
|
+
products.each do |pk, plabel|
|
|
67
|
+
next if qk == pk
|
|
68
|
+
|
|
69
|
+
n = owns.count { |_a, set| set.include?(qk) && !set.include?(pk) }
|
|
70
|
+
pairs << { owns: qlabel, not: plabel, accounts: n } if n.positive?
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
pairs.sort_by! { |x| [-x[:accounts], *sort_key(x[:owns]), *sort_key(x[:not])] }
|
|
74
|
+
|
|
75
|
+
missing = accounts.map do |ak, label|
|
|
76
|
+
{ account: label, owned: owns[ak].size, missing: n_prod - owns[ak].size }
|
|
77
|
+
end
|
|
78
|
+
missing.sort_by! { |m| [-m[:missing], *sort_key(m[:account])] }
|
|
79
|
+
|
|
80
|
+
result = {
|
|
81
|
+
accounts: n_acc, products: n_prod, rows: data[:rows], merged: data[:merged],
|
|
82
|
+
pairs_distinct: owns.values.sum(&:size),
|
|
83
|
+
own_every: owns.count { |_a, set| set.size == n_prod },
|
|
84
|
+
per_product: per_product, pairs_total: pairs.size, pairs: pairs.first(10),
|
|
85
|
+
missing_total: missing.size, missing: missing.first(10)
|
|
86
|
+
}
|
|
87
|
+
if focus
|
|
88
|
+
fk = focus.downcase
|
|
89
|
+
raise ArgumentError, "unknown product #{focus.inspect}, products in the file: #{products.values.sort_by { |l| sort_key(l) }.join(', ')}" unless products.key?(fk)
|
|
90
|
+
|
|
91
|
+
list = accounts.filter_map do |ak, label|
|
|
92
|
+
set = owns[ak]
|
|
93
|
+
next if set.include?(fk) || set.empty?
|
|
94
|
+
|
|
95
|
+
{ account: label, owns: set.map { |k| products[k] }.sort_by { |l| sort_key(l) } }
|
|
96
|
+
end
|
|
97
|
+
list.sort_by! { |x| sort_key(x[:account]) }
|
|
98
|
+
result[:focus] = { product: products[fk], total: list.size, list: list.first(20) }
|
|
99
|
+
end
|
|
100
|
+
result
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def self.render(r)
|
|
104
|
+
out = +"accounts: #{r[:accounts]}\nproducts: #{r[:products]}\n"
|
|
105
|
+
out << "distinct ownership pairs: #{r[:pairs_distinct]} (repeated pairs counted once: #{r[:merged]})\n"
|
|
106
|
+
out << "accounts owning every product: #{r[:own_every]}\n\n"
|
|
107
|
+
w = [r[:per_product].map { |p| p[:label].length }.max, 7].max
|
|
108
|
+
out << format("%-#{w}s %6s %8s %10s\n", 'product', 'owners', 'share', 'without it')
|
|
109
|
+
r[:per_product].each do |p|
|
|
110
|
+
out << format("%-#{w}s %6d %7.1f%% %10d\n", p[:label], p[:owners], p[:share], p[:without])
|
|
111
|
+
end
|
|
112
|
+
out << "\nowns Q but not P (top 10 of #{r[:pairs_total]})\n"
|
|
113
|
+
r[:pairs].each do |x|
|
|
114
|
+
out << " owns #{x[:owns]}, not #{x[:not]}: #{x[:accounts]} #{x[:accounts] == 1 ? 'account' : 'accounts'}\n"
|
|
115
|
+
end
|
|
116
|
+
out << "\naccounts missing the most products (top 10 of #{r[:missing_total]})\n"
|
|
117
|
+
aw = r[:missing].map { |m| m[:account].length }.max
|
|
118
|
+
r[:missing].each do |m|
|
|
119
|
+
out << format(" %-#{aw}s missing %d, owns %d\n", m[:account], m[:missing], m[:owned])
|
|
120
|
+
end
|
|
121
|
+
if (f = r[:focus])
|
|
122
|
+
out << "\nfocus #{f[:product]}: #{f[:total]} #{f[:total] == 1 ? 'account owns' : 'accounts own'} another product but not #{f[:product]}"
|
|
123
|
+
out << " (showing #{f[:list].size})" if f[:total] > f[:list].size
|
|
124
|
+
out << "\n"
|
|
125
|
+
f[:list].each { |x| out << " #{x[:account]}: #{x[:owns].join(', ')}\n" }
|
|
126
|
+
end
|
|
127
|
+
out
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Returns [path, focus]; raises ArgumentError on bad input.
|
|
131
|
+
def self.parse_args(argv)
|
|
132
|
+
args = argv.dup
|
|
133
|
+
path = nil
|
|
134
|
+
focus = nil
|
|
135
|
+
until args.empty?
|
|
136
|
+
arg = args.shift
|
|
137
|
+
case arg
|
|
138
|
+
when '--focus'
|
|
139
|
+
raise ArgumentError, '--focus needs a product' if args.empty?
|
|
140
|
+
|
|
141
|
+
focus = args.shift.to_s.strip
|
|
142
|
+
raise ArgumentError, '--focus needs a non-empty product' if focus.empty?
|
|
143
|
+
when /\A-/ then raise ArgumentError, "unknown option #{arg}"
|
|
144
|
+
else
|
|
145
|
+
raise ArgumentError, "unexpected extra argument #{arg.inspect}" if path
|
|
146
|
+
|
|
147
|
+
path = arg
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
raise ArgumentError, 'no CSV file given' unless path
|
|
151
|
+
|
|
152
|
+
[path, focus]
|
|
153
|
+
end
|
|
154
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: product-whitespace-map
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- OneGTMLab
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: csv
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
-
|
|
17
|
+
- ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: "0"
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
-
|
|
25
|
+
- ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: "0"
|
|
28
|
+
description: "Ruby CLI and library: from a CSV of account and product pairs, count owners per product, list the owns-Q-but-not-P pairs, rank the accounts missing the most products and list the accounts that lack one chosen product. A gap is only a hole in your own list. Offline."
|
|
29
|
+
executables:
|
|
30
|
+
- product-whitespace-map
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- LICENSE
|
|
35
|
+
- README.md
|
|
36
|
+
- bin/product-whitespace-map
|
|
37
|
+
- lib/product_whitespace_map.rb
|
|
38
|
+
homepage: "https://www.onegtmlab.dev/tool-directory/crm/salesforce"
|
|
39
|
+
licenses:
|
|
40
|
+
- MIT
|
|
41
|
+
metadata:
|
|
42
|
+
source_code_uri: "https://github.com/jaizendra-netizen/product-whitespace-map"
|
|
43
|
+
rdoc_options: []
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
-
|
|
49
|
+
- ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: "2.7"
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
-
|
|
55
|
+
- ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: "0"
|
|
58
|
+
requirements: []
|
|
59
|
+
rubygems_version: 4.1.0
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: "Show which products each account in your own list owns, the gaps between them and the accounts missing the most"
|
|
62
|
+
test_files: []
|