pokerstats 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.5
1
+ 2.0.6
@@ -4,6 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + "/pokerstars_hand_history_pars
4
4
  module Pokerstats
5
5
  class HandHistory
6
6
  attr_accessor :lines, :source, :position, :stats
7
+
7
8
  def initialize lines, source, position, parser_class = PokerstarsHandHistoryParser
8
9
  @lines = lines
9
10
  @source = source
@@ -66,7 +66,7 @@ module Pokerstats
66
66
  when /PokerStars Game #([0-9]+): +([^(]*) \((#{CASH})\/(#{CASH})\) - (.*)$/
67
67
  @stats.update_hand :name => "PS#{$1}", :description=> "#{$2} (#{$3}/#{$4})", :tournament=> nil, :sb=> cash_to_d($3), :bb=> cash_to_d($4), :played_at=> Time.parse($5), :street => :prelude, :board => ""
68
68
  when /PokerStars Game #([0-9]+): +([^(]*) \((#{CASH})\/(#{CASH}) USD\) - (.*)$/
69
- @stats.update_hand :name => "PS#{$1}", :description=> "#{$2} (#{$3}/#{$4})", :tournament=> nil, :sb=> cash_to_d($3), :bb=> cash_to_d($4), :played_at=> Time.parse($5), :street => :prelude, :board => ""
69
+ ak @stats.update_hand :name => "PS#{$1}", :description=> "#{$2} (#{$3}/#{$4})", :tournament=> nil, :sb=> cash_to_d($3), :bb=> cash_to_d($4), :played_at=> Time.parse($5), :street => :prelude, :board => ""
70
70
  when /PokerStars Game #([0-9]+):/
71
71
  raise HandHistoryParseError, "invalid hand record: #{line}"
72
72
  when /\*\*\* HOLE CARDS \*\*\*/
@@ -0,0 +1,42 @@
1
+ module Pokerstats
2
+ StatAggregationCount = Struct.new(:items, :total)
3
+ class StatAggregator
4
+ def initialize(specification = {})
5
+ @specification = specification
6
+ @data = {}
7
+ @specification.keys.each do |key|
8
+ @data[key] = StatAggregationCount.new(0, 0)
9
+ end
10
+ end
11
+
12
+ def data
13
+ @data
14
+ end
15
+
16
+ def apply hash
17
+ @specification.each do |key, value|
18
+ puts "applying specification #{key.inspect} with value specification #{value.inspect}"
19
+ # determine datum value from specification
20
+ datum = case value
21
+ when Symbol
22
+ hash[value]
23
+ when Proc
24
+ value.call(hash)
25
+ else
26
+ raise RuntimeError, "there is no valid specification for datum #{key.inspect}"
27
+ end
28
+
29
+ puts "... resulting in datum #{datum.inspect}"
30
+ # apply datum value to aggregated data
31
+ unless datum.nil?
32
+ @data[key].items+=1
33
+ if datum.kind_of? Numeric
34
+ @data[key].total+=datum
35
+ else
36
+ @data[key].total+=1 if datum
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pokerstats}
8
- s.version = "2.0.5"
8
+ s.version = "2.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew C. Greenberg"]
12
- s.date = %q{2009-10-31}
12
+ s.date = %q{2009-11-03}
13
13
  s.default_executable = %q{checkps}
14
14
  s.description = %q{a library for extracting, computing and reporting statistics of poker hands parsed from hand history files}
15
15
  s.email = %q{wizardwerdna@gmail.com}
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
44
44
  "lib/pokerstats/poker-edge.rb",
45
45
  "lib/pokerstats/pokerstars_file.rb",
46
46
  "lib/pokerstats/pokerstars_hand_history_parser.rb",
47
+ "lib/pokerstats/stat_aggregator.rb",
47
48
  "pokerstats.gemspec",
48
49
  "spec/file_empty.txt",
49
50
  "spec/file_many_hands.txt",
@@ -54,6 +55,7 @@ Gem::Specification.new do |s|
54
55
  "spec/pokerstars_file_spec.rb",
55
56
  "spec/pokerstars_hand_history_parser_spec.rb",
56
57
  "spec/spec_helper.rb",
58
+ "spec/stat_aggregator_spec.rb",
57
59
  "spec/zpokerstars_hand_history_parser_integration.rb.txt"
58
60
  ]
59
61
  s.homepage = %q{http://github.com/wizardwerdna/pokerstats}
@@ -67,7 +69,8 @@ Gem::Specification.new do |s|
67
69
  "spec/player_statistics_spec.rb",
68
70
  "spec/pokerstars_file_spec.rb",
69
71
  "spec/pokerstars_hand_history_parser_spec.rb",
70
- "spec/spec_helper.rb"
72
+ "spec/spec_helper.rb",
73
+ "spec/stat_aggregator_spec.rb"
71
74
  ]
