diff options
Diffstat (limited to 'http')
-rw-r--r-- | http/api.php | 40 | ||||
-rw-r--r-- | http/pkle2018-test.php | 19 |
2 files changed, 47 insertions, 12 deletions
diff --git a/http/api.php b/http/api.php index 29c56ec..3ab7f3d 100644 --- a/http/api.php +++ b/http/api.php @@ -90,7 +90,7 @@ function check_parameters($parameters) { if (!isset($parameters['manual']) || !isset($parameters['manual']['min_points']) || !isset($parameters['manual']['tournament_weight'])) { ensure_parameters($parameters, array('tournament_rank', 'over39_boards')); check_values($parameters, array( - 'tournament_rank' => function($r) { return ctype_digit($r) && intval($r) >= 0 && intval($r) <= 7; }, + 'tournament_rank' => function($r) { return ctype_digit($r) && ((intval($r) >= 0 && intval($r) <= 7) || intval($r) == RANK_KMP); }, 'over39_boards' => function($r) { return ctype_digit($r) && intval($r) >= 0 && intval($r) <= 1; } )); } else { @@ -106,23 +106,28 @@ function check_parameters($parameters) { } } +const RANK_KMP = 101; + function parse_parameters($parameters) { $return = array(); $return['type'] = intval($parameters['type']); if ($return['type'] == 3 || $return['type'] > 4) { throw new ParametersException('Parameter: type has incorrect value (' . $return['type'] . ')'); } + if ($return['type'] != 2 && $parameters['tournament_rank'] == RANK_KMP) { + throw new ParametersException('Parameter: type has incorrect value (' . $return['type'] . ') for KMP tournament'); + } $return['contestants'] = intval($parameters['contestants']); $return['players'] = isset($parameters['players']) ? intval($parameters['players']) : intval($parameters['contestants']) * $return['type']; $return['title_sum'] = floatval($parameters['title_sum']); $weights = array( - array(1, 2, 4, 5, 7, 10, 15, 25), - array(2, 3, 5, 7, 10, 15, 25, 40) + array(1, 2, 4, 5, 7, 10, 15, 25, RANK_KMP => 0), + array(2, 3, 5, 7, 10, 15, 25, 40, RANK_KMP => 0) ); $return['tournament_weight'] = (isset($parameters['manual']) && isset($parameters['manual']['tournament_weight'])) ? intval($parameters['manual']['tournament_weight']) : $weights[intval($parameters['over39_boards'])][intval($parameters['tournament_rank'])]; $min_points = array( - array(0, 0, 0, 0, 50, 75, 150, 200), - array(0, 0, 0, 0, 70, 100, 200, 300) + array(0, 0, 0, 0, 50, 75, 150, 200, RANK_KMP => 0), + array(0, 0, 0, 0, 70, 100, 200, 300, RANK_KMP => 0) ); $return['min_points'] = (isset($parameters['manual']) && isset($parameters['manual']['min_points'])) ? intval($parameters['manual']['min_points']) : $min_points[intval($parameters['over39_boards'])][intval($parameters['tournament_rank'])]; $return['players_coefficient'] = (isset($parameters['manual']) && isset($parameters['manual']['players_coefficient'])) ? floatval($parameters['manual']['players_coefficient']) : 0.05; @@ -196,11 +201,32 @@ function calculate_points($parameters) { return $result; } +function calculate_kmp_points($parameters) { + $max_points = safe_ceil($parameters['contestants'] * 0.5); + $min_points = 1; + $result = array("sum" => 0, "points" => array(1 => $max_points)); + for ($place = 2; $place <= $parameters['contestants']; $place++) { + $result['points'][$place] = max($min_points, $result['points'][$place-1]-1); + $result['sum'] += $parameters['type'] * $result['points'][$place]; + } + if ($parameters['title_sum'] / $parameters['players'] >= 2.5) { + $result['points'][1] += 5; + $result['points'][2] += 3; + $result['points'][3] += 1; + $result['sum'] += $parameters['type'] * 8; + } + return $result; +} + function run($parameters) { try { check_parameters($parameters); - $parameters = parse_parameters($parameters); - $result = calculate_points($parameters); + $params = parse_parameters($parameters); + if ($parameters['tournament_rank'] == RANK_KMP) { + $result = calculate_kmp_points($params); + } else { + $result = calculate_points($params); + } return $result; } catch (ParametersException $e) { diff --git a/http/pkle2018-test.php b/http/pkle2018-test.php index c236c0d..446a94c 100644 --- a/http/pkle2018-test.php +++ b/http/pkle2018-test.php @@ -90,6 +90,7 @@ function sendit(form) { over39_boards: parseInt(form.rozdan.value) } var tourtypes = ['tk', 'to', 'tp', 'ok', 'ok1', 'ot', 'gp', 'gg']; + tourtypes[101] = 'kmp'; params['manual[players_coefficient]'] = parseFloat(form.zaw.value); params['manual[min_points]'] = parseInt(form['min' + (8-params.tournament_rank) + (params.over39_boards ? '_' : '')].value); params['manual[tournament_weight]'] = parseInt(form['r' + tourtypes[params.tournament_rank] + (params.over39_boards ? '_' : '')].value); @@ -188,7 +189,9 @@ function submitit(ev){ OTP: <input type="text" id="rok" name="rok" maxlength="3" style="width:30px" value="5"><br /> Regionalny: <input type="text" id="rtp" name="rtp" maxlength="3" style="width:30px" value="4"><br /> Okręgowy: <input type="text" id="rto" name="rto" maxlength="3" style="width:30px" value="2"><br /> - Klubowy: <input type="text" id="rtk" name="rtk" maxlength="3" style="width:30px" value="1"></td> + Klubowy: <input type="text" id="rtk" name="rtk" maxlength="3" style="width:30px" value="1"> + <input type="hidden" id="rkmp" name="rkmp" value="1"> + </td> <td align="left" rowspan="3"> <input type="text" id="min1" name="min1" maxlength="3" style="width:30px" value="200"><br /> <input type="text" id="min2" name="min2" maxlength="3" style="width:30px" value="150"><br /> @@ -197,7 +200,8 @@ function submitit(ev){ <input type="text" id="min5" name="min5" maxlength="3" style="width:30px" value="0"><br /> <input type="text" id="min6" name="min6" maxlength="3" style="width:30px" value="0"><br /> <input type="text" id="min7" name="min7" maxlength="3" style="width:30px" value="0"><br /> - <input type="text" id="min8" name="min8" maxlength="3" style="width:30px" value="0"></td> + <input type="text" id="min8" name="min8" maxlength="3" style="width:30px" value="0"> + <input type="hidden" id="min-93" name="min-93" value="0"></td> <td align="right" rowspan="3"> OTP<sup>∗∗∗∗</sup>: <input type="text" id="rgg_" name="rgg_" maxlength="3" style="width:30px" value="40"><br /> OTP<sup>∗∗∗</sup>: <input type="text" id="rgp_" name="rgp_" maxlength="3" style="width:30px" value="25"><br /> @@ -206,7 +210,9 @@ function submitit(ev){ OTP: <input type="text" id="rok_" name="rok_" maxlength="3" style="width:30px" value="7"><br /> Regionalny: <input type="text" id="rtp_" name="rtp_" maxlength="3" style="width:30px" value="5"><br /> Okręgowy: <input type="text" id="rto_" name="rto_" maxlength="3" style="width:30px" value="3"><br /> - Klubowy: <input type="text" id="rtk_" name="rtk_" maxlength="3" style="width:30px" value="2"></td> + Klubowy: <input type="text" id="rtk_" name="rtk_" maxlength="3" style="width:30px" value="2"> + <input type="hidden" id="rkmp_" name="rkmp_" value="1"> + </td> <td align="left" rowspan="3"> <input type="text" id="min1_" name="min1_" maxlength="3" style="width:30px" value="300"><br /> <input type="text" id="min2_" name="min2_" maxlength="3" style="width:30px" value="200"><br /> @@ -215,7 +221,8 @@ function submitit(ev){ <input type="text" id="min5_" name="min5_" maxlength="3" style="width:30px" value="0"><br /> <input type="text" id="min6_" name="min6_" maxlength="3" style="width:30px" value="0"><br /> <input type="text" id="min7_" name="min7_" maxlength="3" style="width:30px" value="0"><br /> - <input type="text" id="min8_" name="min8_" maxlength="3" style="width:30px" value="0"></td> + <input type="text" id="min8_" name="min8_" maxlength="3" style="width:30px" value="0"> + <input type="hidden" id="min-93_" name="min-93_" value="0"></td> <td align="left" valign="top"><input type="text" id="zaw" name="zaw" maxlength="5" style="width:30px" value="0.05"></td> <td valign="top" colspan="2">PKL za 1 m = <b>śr.WK×WAGA + il.zaw×WSP</b></td> </tr> @@ -239,6 +246,7 @@ function submitit(ev){ <input type="radio" name="rozdan" id="rozdan1" value="1"><label for="rozdan1"> od 40</label> </td> <td valign=top rowspan="2">RANGA ZAWODÓW<br /> + <input type="radio" name="rng" id="rg_kmp" value="-93"><label for="rg_kmp"> KMP</label><br /> <input type="radio" name="rng" id="rg1" value="1"><label for="rg1"> OTP<sup>∗∗∗∗</sup></label><br /> <input type="radio" name="rng" id="rg2" value="2"><label for="rg2"> OTP<sup>∗∗∗</sup></label><br /> <input type="radio" name="rng" id="rg3" value="3"><label for="rg3"> OTP<sup>∗∗</sup></label><br /> @@ -246,7 +254,8 @@ function submitit(ev){ <input type="radio" name="rng" id="rg5" value="5"><label for="rg5"> OTP</label><br /> <input type="radio" name="rng" id="rg6" value="6"><label for="rg6"> Regionalny</label><br /> <input type="radio" name="rng" id="rg7" value="7"><label for="rg7"> Okręgowy</label><br /> - <input type="radio" name="rng" id="rg8" value="8"><label for="rg8"> Klubowy</label></td> + <input type="radio" name="rng" id="rg8" value="8"><label for="rg8"> Klubowy</label> + </td> <td align="CENTER" valign=top>UCZESTNIKÓW<br /> <input type="text" id="iuc" name="iuc" maxlength="3" style="width:50px" onblur="valiuc(this,1)"><br /> <small>W zależności od typu<br />ilość indywidualistów,<br />par lub teamów</small></td> |