2 # -*- coding: utf-8 -*-
4 """Manage collecting and formatting of stats and tooltips."""
5 # Copyright 2008-2011, Ray E. Barker
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 ########################################################################
24 # How to write a new stat:
25 # 0 Do not use a name like "xyz_2". Names ending in _ and a single digit are
26 # used to indicate the number of decimal places the user wants to see in the Hud.
27 # 1 You can see a listing of all the raw stats (e.g., from the HudCache table)
28 # by running Database.py as a stand along program. You need to combine
29 # those raw stats to get stats to present to the HUD. If you need more
30 # information than is in the HudCache table, then you have to write SQL.
31 # 2 The raw stats seen when you run Database.py are available in the Stats.py
32 # in the stat_dict dict. For example the number of vpips would be
33 # stat_dict[player]['vpip']. So the % vpip is
34 # float(stat_dict[player]['vpip'])/float(stat_dict[player]['n']). You can see how the
35 # keys of stat_dict relate to the column names in HudCache by inspecting
36 # the proper section of the SQL.py module.
37 # The stat_dict keys should be in lower case, i.e. vpip not VPIP, since
38 # postgres returns the column names in lower case.
39 # 3 You have to write a small function for each stat you want to add. See
40 # the vpip() function for example. This function has to be protected from
41 # exceptions, using something like the try:/except: paragraphs in vpip.
42 # 4 The name of the function has to be the same as the of the stat used
44 # 5 The stat functions have a peculiar return value, which is outlined in
45 # the do_stat function. This format is useful for tool tips and maybe
47 # 6 For each stat you make add a line to the __main__ function to test it.
50 _
= L10n
.get_translation()
52 # Standard Library modules
60 # FreePokerTools modules
66 # logging has been set up in fpdb.py or HUD_main.py, use their settings:
67 log
= logging
.getLogger("db")
70 re_Places
= re
.compile("_[0-9]$")
74 encoder
= codecs
.lookup(Configuration
.LOCALE_ENCODING
)
76 stat_descriptions
= {}
78 # Since tuples are immutable, we have to create a new one when
79 # overriding any decimal placements. Copy old ones and recreate the
80 # second value in tuple to specified format-
81 def __stat_override(decimals
, stat_vals
):
82 s
= '%.*f' % (decimals
, 100.0*stat_vals
[0])
83 res
= (stat_vals
[0], s
, stat_vals
[2],
84 stat_vals
[3], stat_vals
[4], stat_vals
[5])
88 def do_tip(widget
, tip
):
89 _tip
= Charset
.to_utf8(tip
)
90 widget
.set_tooltip_text(_tip
)
93 def do_stat(stat_dict
, player
= 24, stat
= 'vpip'):
95 match
= re_Places
.search(stat
)
96 if match
: # override if necessary
99 result
= eval("%(stat)s(stat_dict, %(player)d)" % {'stat': statname
, 'player': player
})
101 # If decimal places have been defined, override result[1]
102 # NOTE: decimal place override ALWAYS assumes the raw result is a
103 # fraction (x/100); manual decimal places really only make sense for
104 # percentage values. Also, profit/100 hands (bb/BB) already default
105 # to three decimal places anyhow, so they are unlikely override
108 places
= int(stat
[-1:])
109 result
= __stat_override(places
, result
)
112 # OK, for reference the tuple returned by the stat is:
113 # 0 - The stat, raw, no formating, eg 0.33333333
114 # 1 - formatted stat with appropriate precision, eg. 33; shown in HUD
115 # 2 - formatted stat with appropriate precision, punctuation and a hint, eg v=33%
116 # 3 - same as #2 except name of stat instead of hint, eg vpip=33%
117 # 4 - the calculation that got the stat, eg 9/27
118 # 5 - the name of the stat, useful for a tooltip, eg vpip
120 ###########################################
121 # functions that return individual stats
123 def totalprofit(stat_dict
, player
):
124 stat_descriptions
["totalprofit"] = _("Total Profit") + " (totalprofit)"
125 if stat_dict
[player
]['net'] != 0:
126 stat
= float(stat_dict
[player
]['net']) / 100
127 return (stat
, '$%.2f' % stat
, 'tp=$%.2f' % stat
, 'totalprofit=$%.2f' % stat
, str(stat
), _('Total Profit'))
128 return ('0', '$0.00', 'tp=0', 'totalprofit=0', '0', _('Total Profit'))
130 def playername(stat_dict
, player
):
131 stat_descriptions
["playername"] = _("Player Name") + " (playername)"
132 return (stat_dict
[player
]['screen_name'],
133 stat_dict
[player
]['screen_name'],
134 stat_dict
[player
]['screen_name'],
135 stat_dict
[player
]['screen_name'],
136 stat_dict
[player
]['screen_name'],
137 stat_dict
[player
]['screen_name'])
139 def playershort(stat_dict
, player
):
140 stat_descriptions
["playershort"] = (_("Player Name")+" 1-6") + " (playershort)"
141 r
= stat_dict
[player
]['screen_name']
148 stat_dict
[player
]['screen_name'],
149 (_("Player Name")+" 1-6")
152 def vpip(stat_dict
, player
):
153 stat_descriptions
["vpip"] = _("Voluntarily put in preflop/3rd street %") + " (vpip)"
156 stat
= float(stat_dict
[player
]['vpip'])/float(stat_dict
[player
]['n'])
158 '%3.1f' % (100.0*stat
),
159 'v=%3.1f%%' % (100.0*stat
),
160 'vpip=%3.1f%%' % (100.0*stat
),
161 '(%d/%d)' % (stat_dict
[player
]['vpip'], stat_dict
[player
]['n']),
162 _('Voluntarily put in preflop/3rd street %')
164 except: return (stat
,
169 _('Voluntarily put in preflop/3rd street %')
172 def pfr(stat_dict
, player
):
173 stat_descriptions
["pfr"] = _("Preflop/3rd street raise %") + " (pfr)"
176 stat
= float(stat_dict
[player
]['pfr'])/float(stat_dict
[player
]['n'])
178 '%3.1f' % (100.0*stat
),
179 'p=%3.1f%%' % (100.0*stat
),
180 'pfr=%3.1f%%' % (100.0*stat
),
181 '(%d/%d)' % (stat_dict
[player
]['pfr'], stat_dict
[player
]['n']),
182 _('Preflop/3rd street raise %')
190 _('Preflop/3rd street raise %')
193 def wtsd(stat_dict
, player
):
194 stat_descriptions
["wtsd"] = _("% went to showdown when seen flop/4th street") + " (wtsd)"
197 stat
= float(stat_dict
[player
]['sd'])/float(stat_dict
[player
]['saw_f'])
199 '%3.1f' % (100.0*stat
),
200 'w=%3.1f%%' % (100.0*stat
),
201 'wtsd=%3.1f%%' % (100.0*stat
),
202 '(%d/%d)' % (stat_dict
[player
]['sd'], stat_dict
[player
]['saw_f']),
203 _('% went to showdown when seen flop/4th street')
211 _('% went to showdown when seen flop/4th street')
214 def wmsd(stat_dict
, player
):
215 stat_descriptions
["wmsd"] = _("% won some money at showdown") + " (wmsd)"
218 stat
= float(stat_dict
[player
]['wmsd'])/float(stat_dict
[player
]['sd'])
220 '%3.1f' % (100.0*stat
),
221 'w=%3.1f%%' % (100.0*stat
),
222 'wmsd=%3.1f%%' % (100.0*stat
),
223 '(%5.1f/%d)' % (float(stat_dict
[player
]['wmsd']), stat_dict
[player
]['sd']),
224 _('% won some money at showdown')
232 _('% won some money at showdown')
235 # Money is stored as pennies, so there is an implicit 100-multiplier
237 def profit100(stat_dict
, player
):
238 stat_descriptions
["profit100"] = _("Profit per 100 hands") + " (profit100)"
241 stat
= float(stat_dict
[player
]['net'])/float(stat_dict
[player
]['n'])
245 'p/100=%.2f' % (stat
),
246 '%d/%d' % (stat_dict
[player
]['net'], stat_dict
[player
]['n']),
247 _('Profit per 100 hands')
250 print _("exception calculating p/100: 100 * %d / %d") % (stat_dict
[player
]['net'], stat_dict
[player
]['n'])
256 _('Profit per 100 hands')
259 def bbper100(stat_dict
, player
):
260 stat_descriptions
["bbper100"] = _("Big blinds won per 100 hands") + " (bbper100)"
263 stat
= 100.0 * float(stat_dict
[player
]['net']) / float(stat_dict
[player
]['bigblind'])
266 'bb100=%5.3f' % (stat
),
267 'bb100=%5.3f' % (stat
),
268 '(%d,%d)' % (100*stat_dict
[player
]['net'],stat_dict
[player
]['bigblind']),
269 _('Big blinds won per 100 hands')
272 log
.info(_("exception calculating bb/100: ")+str(stat_dict
[player
]))
278 _('Big blinds won per 100 hands')
281 def BBper100(stat_dict
, player
):
282 stat_descriptions
["BBper100"] = _("Big bets won per 100 hands") + " (BBper100)"
285 stat
= 50 * float(stat_dict
[player
]['net']) / float(stat_dict
[player
]['bigblind'])
288 'BB100=%5.3f' % (stat
),
289 'BB100=%5.3f' % (stat
),
290 '(%d,%d)' % (100*stat_dict
[player
]['net'],2*stat_dict
[player
]['bigblind']),
291 _('Big bets won per 100 hands')
294 log
.info(_("exception calculating BB/100: ")+str(stat_dict
[player
]))
300 _('Big bets won per 100 hands')
303 def saw_f(stat_dict
, player
):
304 stat_descriptions
["saw_f"] = _("Flop/4th street seen %") + " (saw_f)"
306 num
= float(stat_dict
[player
]['saw_f'])
307 den
= float(stat_dict
[player
]['n'])
310 '%3.1f' % (100.0*stat
),
311 'sf=%3.1f%%' % (100.0*stat
),
312 'saw_f=%3.1f%%' % (100.0*stat
),
313 '(%d/%d)' % (stat_dict
[player
]['saw_f'], stat_dict
[player
]['n']),
314 _('Flop/4th street seen %')
323 _('Flop/4th street seen %')
326 def n(stat_dict
, player
):
327 stat_descriptions
["n"] = _("Number of hands seen") + " (n)"
329 # If sample is large enough, use X.Yk notation instead
330 _n
= stat_dict
[player
]['n']
335 _c
= float(c
) / 100.0
340 fmt
= '%d.%dk' % (k
, d
)
341 return (stat_dict
[player
]['n'],
343 'n=%d' % (stat_dict
[player
]['n']),
344 'n=%d' % (stat_dict
[player
]['n']),
345 '(%d)' % (stat_dict
[player
]['n']),
346 _('Number of hands seen')
349 # Number of hands shouldn't ever be "NA"; zeroes are better here
355 _('Number of hands seen')
358 def fold_f(stat_dict
, player
):
362 stat
= float(stat_dict
[player
]['fold_2'])/float(stat_dict
[player
]['saw_f'])
364 '%3.1f' % (100.0*stat
),
365 'ff=%3.1f%%' % (100.0*stat
),
366 'fold_f=%3.1f%%' % (100.0*stat
),
367 '(%d/%d)' % (stat_dict
[player
]['fold_2'], stat_dict
[player
]['saw_f']),
379 def steal(stat_dict
, player
):
380 stat_descriptions
["steal"] = _("% steal attempted") + " (steal)"
383 stat
= float(stat_dict
[player
]['steal'])/float(stat_dict
[player
]['steal_opp'])
385 '%3.1f' % (100.0*stat
),
386 'st=%3.1f%%' % (100.0*stat
),
387 'steal=%3.1f%%' % (100.0*stat
),
388 '(%d/%d)' % (stat_dict
[player
]['steal'], stat_dict
[player
]['steal_opp']),
389 _('% steal attempted')
392 return (stat
, 'NA', 'st=NA', 'steal=NA', '(0/0)', '% steal attempted')
394 def s_steal(stat_dict
, player
):
395 stat_descriptions
["s_steal"] = _("% steal success") + " (s_steal)"
398 stat
= float(stat_dict
[player
]['suc_st'])/float(stat_dict
[player
]['steal'])
400 '%3.1f' % (100.0*stat
),
401 's_st=%3.1f%%' % (100.0*stat
),
402 's_steal=%3.1f%%' % (100.0*stat
),
403 '(%d/%d)' % (stat_dict
[player
]['suc_st'], stat_dict
[player
]['steal']),
407 return (stat
, 'NA', 'st=NA', 's_steal=NA', '(0/0)', '% steal success')
409 def f_SB_steal(stat_dict
, player
):
410 stat_descriptions
["f_SB_steal"] = _("% folded SB to steal") + " (f_SB_steal)"
413 stat
= float(stat_dict
[player
]['sbnotdef'])/float(stat_dict
[player
]['sbstolen'])
415 '%3.1f' % (100.0*stat
),
416 'fSB=%3.1f%%' % (100.0*stat
),
417 'fSB_s=%3.1f%%' % (100.0*stat
),
418 '(%d/%d)' % (stat_dict
[player
]['sbnotdef'], stat_dict
[player
]['sbstolen']),
419 _('% folded SB to steal'))
426 _('% folded SB to steal'))
428 def f_BB_steal(stat_dict
, player
):
429 stat_descriptions
["f_BB_steal"] = _("% folded BB to steal") + " (f_BB_steal)"
432 stat
= float(stat_dict
[player
]['bbnotdef'])/float(stat_dict
[player
]['bbstolen'])
434 '%3.1f' % (100.0*stat
),
435 'fBB=%3.1f%%' % (100.0*stat
),
436 'fBB_s=%3.1f%%' % (100.0*stat
),
437 '(%d/%d)' % (stat_dict
[player
]['bbnotdef'], stat_dict
[player
]['bbstolen']),
438 _('% folded BB to steal'))
445 _('% folded BB to steal'))
447 def f_steal(stat_dict
, player
):
448 stat_descriptions
["f_steal"] = _("% folded blind to steal") + " (f_steal)"
451 folded_blind
= stat_dict
[player
]['sbnotdef'] + stat_dict
[player
]['bbnotdef']
452 blind_stolen
= stat_dict
[player
]['sbstolen'] + stat_dict
[player
]['bbstolen']
454 stat
= float(folded_blind
)/float(blind_stolen
)
456 '%3.1f' % (100.0*stat
),
457 'fB=%3.1f%%' % (100.0*stat
),
458 'fB_s=%3.1f%%' % (100.0*stat
),
459 '(%d/%d)' % (folded_blind
, blind_stolen
),
460 _('% folded blind to steal'))
467 _('% folded blind to steal'))
469 def three_B(stat_dict
, player
):
470 stat_descriptions
["three_B"] = _("% 3 bet preflop/3rd street") + " (three_B)"
473 stat
= float(stat_dict
[player
]['tb_0'])/float(stat_dict
[player
]['tb_opp_0'])
475 '%3.1f' % (100.0*stat
),
476 '3B=%3.1f%%' % (100.0*stat
),
477 '3B_pf=%3.1f%%' % (100.0*stat
),
478 '(%d/%d)' % (stat_dict
[player
]['tb_0'], stat_dict
[player
]['tb_opp_0']),
479 _('% 3 bet preflop/3rd street'))
486 _('% 3 bet preflop/3rd street'))
488 def four_B(stat_dict
, player
):
489 stat_descriptions
["four_B"] = _("% 4 bet preflop/3rd street") + " (four_B)"
492 stat
= float(stat_dict
[player
]['fb_0'])/float(stat_dict
[player
]['fb_opp_0'])
494 '%3.1f' % (100.0*stat
),
495 '4B=%3.1f%%' % (100.0*stat
),
496 '4B=%3.1f%%' % (100.0*stat
),
497 '(%d/%d)' % (stat_dict
[player
]['fb_0'], stat_dict
[player
]['fb_opp_0']),
498 _('% 4 bet preflop/3rd street'))
505 _('% 4 bet preflop/3rd street'))
507 def cfour_B(stat_dict
, player
):
508 stat_descriptions
["cfour_B"] = _("% cold 4 bet preflop/3rd street") + " (cfour_B)"
511 stat
= float(stat_dict
[player
]['cfb_0'])/float(stat_dict
[player
]['cfb_opp_0'])
513 '%3.1f' % (100.0*stat
),
514 'C4B=%3.1f%%' % (100.0*stat
),
515 'C4B_pf=%3.1f%%' % (100.0*stat
),
516 '(%d/%d)' % (stat_dict
[player
]['cfb_0'], stat_dict
[player
]['cfb_opp_0']),
517 _('% cold 4 bet preflop/3rd street'))
524 _('% cold 4 bet preflop/3rd street'))
526 def squeeze(stat_dict
, player
):
527 stat_descriptions
["squeeze"] = _("% squeeze preflop") + " (squeeze)"
530 stat
= float(stat_dict
[player
]['sqz_0'])/float(stat_dict
[player
]['sqz_opp_0'])
532 '%3.1f' % (100.0*stat
),
533 'SQZ=%3.1f%%' % (100.0*stat
),
534 'SQZ_pf=%3.1f%%' % (100.0*stat
),
535 '(%d/%d)' % (stat_dict
[player
]['sqz_0'], stat_dict
[player
]['sqz_opp_0']),
536 _('% squeeze preflop'))
543 _('% squeeze preflop'))
546 def raiseToSteal(stat_dict
, player
):
547 stat_descriptions
["raiseToSteal"] = _("% raise to steal") + " (raiseToSteal)"
550 stat
= float(stat_dict
[player
]['rts'])/float(stat_dict
[player
]['rts_opp'])
552 '%3.1f' % (100.0*stat
),
553 'RST=%3.1f%%' % (100.0*stat
),
554 'RST_pf=%3.1f%%' % (100.0*stat
),
555 '(%d/%d)' % (stat_dict
[player
]['rts'], stat_dict
[player
]['rts_opp']),
556 _('% raise to steal'))
563 _('% raise to steal'))
566 def f_3bet(stat_dict
, player
):
567 stat_descriptions
["f_3bet"] = _("% fold to 3 bet preflop/3rd street") + " (f_3bet)"
570 stat
= float(stat_dict
[player
]['f3b_0'])/float(stat_dict
[player
]['f3b_opp_0'])
572 '%3.1f' % (100.0*stat
),
573 'F3B=%3.1f%%' % (100.0*stat
),
574 'F3B_pf=%3.1f%%' % (100.0*stat
),
575 '(%d/%d)' % (stat_dict
[player
]['f3b_0'], stat_dict
[player
]['f3b_opp_0']),
576 _('% fold to 3 bet preflop/3rd street'))
583 _('% fold to 3 bet preflop/3rd street'))
585 def f_4bet(stat_dict
, player
):
586 stat_descriptions
["f_4bet"] = _("% fold to 4 bet preflop/3rd street") + " (f_4bet)"
589 stat
= float(stat_dict
[player
]['f4b_0'])/float(stat_dict
[player
]['f4b_opp_0'])
591 '%3.1f' % (100.0*stat
),
592 'F4B=%3.1f%%' % (100.0*stat
),
593 'F4B_pf=%3.1f%%' % (100.0*stat
),
594 '(%d/%d)' % (stat_dict
[player
]['f4b_0'], stat_dict
[player
]['f4b_opp_0']),
595 _('% fold to 4 bet preflop/3rd street'))
602 _('% fold to 4 bet preflop/3rd street'))
604 def WMsF(stat_dict
, player
):
605 stat_descriptions
["WMsF"] = _("% won money when seen flop/4th street") + " (WMsF)"
608 stat
= float(stat_dict
[player
]['w_w_s_1'])/float(stat_dict
[player
]['saw_1'])
610 '%3.1f' % (100.0*stat
),
611 'wf=%3.1f%%' % (100.0*stat
),
612 'w_w_f=%3.1f%%' % (100.0*stat
),
613 '(%d/%d)' % (stat_dict
[player
]['w_w_s_1'], stat_dict
[player
]['saw_f']),
614 _('% won money when seen flop/4th street'))
621 _('% won money when seen flop/4th street'))
623 def a_freq1(stat_dict
, player
):
624 stat_descriptions
["a_freq1"] = _("Aggression frequency flop/4th street") + " (a_freq1)"
627 stat
= float(stat_dict
[player
]['aggr_1'])/float(stat_dict
[player
]['saw_f'])
629 '%3.1f' % (100.0*stat
),
630 'a1=%3.1f%%' % (100.0*stat
),
631 'a_fq_1=%3.1f%%' % (100.0*stat
),
632 '(%d/%d)' % (stat_dict
[player
]['aggr_1'], stat_dict
[player
]['saw_f']),
633 _('Aggression frequency flop/4th street'))
640 _('Aggression frequency flop/4th street'))
642 def a_freq2(stat_dict
, player
):
643 stat_descriptions
["a_freq2"] = _("Aggression frequency turn/5th street") + " (a_freq2)"
646 stat
= float(stat_dict
[player
]['aggr_2'])/float(stat_dict
[player
]['saw_2'])
648 '%3.1f' % (100.0*stat
),
649 'a2=%3.1f%%' % (100.0*stat
),
650 'a_fq_2=%3.1f%%' % (100.0*stat
),
651 '(%d/%d)' % (stat_dict
[player
]['aggr_2'], stat_dict
[player
]['saw_2']),
652 _('Aggression frequency turn/5th street'))
659 _('Aggression frequency turn/5th street'))
661 def a_freq3(stat_dict
, player
):
662 stat_descriptions
["a_freq3"] = _("Aggression frequency river/6th street") + " (a_freq3)"
665 stat
= float(stat_dict
[player
]['aggr_3'])/float(stat_dict
[player
]['saw_3'])
667 '%3.1f' % (100.0*stat
),
668 'a3=%3.1f%%' % (100.0*stat
),
669 'a_fq_3=%3.1f%%' % (100.0*stat
),
670 '(%d/%d)' % (stat_dict
[player
]['aggr_3'], stat_dict
[player
]['saw_3']),
671 _('Aggression frequency river/6th street'))
678 _('Aggression frequency river/6th street'))
680 def a_freq4(stat_dict
, player
):
681 stat_descriptions
["a_freq4"] = _("Aggression frequency 7th street") + " (a_freq4)"
684 stat
= float(stat_dict
[player
]['aggr_4'])/float(stat_dict
[player
]['saw_4'])
686 '%3.1f' % (100.0*stat
),
687 'a4=%3.1f%%' % (100.0*stat
),
688 'a_fq_4=%3.1f%%' % (100.0*stat
),
689 '(%d/%d)' % (stat_dict
[player
]['aggr_4'], stat_dict
[player
]['saw_4']),
690 _('Aggression frequency 7th street'))
697 _('Aggression frequency 7th street'))
699 def a_freq_123(stat_dict
, player
):
700 stat_descriptions
["a_freq_123"] = _("Post-flop aggression frequency") + " (a_freq_123)"
703 stat
= float( stat_dict
[player
]['aggr_1'] + stat_dict
[player
]['aggr_2'] + stat_dict
[player
]['aggr_3']
704 ) / float( stat_dict
[player
]['saw_1'] + stat_dict
[player
]['saw_2'] + stat_dict
[player
]['saw_3']);
706 '%3.1f' % (100.0*stat
),
707 'afq=%3.1f%%' % (100.0*stat
),
708 'postf_aggfq=%3.1f%%' % (100.0*stat
),
709 '(%d/%d)' % ( stat_dict
[player
]['aggr_1']
710 + stat_dict
[player
]['aggr_2']
711 + stat_dict
[player
]['aggr_3']
712 , stat_dict
[player
]['saw_1']
713 + stat_dict
[player
]['saw_2']
714 + stat_dict
[player
]['saw_3']
716 _('Post-flop aggression frequency'))
723 _('Post-flop aggression frequency'))
725 def agg_freq(stat_dict
, player
):
726 #TODO: remove, dupe of a_freq_123
729 #Agression on the flop and all streets
730 bet_raise
= stat_dict
[player
]['aggr_1'] + stat_dict
[player
]['aggr_2'] + stat_dict
[player
]['aggr_3'] + stat_dict
[player
]['aggr_4']
731 #number post flop streets seen, this must be number of post-flop calls !!
732 post_call
= stat_dict
[player
]['call_1'] + stat_dict
[player
]['call_2'] + stat_dict
[player
]['call_3'] + stat_dict
[player
]['call_4']
733 #Number of post flop folds this info is not yet in the database
734 post_fold
= stat_dict
[player
]['f_freq_1'] + stat_dict
[player
]['f_freq_2'] + stat_dict
[player
]['f_freq_3'] + stat_dict
[player
]['f_freq_4']
736 stat
= float (bet_raise
) / float(post_call
+ post_fold
+ bet_raise
)
739 '%3.1f' % (100.0*stat
),
740 'afr=%3.1f%%' % (100.0*stat
),
741 'agg_fr=%3.1f%%' % (100.0*stat
),
742 '(%d/%d)' % (bet_raise
, (post_call
+ post_fold
+ bet_raise
)),
752 def agg_fact(stat_dict
, player
):
753 stat_descriptions
["agg_fact"] = _("Aggression factor") + " (agg_fact)"
756 bet_raise
= stat_dict
[player
]['aggr_1'] + stat_dict
[player
]['aggr_2'] + stat_dict
[player
]['aggr_3'] + stat_dict
[player
]['aggr_4']
757 post_call
= stat_dict
[player
]['call_1'] + stat_dict
[player
]['call_2'] + stat_dict
[player
]['call_3'] + stat_dict
[player
]['call_4']
760 stat
= float (bet_raise
) / float(post_call
)
762 stat
= float (bet_raise
)
765 'afa=%2.2f' % (stat
) ,
766 'agg_fa=%2.2f' % (stat
) ,
767 '(%d/%d)' % (bet_raise
, post_call
),
768 _('Aggression factor'))
775 _('Aggression factor'))
777 def cbet(stat_dict
, player
):
778 stat_descriptions
["cbet"] = _("% continuation bet") + " (cbet)"
781 cbets
= stat_dict
[player
]['cb_1']+stat_dict
[player
]['cb_2']+stat_dict
[player
]['cb_3']+stat_dict
[player
]['cb_4']
782 oppt
= stat_dict
[player
]['cb_opp_1']+stat_dict
[player
]['cb_opp_2']+stat_dict
[player
]['cb_opp_3']+stat_dict
[player
]['cb_opp_4']
783 stat
= float(cbets
)/float(oppt
)
785 '%3.1f' % (100.0*stat
),
786 'cbet=%3.1f%%' % (100.0*stat
),
787 'cbet=%3.1f%%' % (100.0*stat
),
788 '(%d/%d)' % (cbets
, oppt
),
789 _('% continuation bet'))
796 _('% continuation bet'))
798 def cb1(stat_dict
, player
):
799 stat_descriptions
["cb1"] = _("% continuation bet flop/4th street") + " (cb1)"
802 stat
= float(stat_dict
[player
]['cb_1'])/float(stat_dict
[player
]['cb_opp_1'])
804 '%3.1f' % (100.0*stat
),
805 'cb1=%3.1f%%' % (100.0*stat
),
806 'cb_1=%3.1f%%' % (100.0*stat
),
807 '(%d/%d)' % (stat_dict
[player
]['cb_1'], stat_dict
[player
]['cb_opp_1']),
808 _('% continuation bet flop/4th street'))
815 _('% continuation bet flop/4th street'))
817 def cb2(stat_dict
, player
):
818 stat_descriptions
["cb2"] = _("% continuation bet turn/5th street") + " (cb2)"
821 stat
= float(stat_dict
[player
]['cb_2'])/float(stat_dict
[player
]['cb_opp_2'])
823 '%3.1f' % (100.0*stat
),
824 'cb2=%3.1f%%' % (100.0*stat
),
825 'cb_2=%3.1f%%' % (100.0*stat
),
826 '(%d/%d)' % (stat_dict
[player
]['cb_2'], stat_dict
[player
]['cb_opp_2']),
827 _('% continuation bet turn/5th street'))
834 _('% continuation bet turn/5th street'))
836 def cb3(stat_dict
, player
):
837 stat_descriptions
["cb3"] = _("% continuation bet river/6th street") + " (cb3)"
840 stat
= float(stat_dict
[player
]['cb_3'])/float(stat_dict
[player
]['cb_opp_3'])
842 '%3.1f' % (100.0*stat
),
843 'cb3=%3.1f%%' % (100.0*stat
),
844 'cb_3=%3.1f%%' % (100.0*stat
),
845 '(%d/%d)' % (stat_dict
[player
]['cb_3'], stat_dict
[player
]['cb_opp_3']),
846 _('% continuation bet river/6th street'))
853 _('% continuation bet river/6th street'))
855 def cb4(stat_dict
, player
):
856 stat_descriptions
["cb4"] = _("% continuation bet 7th street") + " (cb4)"
859 stat
= float(stat_dict
[player
]['cb_4'])/float(stat_dict
[player
]['cb_opp_4'])
861 '%3.1f' % (100.0*stat
),
862 'cb4=%3.1f%%' % (100.0*stat
),
863 'cb_4=%3.1f%%' % (100.0*stat
),
864 '(%d/%d)' % (stat_dict
[player
]['cb_4'], stat_dict
[player
]['cb_opp_4']),
865 _('% continuation bet 7th street'))
872 _('% continuation bet 7th street'))
874 def ffreq1(stat_dict
, player
):
875 stat_descriptions
["ffreq1"] = _("% fold frequency flop/4th street") + " (ffreq1)"
878 stat
= float(stat_dict
[player
]['f_freq_1'])/float(stat_dict
[player
]['was_raised_1'])
880 '%3.1f' % (100.0*stat
),
881 'ff1=%3.1f%%' % (100.0*stat
),
882 'ff_1=%3.1f%%' % (100.0*stat
),
883 '(%d/%d)' % (stat_dict
[player
]['f_freq_1'], stat_dict
[player
]['was_raised_1']),
884 _('% fold frequency flop/4th street'))
891 _('% fold frequency flop/4th street'))
893 def ffreq2(stat_dict
, player
):
894 stat_descriptions
["ffreq2"] = _("% fold frequency turn/5th street") + " (ffreq2)"
897 stat
= float(stat_dict
[player
]['f_freq_2'])/float(stat_dict
[player
]['was_raised_2'])
899 '%3.1f' % (100.0*stat
),
900 'ff2=%3.1f%%' % (100.0*stat
),
901 'ff_2=%3.1f%%' % (100.0*stat
),
902 '(%d/%d)' % (stat_dict
[player
]['f_freq_2'], stat_dict
[player
]['was_raised_2']),
903 _('% fold frequency turn/5th street'))
910 _('% fold frequency turn/5th street'))
912 def ffreq3(stat_dict
, player
):
913 stat_descriptions
["ffreq3"] = _("% fold frequency river/6th street") + " (ffreq3)"
916 stat
= float(stat_dict
[player
]['f_freq_3'])/float(stat_dict
[player
]['was_raised_3'])
918 '%3.1f' % (100.0*stat
),
919 'ff3=%3.1f%%' % (100.0*stat
),
920 'ff_3=%3.1f%%' % (100.0*stat
),
921 '(%d/%d)' % (stat_dict
[player
]['f_freq_3'], stat_dict
[player
]['was_raised_3']),
922 _('% fold frequency river/6th street'))
929 _('% fold frequency river/6th street'))
931 def ffreq4(stat_dict
, player
):
932 stat_descriptions
["ffreq4"] = _("% fold frequency 7th street") + " (ffreq4)"
935 stat
= float(stat_dict
[player
]['f_freq_4'])/float(stat_dict
[player
]['was_raised_4'])
937 '%3.1f' % (100.0*stat
),
938 'ff4=%3.1f%%' % (100.0*stat
),
939 'ff_4=%3.1f%%' % (100.0*stat
),
940 '(%d/%d)' % (stat_dict
[player
]['f_freq_4'], stat_dict
[player
]['was_raised_4']),
941 _('% fold frequency 7th street'))
948 _('% fold frequency 7th street'))
951 def build_stat_descriptions(stats_file
):
952 for method
in dir(stats_file
):
953 if method
in ("Charset", "Configuration", "Database", "GInitiallyUnowned", "gtk", "pygtk",
954 "player", "c", "db_connection", "do_stat", "do_tip", "stat_dict", "h", "re",
955 "re_Percent", "re_Places", "L10n", "sys", "_", "log", "encoder", "codecs",
958 if method
.startswith('__'):
961 eval(method
+"(None, None)")
965 return stat_descriptions
967 if __name__
== "__main__":
970 misslist
= [ "Configuration", "Database", "Charset", "codecs", "encoder"
971 , "do_stat", "do_tip", "GInitiallyUnowned", "gtk", "pygtk"
974 statlist
= [ x
for x
in statlist
if x
not in dir(sys
) ]
975 statlist
= [ x
for x
in statlist
if x
not in dir(codecs
) ]
976 statlist
= [ x
for x
in statlist
if x
not in misslist
]
977 #print "statlist is", statlist
979 c
= Configuration
.Config()
980 #TODO: restore the below code. somehow it creates a version 119 DB but commenting this out makes it print a stat list
981 db_connection
= Database
.Database(c
)
982 h
= db_connection
.get_last_hand()
983 stat_dict
= db_connection
.get_stats_from_hand(h
, "ring")
985 for player
in stat_dict
.keys():
986 print (_("Example stats, player = %s hand = %s:") % (player
, h
))
987 for attr
in statlist
:
988 print " ", do_stat(stat_dict
, player
=player
, stat
=attr
)
990 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'vpip')
991 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'pfr')
992 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'wtsd')
993 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'profit100')
994 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'saw_f')
995 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'n')
996 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'fold_f')
997 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'wmsd')
998 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'steal')
999 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'f_SB_steal')
1000 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'f_BB_steal')
1001 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'f_steal')
1002 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'three_B')
1003 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'WMsF')
1004 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq1')
1005 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq2')
1006 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq3')
1007 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq4')
1008 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'a_freq_123')
1009 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'cb1')
1010 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'cb2')
1011 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'cb3')
1012 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'cb4')
1013 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'ffreq1')
1014 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'ffreq2')
1015 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'ffreq3')
1016 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'ffreq4')
1017 #print "player = ", player, do_stat(stat_dict, player = player, stat = 'playershort')
1020 print _("\n\nLegal stats:")
1021 print _("(add _0 to name to display with 0 decimal places, _1 to display with 1, etc)\n")
1022 for attr
in statlist
:
1023 print "%-14s %s" % (attr
, eval("%s.__doc__" % (attr
)))
1024 # print " <pu_stat pu_stat_name = \"%s\"> </pu_stat>" % (attr)
1027 #db_connection.close_connection