wizardwerdna-pokerstats 1.0.14 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.14
1
+ 1.0.15
data/bin/checkps CHANGED
@@ -5,10 +5,10 @@ require "activesupport"
5
5
  require "open-uri"
6
6
  # ENV['RAILS_ENV'] = ENV['RAILS_ENV'] || 'development'
7
7
  # require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
8
- # require File.expand_path(File.dirname(__FILE__) + "/pokerstats/pokerstars_file")
9
- # require File.expand_path(File.dirname(__FILE__) + '/pokerstats/player_statistics')
10
- require 'pokerstats/pokerstars_file'
11
- require 'pokerstats/player_statistics'
8
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/pokerstats/pokerstars_file")
9
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/pokerstats/player_statistics')
10
+ # require 'pokerstats/pokerstars_file'
11
+ # require 'pokerstats/player_statistics'
12
12
 
13
13
  def search_poker_edge(playername, players_shown = {})
14
14
  return if players_shown[playername]
@@ -52,8 +52,8 @@ def dopsfile(file, players_shown)
52
52
  return if File.directory?(file)
53
53
  players = {}
54
54
  last = nil
55
- statistics = PlayerStatistics.new
56
- PokerstarsFile.open(file).each do |handrecord|
55
+ statistics = Pokerstats::PlayerStatistics.new
56
+ Pokerstats::PokerstarsFile.open(file).each do |handrecord|
57
57
  begin
58
58
  handrecord.parse
59
59
  statistics.record(handrecord)
@@ -162,7 +162,6 @@ def display_poker_edge_results
162
162
  end
163
163
  end
164
164
 
