account-owner-load-report 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 +38 -0
- data/bin/account-owner-load-report +29 -0
- data/lib/account_owner_load_report.rb +71 -0
- metadata +64 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d50b6e2e7565fcd5a15e8d888af27b41ecc3998010374e7b2bea88350ac26b9a
|
|
4
|
+
data.tar.gz: e16c22a3499fc1091e9805870e5372c851aff1d0fe2fc01bffc2b456e6610ba2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e7ee26bcc133fa5660db23538a3c4851a9a996935cbdcc57451107ff45a8b8362cc3b486d59f1d3c03de95a9a83916e9aa3a5b7b8049e125821d3f50535386eb
|
|
7
|
+
data.tar.gz: c6df51eb9bbcf6e315fa9fb0b7c1a0aaa7c25a6efc3a5c7fc5830032b2fab9bf6242424bea3dc739c3687bec86e68561bb8b105325dcfb899135dda1237f1cf9
|
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,38 @@
|
|
|
1
|
+
# account-owner-load-report
|
|
2
|
+
|
|
3
|
+
Ruby command line tool and library. Give it a CSV of accounts with their owner and tier (1, 2 or 3) and it shows, per owner, the number of accounts, the tier 1 accounts and the share of all accounts, with an OVER LIMIT flag when you set a per-owner cap. It then prints the average accounts per owner, the spread between the busiest and lightest owner, and who carries the most and fewest accounts.
|
|
4
|
+
|
|
5
|
+
Part of the [OneGTMLab](https://www.onegtmlab.dev) free GTM tools. Background on the idea: [account-based marketing](https://www.onegtmlab.dev/glossary/account-based-marketing).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
gem install account-owner-load-report
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
CSV columns: account, owner, tier. Pass --limit N to flag any owner with more than N accounts. A row repeated exactly is counted once. The same account listed with two different owners (or two different tiers) stops the run with an error and a non-zero exit code, as does a tier other than 1, 2 or 3. When owners tie for most or fewest, all are named.
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ ruby bin/account-owner-load-report sample.csv --limit 4
|
|
19
|
+
owner accounts tier 1 share flag
|
|
20
|
+
Priya 5 2 45.5% OVER LIMIT
|
|
21
|
+
Marcus 3 1 27.3%
|
|
22
|
+
Dana 2 1 18.2%
|
|
23
|
+
Lena 1 1 9.1%
|
|
24
|
+
|
|
25
|
+
11 accounts across 4 owners
|
|
26
|
+
average per owner: 2.75
|
|
27
|
+
spread (max minus min): 4
|
|
28
|
+
most accounts: Priya
|
|
29
|
+
fewest accounts: Lena
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Test
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
ruby test/run.rb
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/account_owner_load_report'
|
|
5
|
+
|
|
6
|
+
args = ARGV.dup
|
|
7
|
+
if args.empty? || args.include?('-h') || args.include?('--help')
|
|
8
|
+
warn "usage: account-owner-load-report accounts.csv [--limit 4]\n" \
|
|
9
|
+
"CSV columns: account, owner, tier (1, 2 or 3). More: https://www.onegtmlab.dev/glossary/account-based-marketing"
|
|
10
|
+
exit 2
|
|
11
|
+
end
|
|
12
|
+
file = args.shift
|
|
13
|
+
limit = nil
|
|
14
|
+
begin
|
|
15
|
+
until args.empty?
|
|
16
|
+
flag = args.shift
|
|
17
|
+
val = args.shift or abort "error: #{flag} needs a value"
|
|
18
|
+
case flag
|
|
19
|
+
when '--limit'
|
|
20
|
+
raise ArgumentError, "bad --limit #{val.inspect}, expected a whole number of 1 or more" unless val.match?(/\A[1-9]\d*\z/)
|
|
21
|
+
|
|
22
|
+
limit = Integer(val)
|
|
23
|
+
else abort "error: unknown option #{flag}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
print AccountOwnerLoadReport.render(AccountOwnerLoadReport.from_csv(File.read(file), limit: limit), limit: limit)
|
|
27
|
+
rescue ArgumentError, Errno::ENOENT, CSV::MalformedCSVError => e
|
|
28
|
+
abort "error: #{e.message}"
|
|
29
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'csv'
|
|
4
|
+
|
|
5
|
+
# Show how many accounts each owner carries, how many are tier 1, and who is over a limit.
|
|
6
|
+
module AccountOwnerLoadReport
|
|
7
|
+
Owner = Struct.new(:owner, :accounts, :tier1, :share, :over_limit, keyword_init: true)
|
|
8
|
+
Result = Struct.new(:owners, :total, :average, :spread, :most, :fewest, keyword_init: true)
|
|
9
|
+
|
|
10
|
+
# Returns [[account, owner, tier], ...] with exact repeats of a row collapsed to one.
|
|
11
|
+
def self.parse(text)
|
|
12
|
+
table = CSV.parse(text, headers: true)
|
|
13
|
+
missing = %w[account owner tier] - table.headers.compact.map(&:strip)
|
|
14
|
+
raise ArgumentError, "missing column(s): #{missing.join(', ')}" unless missing.empty?
|
|
15
|
+
raise ArgumentError, 'no rows in the CSV' if table.empty?
|
|
16
|
+
|
|
17
|
+
seen = {}
|
|
18
|
+
table.each_with_index do |r, i|
|
|
19
|
+
line = i + 2
|
|
20
|
+
account = r['account'].to_s.strip
|
|
21
|
+
owner = r['owner'].to_s.strip
|
|
22
|
+
tier = r['tier'].to_s.strip
|
|
23
|
+
raise ArgumentError, "line #{line}: empty account" if account.empty?
|
|
24
|
+
raise ArgumentError, "line #{line}: empty owner for #{account}" if owner.empty?
|
|
25
|
+
raise ArgumentError, "line #{line}: bad tier #{tier.inspect} for #{account}, expected 1, 2 or 3" unless %w[1 2 3].include?(tier)
|
|
26
|
+
|
|
27
|
+
if (prev = seen[account])
|
|
28
|
+
if prev[:owner] != owner
|
|
29
|
+
raise ArgumentError, "line #{line}: #{account} appears with two owners, #{prev[:owner]} and #{owner}"
|
|
30
|
+
elsif prev[:tier] != tier.to_i
|
|
31
|
+
raise ArgumentError, "line #{line}: #{account} appears with two tiers, #{prev[:tier]} and #{tier}"
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
seen[account] = { owner: owner, tier: tier.to_i }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
seen.map { |account, v| [account, v[:owner], v[:tier]] }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.analyze(rows, limit: nil)
|
|
41
|
+
raise ArgumentError, "limit must be a whole number of 1 or more, got #{limit.inspect}" if limit && (!limit.is_a?(Integer) || limit < 1)
|
|
42
|
+
|
|
43
|
+
total = rows.size
|
|
44
|
+
owners = rows.group_by { |_, o, _| o }.map do |name, list|
|
|
45
|
+
Owner.new(owner: name, accounts: list.size, tier1: list.count { |_, _, t| t == 1 },
|
|
46
|
+
share: list.size.to_f / total * 100, over_limit: !limit.nil? && list.size > limit)
|
|
47
|
+
end
|
|
48
|
+
owners.sort_by! { |o| [-o.accounts, o.owner] }
|
|
49
|
+
counts = owners.map(&:accounts)
|
|
50
|
+
Result.new(owners: owners, total: total, average: total.to_f / owners.size, spread: counts.max - counts.min,
|
|
51
|
+
most: owners.select { |o| o.accounts == counts.max }.map(&:owner),
|
|
52
|
+
fewest: owners.select { |o| o.accounts == counts.min }.map(&:owner))
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.from_csv(text, limit: nil)
|
|
56
|
+
analyze(parse(text), limit: limit)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.render(result, limit: nil)
|
|
60
|
+
out = +format("%-12s %8s %7s %7s %s", 'owner', 'accounts', 'tier 1', 'share', limit ? 'flag' : '').rstrip << "\n"
|
|
61
|
+
result.owners.each do |o|
|
|
62
|
+
out << format("%-12s %8d %7d %6.1f%% %s\n", o.owner, o.accounts, o.tier1, o.share, o.over_limit ? 'OVER LIMIT' : '').rstrip << "\n"
|
|
63
|
+
end
|
|
64
|
+
out << format("\n%d accounts across %d owners\n", result.total, result.owners.size)
|
|
65
|
+
out << format("average per owner: %.2f\n", result.average)
|
|
66
|
+
out << format("spread (max minus min): %d\n", result.spread)
|
|
67
|
+
out << "most accounts: #{result.most.join(', ')}\n"
|
|
68
|
+
out << "fewest accounts: #{result.fewest.join(', ')}\n"
|
|
69
|
+
out
|
|
70
|
+
end
|
|
71
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: account-owner-load-report
|
|
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 accounts with owner and tier (1, 2, 3), show accounts per owner, tier 1 accounts, share of all accounts and an OVER LIMIT flag, then the average, the spread and who carries the most and fewest accounts. Offline."
|
|
29
|
+
executables:
|
|
30
|
+
- account-owner-load-report
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- LICENSE
|
|
35
|
+
- README.md
|
|
36
|
+
- bin/account-owner-load-report
|
|
37
|
+
- lib/account_owner_load_report.rb
|
|
38
|
+
homepage: "https://www.onegtmlab.dev/glossary/account-based-marketing"
|
|
39
|
+
licenses:
|
|
40
|
+
- MIT
|
|
41
|
+
metadata:
|
|
42
|
+
homepage_uri: "https://www.onegtmlab.dev/glossary/account-based-marketing"
|
|
43
|
+
source_code_uri: "https://github.com/jaizendra-netizen/account-owner-load-report"
|
|
44
|
+
documentation_uri: "https://www.onegtmlab.dev/glossary/account-based-marketing"
|
|
45
|
+
rdoc_options: []
|
|
46
|
+
require_paths:
|
|
47
|
+
- lib
|
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
-
|
|
51
|
+
- ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: "2.7"
|
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
-
|
|
57
|
+
- ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: "0"
|
|
60
|
+
requirements: []
|
|
61
|
+
rubygems_version: 4.1.0
|
|
62
|
+
specification_version: 4
|
|
63
|
+
summary: "Show how many accounts each owner carries, tier 1 counts and who is over a limit"
|
|
64
|
+
test_files: []
|