72
75
 
73
76
  if s.respond_to? :specification_version then
@@ -0,0 +1,119 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/pokerstats/stat_aggregator')
3
+
4
+ describe Pokerstats::StatAggregator do
5
+
6
+ STAT_SPECIFICATION_HASH = {
7
+ :t_data_items => lambda{|hash| 1},
8
+ :t_zero_numeric_items => lambda{|hash| hash[:numeric_item].nil? ? nil : hash[:numeric_item].zero?},
9
+ :t_numeric_item => :numeric_item,
10
+ :t_boolean_item => :is_boolean_item
11
+ }
12
+
13
+ DATA_ITEM_WITH_ZERO_NUMERIC_AND_TRUE_BOOLEAN = {:numeric_item => 0, :is_boolean_item => true}
14
+ DATA_ITEM_WITH_NON_ZERO_NUMERIC_AND_FALSE_BOOLEAN = {:numeric_item => 2, :is_boolean_item => false}
15
+ DATA_ITEM_WITH_NIL_NUMERIC_AND_TRUE_BOOLEAN = {:numeric_item => nil, :is_boolean_item => true}
16
+ ALL_DATA_ITEMS = [
17
+ DATA_ITEM_WITH_ZERO_NUMERIC_AND_TRUE_BOOLEAN,
18
+ DATA_ITEM_WITH_NON_ZERO_NUMERIC_AND_FALSE_BOOLEAN,
19
+ DATA_ITEM_WITH_NIL_NUMERIC_AND_TRUE_BOOLEAN
20
+ ]
21
+
22
+ before(:each) do
23
+ @stat_aggregator = Pokerstats::StatAggregator.new(STAT_SPECIFICATION_HASH)
24
+ end
25
+
26
+ context "when created" do
27
+ it "generates data with the correct initial values" do
28
+ data = @stat_aggregator.data
29
+ STAT_SPECIFICATION_HASH.each do |key, value|
30
+ data[key].items.should be_zero
31
+ data[key].total.should be_zero
32
+ end
33
+ end
34
+ end
35
+
36
+ context "after applying a non-null zero numeric and boolean true result" do
37
+ before(:each) do
38
+ EXPECTED_AGGREGATION_REPORT_FOR_ZERO_NUMERIC_AND_TRUE_BOOLEAN = {
39
+ :t_data_items => Pokerstats::StatAggregationCount.new(1, 1),
40
+ :t_zero_numeric_items => Pokerstats::StatAggregationCount.new(1, 1),
41
+ :t_numeric_item => Pokerstats::StatAggregationCount.new(1, 0),
42
+ :t_boolean_item => Pokerstats::StatAggregationCount.new(1, 1)
43
+ }
44
+ @applied = @stat_aggregator.apply DATA_ITEM_WITH_ZERO_NUMERIC_AND_TRUE_BOOLEAN
45
+ end
46
+ it "generates data with the correct applied values with a numeric and a boolean true result" do
47
+ @stat_aggregator.data.should == EXPECTED_AGGREGATION_REPORT_FOR_ZERO_NUMERIC_AND_TRUE_BOOLEAN
48
+ end
49
+ end
50
+
51
+ context "after applying a non-null non-zero numeric and boolean false result" do
52
+ before(:each) do
53
+ EXPECTED_AGGREGATION_REPORT_FOR_NON_ZERO_NUMERIC_AND_FALSE_BOOLEAN = {
54
+ :t_data_items => Pokerstats::StatAggregationCount.new(1, 1),
55
+ :t_zero_numeric_items => Pokerstats::StatAggregationCount.new(1, 0),
56
+ :t_numeric_item => Pokerstats::StatAggregationCount.new(1, 2),
57
+ :t_boolean_item => Pokerstats::StatAggregationCount.new(1, 0)
58
+ }
59
+ @applied = @stat_aggregator.apply DATA_ITEM_WITH_NON_ZERO_NUMERIC_AND_FALSE_BOOLEAN
60
+ end
61
+ it "generates data with the correct applied values with a numeric and a boolean true result" do
62
+ @stat_aggregator.data.should == EXPECTED_AGGREGATION_REPORT_FOR_NON_ZERO_NUMERIC_AND_FALSE_BOOLEAN
63
+ end
64
+ end
65
+
66
+ context "after applying a non-null non-zero numeric and boolean false result" do
67
+ before(:each) do
68
+ EXPECTED_AGGREGATION_REPORT_FOR_NIL_NUMERIC_AND_TRUE_BOOLEAN = {
69
+ :t_data_items => Pokerstats::StatAggregationCount.new(1, 1),
70
+ :t_zero_numeric_items => Pokerstats::StatAggregationCount.new(0, 0),
71
+ :t_numeric_item => Pokerstats::StatAggregationCount.new(0, 0),
72
+ :t_boolean_item => Pokerstats::StatAggregationCount.new(1, 1)
73
+ }
74
+ @applied = @stat_aggregator.apply DATA_ITEM_WITH_NIL_NUMERIC_AND_TRUE_BOOLEAN
75
+ end
76
+ it "generates data with the correct applied values with a numeric and a boolean true result" do
77
+ @stat_aggregator.data.should == EXPECTED_AGGREGATION_REPORT_FOR_NIL_NUMERIC_AND_TRUE_BOOLEAN
78
+ end
79
+ end
80
+
81
+ context "after applying the full set of data" do
82
+ before(:each) do
83
+ EXPECTED_AGGREGATION_REPORT = {
84
+ :t_data_items => Pokerstats::StatAggregationCount.new(3, 3),
85
+ :t_zero_numeric_items => Pokerstats::StatAggregationCount.new(2, 1),
86
+ :t_numeric_item => Pokerstats::StatAggregationCount.new(2, 2),
87
+ :t_boolean_item => Pokerstats::StatAggregationCount.new(3, 2)
88
+ }
89
+ ALL_DATA_ITEMS.each{|item| @stat_aggregator.apply item}
90
+ end
91
+ it "generates data with the correct applied values with a numeric and a boolean true result" do
92
+ puts ALL_DATA_ITEMS.to_yaml
93
+ puts EXPECTED_AGGREGATION_REPORT.to_yaml
94
+ puts @stat_aggregator.data.to_yaml
95
+ @stat_aggregator.data.should == EXPECTED_AGGREGATION_REPORT
96
+ end
97
+ end
98
+ end
99
+
100
+ # @aggreation_specification_hash = {
101
+ # :t_hands => {|hash| 1}
102
+ # :t_vpip => {|hash| hash[:paid].zero?}
103
+ # :t_posted => :posted
104
+ # :t_posted, :posted
105
+ # :t_paid, :paid
106
+ # :t_won, :won
107
+ # :t_preflop_passive, :preflop_passive
108
+ # :t_preflop_aggressive, :preflop_aggressive
109
+ # :t_postflop_passive, :postflop_passive
110
+ # :t_postflop_aggressive, :postflop_aggressive
111
+ # :t_blind_attack_opportunity, :is_blind_attack_opportunity
112
+ # :t_blind_attack_opportunity_taken, :is_blind_attack_opportunity_taken
113
+ # :t_blind_defense_opportunity, :is_blind_defense_opportunity
114
+ # :t_blind_defense_opportunity_taken, :is_blind_defense_opportunity_taken
115
+ # :t_pfr_opportunity, :is_pfr_opportunity
116
+ # :t_pfr_opportunity_taken, :is_pfr_opportunity_taken
117
+ # :t_cbet_opportunity, :is_cbet_opportunity
118
+ # :t_cbet_opportunity_taken, :is_cbet_opportunity_taken
119
+ # }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pokerstats
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew C. Greenberg
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-31 00:00:00 -07:00
12
+ date: 2009-11-03 00:00:00 -08:00
13
13
  default_executable: checkps
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -77,6 +77,7 @@ files:
77
77
  - lib/pokerstats/poker-edge.rb
78
78
  - lib/pokerstats/pokerstars_file.rb
79
79
  - lib/pokerstats/pokerstars_hand_history_parser.rb
80
+ - lib/pokerstats/stat_aggregator.rb
80
81
  - pokerstats.gemspec
81
82
  - spec/file_empty.txt
82
83
  - spec/file_many_hands.txt
@@ -87,6 +88,7 @@ files:
87
88
  - spec/pokerstars_file_spec.rb
88
89
  - spec/pokerstars_hand_history_parser_spec.rb
89
90
  - spec/spec_helper.rb
91
+ - spec/stat_aggregator_spec.rb
90
92
  - spec/zpokerstars_hand_history_parser_integration.rb.txt
91
93
  has_rdoc: true
92
94
  homepage: http://github.com/wizardwerdna/pokerstats
@@ -123,3 +125,4 @@ test_files:
123
125
  - spec/pokerstars_file_spec.rb
124
126
  - spec/pokerstars_hand_history_parser_spec.rb
125
127
  - spec/spec_helper.rb
128
+ - spec/stat_aggregator_spec.rb