165
-
166
165
  opts = GetoptLong.new(
167
166
  [ "--help", "-h", GetoptLong::NO_ARGUMENT],
168
167
  [ "--version", "-v", GetoptLong::NO_ARGUMENT],
@@ -188,4 +187,4 @@ if $*.empty?
188
187
  display_recent_pokerstars_results user
189
188
  else
190
189
  display_poker_edge_results
191
- end
190
+ end
data/lib/pokerstats.rb CHANGED
@@ -0,0 +1,2 @@
1
+ module Pokerstats
2
+ end
@@ -1,25 +1,27 @@
1
- module HandConstants
2
- HAND_REPORT_SPECIFICATION = [
3
- # [key, sql_type, function]
4
- [:session_filename, 'string'],
5
- [:starting_at, 'datetime'],
6
- [:name, 'string'],
7
- [:description, 'string'],
8
- [:sb, 'decimal'],
9
- [:bb, 'decimal'],
10
- [:board, 'string'],
11
- [:total_pot, 'decimal'],
12
- [:rake, 'decimal'],
13
- [:played_at, 'datetime'],
14
- [:tournament, 'string']
15
- ]
16
- HAND_INFORMATION_KEYS = HAND_REPORT_SPECIFICATION.map{|each| each.first}
17
- HAND_RECORD_INCOMPLETE_MESSAGE = "hand record is incomplete"
18
- PLAYER_RECORDS_NO_PLAYER_REGISTERED = "no players have been registered"
19
- PLAYER_RECORDS_DUPLICATE_PLAYER_NAME = "player screen_name has been registered twice"
20
- PLAYER_RECORDS_NO_BUTTON_REGISTERED = "no button has been registered"
21
- PLAYER_RECORDS_UNREGISTERED_PLAYER = "player has not been registered"
22
- PLAYER_RECORDS_OUT_OF_BALANCE = "hand record is out of balance"
1
+ module Pokerstats
2
+ module HandConstants
3
+ HAND_REPORT_SPECIFICATION = [
4
+ # [key, sql_type, function]
5
+ [:session_filename, 'string'],
6
+ [:starting_at, 'datetime'],
7
+ [:name, 'string'],
8
+ [:description, 'string'],
9
+ [:sb, 'decimal'],
10
+ [:bb, 'decimal'],
11
+ [:board, 'string'],
12
+ [:total_pot, 'decimal'],
13
+ [:rake, 'decimal'],
14
+ [:played_at, 'datetime'],
15
+ [:tournament, 'string']
16
+ ]
17
+ HAND_INFORMATION_KEYS = HAND_REPORT_SPECIFICATION.map{|each| each.first}
18
+ HAND_RECORD_INCOMPLETE_MESSAGE = "hand record is incomplete"
19
+ PLAYER_RECORDS_NO_PLAYER_REGISTERED = "no players have been registered"
20
+ PLAYER_RECORDS_DUPLICATE_PLAYER_NAME = "player screen_name has been registered twice"
21
+ PLAYER_RECORDS_NO_BUTTON_REGISTERED = "no button has been registered"
22
+ PLAYER_RECORDS_UNREGISTERED_PLAYER = "player has not been registered"
23
+ PLAYER_RECORDS_OUT_OF_BALANCE = "hand record is out of balance"
23
24
 
24
- MAX_SEATS = 12
25
+ MAX_SEATS = 12
26
+ end
25
27
  end
@@ -1,35 +1,38 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/hand_constants")
2
2
  require File.expand_path(File.dirname(__FILE__) + "/pokerstars_hand_history_parser")
3
- class HandHistory
4
- attr_accessor :lines, :source, :position, :stats
5
- def initialize lines, source, position, parser_class = PokerstarsHandHistoryParser
6
- @lines = lines
7
- @source = source
8
- @position = position
9
- @parsed = false
10
- @parser_class = parser_class
11
- @stats = HandStatistics.new
12
- end
3
+
4
+ module Pokerstats
5
+ class HandHistory
6
+ attr_accessor :lines, :source, :position, :stats
7
+ def initialize lines, source, position, parser_class = PokerstarsHandHistoryParser
8
+ @lines = lines
9
+ @source = source
10
+ @position = position
11
+ @parsed = false
12
+ @parser_class = parser_class
13
+ @stats = HandStatistics.new
14
+ end
13
15
 
14
- def parsed?
15
- @parsed
16
- end
16
+ def parsed?
17
+ @parsed
18
+ end
17
19
 
18
- def parse
19
- @parser = @parser_class.new(@stats)
20
- @lines.each do |each_line|
21
- begin
22
- @parser.parse(each_line)
23
- rescue => e
24
- raise "#{@source}:#{position}: #{e.message}"
20
+ def parse
21
+ @parser = @parser_class.new(@stats)
22
+ @lines.each do |each_line|
23
+ begin
24
+ @parser.parse(each_line)
25
+ rescue => e
26
+ raise "#{@source}:#{position}: #{e.message}"
27
+ end
25
28
  end
29
+ @stats.update_hand :session_filename => source, :starting_at => position
30
+ @parsed = true
26
31
  end
27
- @stats.update_hand :session_filename => source, :starting_at => position
28
- @parsed = true
29
- end
30
32
 
31
- def reports
32
- parse unless parsed?
33
- @stats.reports
33
+ def reports
34
+ parse unless parsed?
35
+ @stats.reports
36
+ end
34
37
  end
35
38
  end
@@ -5,219 +5,219 @@ require 'bigdecimal/util'
5
5
  require 'activesupport'
6
6
  require File.expand_path(File.dirname(__FILE__) + '/hand_constants')
7
7
  require File.expand_path(File.dirname(__FILE__) + '/hand_statistics_api')
8
+ module Pokerstats
9
+ class HandStatistics
10
+ include Pluggable
11
+ include HandConstants
12
+ plugin_include_module HandStatisticsAPI
13
+ def initialize
14
+ install_plugins self
15
+ @hand_information = {}
16
+ @player_hashes = []
17
+ @button_player_index = nil
18
+ @cached_player_position = nil
19
+ @street_state = nil
20
+ street_transition(:prelude)
21
+ end
8
22
 
9
- class HandStatistics
10
- include Pluggable
11
- include HandConstants
12
- plugin_include_module HandStatisticsAPI
13
- def initialize
14
- install_plugins self
15
- @hand_information = {}
16
- @player_hashes = []
17
- @button_player_index = nil
18
- @cached_player_position = nil
19
- @street_state = nil
20
- street_transition(:prelude)
21
- end
22
-
23
- ##
24
- # Hand Information
25
- ##
23
+ ##
24
+ # Hand Information
25
+ ##
26
26
 
27
- def hand_record
28
- raise "#{HAND_RECORD_INCOMPLETE_MESSAGE}: #{(HAND_INFORMATION_KEYS - @hand_information.keys).inspect}" unless (HAND_INFORMATION_KEYS - @hand_information.keys).empty?
29
- @hand_information
30
- end
27
+ def hand_record
28
+ raise "#{HAND_RECORD_INCOMPLETE_MESSAGE}: #{(HAND_INFORMATION_KEYS - @hand_information.keys).inspect}" unless (HAND_INFORMATION_KEYS - @hand_information.keys).empty?
29
+ @hand_information
30
+ end
31
31
 
32
- def update_hand update
33
- street_transition(update[:street]) unless update[:street] == @street_state
34
- @hand_information.update(update)
35
- self
36
- end
32
+ def update_hand update
33
+ street_transition(update[:street]) unless update[:street] == @street_state
34
+ @hand_information.update(update)
35
+ self
36
+ end
37
37
 
38
- ##
39
- # Player Information
40
- ##
38
+ ##
39
+ # Player Information
40
+ ##
41
41
 
42
- def player_records_without_validation
43
- @player_hashes
44
- end
42
+ def player_records_without_validation
43
+ @player_hashes
44
+ end
45
45
 
46
- def player_records
47
- raise PLAYER_RECORDS_NO_PLAYER_REGISTERED if players.empty?
48
- raise PLAYER_RECORDS_NO_BUTTON_REGISTERED if button.nil?
49
- raise PLAYER_RECORDS_OUT_OF_BALANCE if out_of_balance
50
- self.player_records_without_validation
51
- end
46
+ def player_records
47
+ raise PLAYER_RECORDS_NO_PLAYER_REGISTERED if players.empty?
48
+ raise PLAYER_RECORDS_NO_BUTTON_REGISTERED if button.nil?
49
+ raise PLAYER_RECORDS_OUT_OF_BALANCE if out_of_balance
50
+ self.player_records_without_validation
51
+ end
52
52
 
53
- def players
54
- @player_hashes.sort{|a, b| a[:seat] <=> b[:seat]}.collect{|each| each[:screen_name]}
55
- end
53
+ def players
54
+ @player_hashes.sort{|a, b| a[:seat] <=> b[:seat]}.collect{|each| each[:screen_name]}
55
+ end
56
56
 
57
- def number_players
58
- @player_hashes.size
59
- end
57
+ def number_players
58
+ @player_hashes.size
59
+ end
60
60
 
61
- def register_player player
62
- screen_name = player[:screen_name]
63
- raise "#{PLAYER_RECORDS_DUPLICATE_PLAYER_NAME}: #{screen_name.inspect}" if players.member?(screen_name)
64
- @cached_player_position = nil
65
- @player_hashes << player
66
- plugins.each{|each| each.register_player(screen_name, @street_state)} #why the second parameter?
67
- street_transition_for_player(@street_state, screen_name)
68
- end
61
+ def register_player player
62
+ screen_name = player[:screen_name]
63
+ raise "#{PLAYER_RECORDS_DUPLICATE_PLAYER_NAME}: #{screen_name.inspect}" if players.member?(screen_name)
64
+ @cached_player_position = nil
65
+ @player_hashes << player
66
+ plugins.each{|each| each.register_player(screen_name, @street_state)} #why the second parameter?
67
+ street_transition_for_player(@street_state, screen_name)
68
+ end
69
69
 
70
- ###
71
- # Street state information
72
- ##
70
+ ###
71
+ # Street state information
72
+ ##
73
73
 
74
- def street
75
- @street_state
76
- end
74
+ def street
75
+ @street_state
76
+ end
77
77
 
78
- def street_transition street
79
- @street_state = street
80
- plugins.each{|each| each.street_transition(street)}
81
- players.each {|player| street_transition_for_player(street, player)}
82
- end
78
+ def street_transition street
79
+ @street_state = street
80
+ plugins.each{|each| each.street_transition(street)}
81
+ players.each {|player| street_transition_for_player(street, player)}
82
+ end
83
83
 
84
- def street_transition_for_player street, screen_name
85
- plugins.each{|each| each.street_transition_for_player(street, screen_name)}
86
- end
84
+ def street_transition_for_player street, screen_name
85
+ plugins.each{|each| each.street_transition_for_player(street, screen_name)}
86
+ end
87
87
 
88
- ##
89
- # Button and Position Information
90
- ##
88
+ ##
89
+ # Button and Position Information
90
+ ##
91
91
 
92
- def register_button button_index
93
- @cached_player_position = nil
94
- @button_player_index = button_index
95
- end
92
+ def register_button button_index
93
+ @cached_player_position = nil
94
+ @button_player_index = button_index
95
+ end
96
96
 
97
- def button
98
- @button_player_index
99
- end
97
+ def button
98
+ @button_player_index
99
+ end
100
100
 
101
- def button_relative_seat(player_hash)
102
- (player_hash[:seat] + MAX_SEATS - @button_player_index) % MAX_SEATS
103
- end
101
+ def button_relative_seat(player_hash)
102
+ (player_hash[:seat] + MAX_SEATS - @button_player_index) % MAX_SEATS
103
+ end
104
104
 
105
- # long computation is cached, which cache is cleared every time a new player is registered
106
- def calculate_player_position screen_name
107
- @cached_player_position = {}
108
- @player_hashes.sort!{|a,b| button_relative_seat(a) <=> button_relative_seat(b)}
109
- @player_hashes = [@player_hashes.pop] + @player_hashes unless @player_hashes.first[:seat] == @button_player_index
110
- @player_hashes.each_with_index{|player, index| player[:position] = index, @cached_player_position[player[:screen_name]] = index}
111
- @cached_player_position[screen_name]
112
- end
105
+ # long computation is cached, which cache is cleared every time a new player is registered
106
+ def calculate_player_position screen_name
107
+ @cached_player_position = {}
108
+ @player_hashes.sort!{|a,b| button_relative_seat(a) <=> button_relative_seat(b)}
109
+ @player_hashes = [@player_hashes.pop] + @player_hashes unless @player_hashes.first[:seat] == @button_player_index
110
+ @player_hashes.each_with_index{|player, index| player[:position] = index, @cached_player_position[player[:screen_name]] = index}
111
+ @cached_player_position[screen_name]
112
+ end
113
113
 
114
- def position screen_name
115
- (@cached_player_position && @cached_player_position[screen_name]) || calculate_player_position(screen_name)
116
- end
114
+ def position screen_name
115
+ (@cached_player_position && @cached_player_position[screen_name]) || calculate_player_position(screen_name)
116
+ end
117
117
 
118
- def button?(screen_name)
119
- position(screen_name) && position(screen_name).zero?
120
- end
118
+ def button?(screen_name)
119
+ position(screen_name) && position(screen_name).zero?
120
+ end
121
121
 
122
- # The cutoff position is defined as the player to the left of the button if there are three players, otherwise nil
123
- def cutoff_position
124
- # formerly: (number_players > 3) && (-1 % number_players)
125
- -1 % number_players if number_players > 3
126
- end
122
+ # The cutoff position is defined as the player to the left of the button if there are three players, otherwise nil
123
+ def cutoff_position
124
+ # formerly: (number_players > 3) && (-1 % number_players)
125
+ -1 % number_players if number_players > 3
126
+ end
127
127
 
128
- def cutoff?(screen_name)
129
- position(screen_name) == cutoff_position
130
- end
128
+ def cutoff?(screen_name)
129
+ position(screen_name) == cutoff_position
130
+ end
131
131
 
132
- def blind?(screen_name)
133
- (sbpos?(screen_name) || bbpos?(screen_name)) and !posted(screen_name).zero?
134
- end
132
+ def blind?(screen_name)
133
+ (sbpos?(screen_name) || bbpos?(screen_name)) and !posted(screen_name).zero?
134
+ end
135
135
 
136
- def sbpos?(screen_name)
137
- (number_players > 2) && position(screen_name) == 1
138
- end
136
+ def sbpos?(screen_name)
137
+ (number_players > 2) && position(screen_name) == 1
138
+ end
139
139
 
140
- def bbpos?(screen_name)
141
- (number_players > 2) && position(screen_name) == 2
142
- end
140
+ def bbpos?(screen_name)
141
+ (number_players > 2) && position(screen_name) == 2
142
+ end
143
143
 
144
- def attacker?(screen_name)
145
- (number_players > 2) && (button?(screen_name) || cutoff?(screen_name))
146
- end
144
+ def attacker?(screen_name)
145
+ (number_players > 2) && (button?(screen_name) || cutoff?(screen_name))
146
+ end
147
147
 
148
148
 
149
- ##
150
- # Action Information
151
- ##
152
- def aggression(description)
153
- case description
154
- when /call/
155
- :passive
156
- when /raise/
157
- :aggressive
158
- when /bet/
159
- :aggressive
160
- when /fold/
161
- :fold
162
- when /check/
163
- :check
164
- else
165
- :neutral
149
+ ##
150
+ # Action Information
151
+ ##
152
+ def aggression(description)
153
+ case description
154
+ when /call/
155
+ :passive
156
+ when /raise/
157
+ :aggressive
158
+ when /bet/
159
+ :aggressive
160
+ when /fold/
161
+ :fold
162
+ when /check/
163
+ :check
164
+ else
165
+ :neutral
166
+ end
166
167
  end
167
- end
168
168
 
169
- def register_action(screen_name, description, options={})
170
- raise "#{PLAYER_RECORDS_UNREGISTERED_PLAYER}: #{screen_name.inspect}" unless players.member?(screen_name)
171
- plugins.each do |each|
172
- each.apply_action(
173
- {:screen_name => screen_name, :description => description, :aggression => aggression(description)}.update(options),
174
- @street_state)
169
+ def register_action(screen_name, description, options={})
170
+ raise "#{PLAYER_RECORDS_UNREGISTERED_PLAYER}: #{screen_name.inspect}" unless players.member?(screen_name)
171
+ plugins.each do |each|
172
+ each.apply_action(
173
+ {:screen_name => screen_name, :description => description, :aggression => aggression(description)}.update(options),
174
+ @street_state)
175
+ end
175
176
  end
176
- end
177
177
 
178
- ##
179
- # Reporting Information
180
- ##
178
+ ##
179
+ # Reporting Information
180
+ ##
181
181
 
182
- def report_player(player)
183
- result = {}
184
- plugins.each {|each| result.merge!(each.report(player))}
185
- result
186
- end
182
+ def report_player(player)
183
+ result = {}
184
+ plugins.each {|each| result.merge!(each.report(player))}
185
+ result
186
+ end
187
187
 
188
- def reports
189
- result = {}
190
- players.each{|each| result[each] = report_player(each)}
191
- result
192
- end
188
+ def reports
189
+ result = {}
190
+ players.each{|each| result[each] = report_player(each)}
191
+ result
192
+ end
193
193
 
194
- def report_hand_information
195
- @hand_information
196
- end
194
+ def report_hand_information
195
+ @hand_information
196
+ end
197
197
 
198
- def self.hand_statistics_migration_data
199
- HAND_REPORT_SPECIFICATION.inject("") do |string, each|
200
- string + "t.#{each[1]}\t#{each[0].inspect}\n"
198
+ def self.hand_statistics_migration_data
199
+ HAND_REPORT_SPECIFICATION.inject("") do |string, each|
200
+ string + "t.#{each[1]}\t#{each[0].inspect}\n"
201
+ end
201
202
  end
202
- end
203
203
 
204
- def self.player_statistics_migration_data
205
- plugin_factory.inject("") do |str, each_plugin|
206
- tstr = "# from #{each_plugin.inspect}\n"
207
- each_plugin.report_specification.each do |each_datum|
208
- tstr += "t.#{each_datum[1]}\t#{each_datum[0].inspect}\n"
204
+ def self.player_statistics_migration_data
205
+ plugin_factory.inject("") do |str, each_plugin|
206
+ tstr = "# from #{each_plugin.inspect}\n"
207
+ each_plugin.report_specification.each do |each_datum|
208
+ tstr += "t.#{each_datum[1]}\t#{each_datum[0].inspect}\n"
209
+ end
210
+ str = str + tstr
209
211
  end
210
- str = str + tstr
212
+ end
213
+ private
214
+ def method_missing symbol, *args
215
+ plugins.send symbol, *args
211
216
  end
212
217
  end
213
- private
214
- def method_missing symbol, *args
215
- plugins.send symbol, *args
216
- end
218
+ Dir[File.dirname(__FILE__) + "/plugins/*_statistics.rb"].each {|filename| require File.expand_path(filename)}
219
+ HandStatistics.delegate_plugin_public_methods_except HandStatisticsAPI.public_methods
217
220
  end
218
221
  # Load Plugins and Delegate non-api public methods to plugins
219
- Dir[File.dirname(__FILE__) + "/plugins/*_statistics.rb"].each {|filename| require File.expand_path(filename)}
220
- HandStatistics.delegate_plugin_public_methods_except HandStatisticsAPI.public_methods
221
-
222
- # # puts HandStatistics.rails_migration_data
223
- # puts HandStatistics.player_statistics_migration_data
222
+ # puts Pokerstats::HandStatistics.hand_statistics_migration_data
223
+ # puts Pokerstats::HandStatistics.player_statistics_migration_data