-
Notifications
You must be signed in to change notification settings - Fork 0
/
plm.inc
executable file
·141 lines (125 loc) · 3.68 KB
/
plm.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
// output place string. eg "1st" for 1, "2nd" for 2, etc...
function _plm_format_place($place) {
if (!is_numeric($place)) return $place;
if ($place > 3 && $place < 21) return $place . 'th';
switch ($place%10){
case 1:
$suffix = 'st';
break;
case 2:
$suffix = 'nd';
break;
case 3:
$suffix = 'rd';
break;
default:
$suffix = 'th';
}
return $place . $suffix;
}
function _plm_format_time_elapsed($seconds, $short_form=false) {
$days = (int) ($seconds / (60*60*24));
if ($days < 7){
$str1 = $short_form ? 'Day' : 'day';
$strn = $short_form ? 'Dys' : 'days';
return format_plural($days, "1 $str1", "@count $strn");
}
$weeks = (int) ($days / 7);
if ($weeks < 8) {
$str1 = $short_form ? 'Wk' : 'week';
$strn = $short_form ? 'Wks' : 'weeks';
return format_plural($weeks, "1 $str1", "@count $strn");
}
$months = (int) ($weeks / 4);
if ($months < 12) {
$str1 = $short_form ? 'Mo' : 'month';
$strn = $short_form ? 'Mos' : 'months';
return format_plural($months, "1 $str1", "@count $strn");
}
$years = (int) ($weeks / 52);
$months %= 12;
$elapsed = format_plural($years, '1 Yr', '@count Yr');
if ($months) $elapsed .= " $months m";
return $elapsed;
}
function _plm_rules_default_buyin($sid) {
return variable_get('plm_default_buyin', 10);
}
// Default point distribution for a game
// Could be dependent on ruleset for season, etc, but hardcoded for now
function _plm_rules_default_points($game, $place) {
switch ($place){
case 1:
return 10;
case 2:
return 7;
case 3:
return 5;
case 4:
return 3;
case 5:
return 1;
default:
return 0;
}
}
function _plm_rules_default_payout($game, $place) {
$num_players = $game->num_players;
if ($game->payid){
$payrule = _plm_get_payrule($game->payid, $num_players, $place);
if ($payrule) return $payrule->amount;
}
$buyin = $game->buyin;
$pot_total = $game->pot_start + $num_players*$buyin;
if ($pot_total <= 0) return 0;
$pot_left = $pot_total;
if ($buyin == 0) $buyin = (int)($pot_total/$num_players);
if ($buyin == (int)$buyin){
$round_units = 1.00;
//$round_units = (int)($buyin/2);
}
$min_payout = (int)($buyin/2);
for ($i=1;$i<=$place;$i++){
$remainder = $pot_left % ($round_units*2);
// don't give last 2 places the same payout
if ($pot_left == $round_units*2) $remainder = $round_units*2;
$pot_left -= $remainder;
if ($pot_left > $min_payout)
$pot_left /= 2;
$payout = $pot_left + $remainder;
}
return $payout;
}
function _plm_get_est_cutoff_points($plm_season, $tenth) {
$num_games_finished = _plm_get_num_games($plm_season->sid, "finished != 0");
//$num_games_total = _plm_get_num_games($plm_season->sid);
$num_games_total = $plm_season->num_games;
return round($tenth*$num_games_total/$num_games_finished);
}
function _plm_get_eoy_est($plm_season, $eoy_total) {
$num_games_finished = _plm_get_num_games($plm_season->sid, "finished != 0");
$num_games_total = $plm_season->num_games;
return round($eoy_total*$num_games_total/$num_games_finished);
}
// Temporarily hardcoded
function _plm_get_eoy_total($plm_season) {
//$num_games_finished = _plm_get_num_games($plm_season->sid, "finished != 0");
$games = _plm_get_games($plm_season->sid);
$total = 0;
foreach ($games as $g) {
$total += $g->eoy_rake;
}
return $total;
}
// Temporarily hardcoded
//function _plm_get_season_num_games($plm_season) {
// switch ($plm_season->title) {
// case 'Season 5':
// case 'Season 6':
// case 'Season 7':
// return 26;
// default:
// return 26;
// }
//}