win-loss-reason-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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3bd6894da5db2d367289b8e9fc0142edf6b7b3b7d3f82e0d8f1b07cd25d37dec
4
+ data.tar.gz: 705f6425bf707bd3b1908209f915f40eeccd386d9a01979b2987e5a93efc2ad9
5
+ SHA512:
6
+ metadata.gz: 667ea0a7fdc828ceeaed924f8bff5005c65a291b7181b002b04f4597eaf0f735467c209964538eb5d945d681cceb44cc176e9a065bd5dd6929f31cd1c2ca7da7
7
+ data.tar.gz: 46277d91bb23ca32f0b185c2889d3cff8bd689d56832dba14aeb4c266f4229d1d8a02ea92cf974ac8185f8a6b15c9763506c434cbf06de56dd6e8d39096f8eee
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
+ # win-loss-reason-report
2
+
3
+ Ruby command line tool and library. Give it a CSV of closed deals with an outcome, a reason and an amount and it prints the win rate, then the lost reasons and won reasons ranked by count, share and money.
4
+
5
+ Part of the [OneGTMLab](https://www.onegtmlab.dev) free GTM tools. Background on the idea: [sales playbook](https://www.onegtmlab.dev/glossary/sales-playbook).
6
+
7
+ ## Install
8
+
9
+ ```
10
+ gem install win-loss-reason-report
11
+ ```
12
+
13
+ ## Use
14
+
15
+ CSV columns: outcome (won or lost), reason, amount. A blank reason is counted as (no reason logged).
16
+
17
+ ```
18
+ $ ruby bin/win-loss-reason-report sample.csv
19
+ closed deals: 3 won, 5 lost, win rate 37.5%
20
+
21
+ why we lost
22
+ price 2 40.0% 27000
23
+ (no reason logged) 1 20.0% 5000
24
+ no decision 1 20.0% 8000
25
+ went with competitor 1 20.0% 22000
26
+
27
+ why we won
28
+ integration fit 2 66.7% 48000
29
+ speed to value 1 33.3% 9000
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,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/win_loss_reason_report'
5
+
6
+ if ARGV.empty? || ARGV.include?('-h') || ARGV.include?('--help')
7
+ warn "usage: win-loss-reason-report deals.csv\nCSV columns: outcome (won or lost), reason, amount. More: https://www.onegtmlab.dev/glossary/sales-playbook"
8
+ exit 2
9
+ end
10
+ begin
11
+ print WinLossReasonReport.render(WinLossReasonReport.from_csv(File.read(ARGV[0])))
12
+ rescue ArgumentError, Errno::ENOENT => e
13
+ abort "error: #{e.message}"
14
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+
5
+ # Count why deals were won or lost and show the share of each reason.
6
+ module WinLossReasonReport
7
+ Line = Struct.new(:reason, :count, :share, :amount, keyword_init: true)
8
+ Result = Struct.new(:won, :lost, :win_rate, :lost_reasons, :won_reasons, keyword_init: true)
9
+
10
+ def self.tally(rows)
11
+ total = rows.size
12
+ rows.group_by { |r| r[:reason] }.map do |reason, rs|
13
+ Line.new(reason: reason, count: rs.size, share: total.zero? ? 0.0 : rs.size.fdiv(total), amount: rs.sum { |r| r[:amount] })
14
+ end.sort_by { |l| [-l.count, l.reason] }
15
+ end
16
+
17
+ def self.from_csv(text)
18
+ rows = CSV.parse(text, headers: true).map do |r|
19
+ outcome = r['outcome'].to_s.strip.downcase
20
+ raise ArgumentError, "outcome must be won or lost, got #{outcome.inspect}" unless %w[won lost].include?(outcome)
21
+
22
+ amt = Float(r['amount'].to_s.strip.empty? ? '0' : r['amount'].to_s.strip)
23
+ { outcome: outcome, reason: r['reason'].to_s.strip.then { |x| x.empty? ? '(no reason logged)' : x }, amount: amt }
24
+ end
25
+ won = rows.select { |r| r[:outcome] == 'won' }
26
+ lost = rows.select { |r| r[:outcome] == 'lost' }
27
+ closed = rows.size
28
+ Result.new(won: won.size, lost: lost.size, win_rate: closed.zero? ? 0.0 : won.size.fdiv(closed),
29
+ lost_reasons: tally(lost), won_reasons: tally(won))
30
+ end
31
+
32
+ def self.render(res)
33
+ out = +format("closed deals: %d won, %d lost, win rate %.1f%%\n", res.won, res.lost, res.win_rate * 100)
34
+ { 'why we lost' => res.lost_reasons, 'why we won' => res.won_reasons }.each do |title, lines|
35
+ out << "\n#{title}\n"
36
+ out << " (none)\n" if lines.empty?
37
+ lines.each { |l| out << format(" %-26s %3d %5.1f%% %10.0f\n", l.reason, l.count, l.share * 100, l.amount) }
38
+ end
39
+ out
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: win-loss-reason-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 closed deals with an outcome, a reason and an amount, print the win rate and the lost and won reasons ranked by count, share and money. Offline."
29
+ email:
30
+ - account@onegtmlab.dev
31
+ executables:
32
+ - win-loss-reason-report
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - LICENSE
37
+ - README.md
38
+ - bin/win-loss-reason-report
39
+ - lib/win_loss_reason_report.rb
40
+ homepage: "https://www.onegtmlab.dev/glossary/sales-playbook"
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ homepage_uri: "https://www.onegtmlab.dev/glossary/sales-playbook"
45
+ source_code_uri: "https://github.com/jaizendra-netizen/win-loss-reason-report"
46
+ documentation_uri: "https://www.onegtmlab.dev/glossary/sales-playbook"
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ -
53
+ - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "2.7"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ -
59
+ - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ requirements: []
63
+ rubygems_version: 4.1.0
64
+ specification_version: 4
65
+ summary: "Count why deals were won or lost, with the share and amount per reason"
66
+ test_files: []