diff options
author | Michał Zimniewicz <michzimny@users.noreply.github.com> | 2020-01-12 00:20:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-12 00:20:42 +0100 |
commit | 072b1f73eeaf3769b97b6e5ba969c7e20b5701ff (patch) | |
tree | 651f881f07887f1aa69fc4525690bca259925591 /http | |
parent | 930ebda4087a149a4683bace48041a169fd900a3 (diff) | |
parent | 63fca7536a331b41d593c3ee7e40fa5999be94ed (diff) |
Merge pull request #4 from PZBS/kmp-2020
KMP 2020
Diffstat (limited to 'http')
-rw-r--r-- | http/api-inc.php | 220 | ||||
-rw-r--r-- | http/api.php | 207 | ||||
-rw-r--r-- | http/pkle.php | 2 | ||||
-rw-r--r-- | http/pkle2018.php | 1 | ||||
-rw-r--r-- | http/pkle2020.php | 298 |
5 files changed, 533 insertions, 195 deletions
diff --git a/http/api-inc.php b/http/api-inc.php new file mode 100644 index 0000000..64612d9 --- /dev/null +++ b/http/api-inc.php @@ -0,0 +1,220 @@ +<?php + +if (!function_exists('http_response_code')) { + function http_response_code($code = NULL) { + $codes = array(400 => "Bad Request", + 500 => "Internal Server Error"); + if (!isset($codes[$code])) { + return; + } + $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); + header($protocol . ' ' . $code . ' ' . $codes[$code]); + } +} + +function safe_ceil($value, $precision = 1e-6) { + $ceilValue = ceil($value); + return (abs($value - $ceilValue) < (1-$precision)) ? $ceilValue : round($value); +} + +function recursive_ksort(&$array, $flags = SORT_REGULAR) { + if (!is_array($array)) return false; + ksort($array, $flags); + foreach ($array as &$arr) { + recursive_ksort($arr, $flags); + } + return true; +} + +class ParametersException extends Exception {}; + +class ApiPkl { + + const RANK_KMP = 101; + + protected $parameters; + + function __construct($parameters) { + $this->parameters = $parameters; + $this->check_parameters($parameters); + $this->parameters = $this->parse_parameters($parameters); + } + + function ensure_parameters($params) { + foreach ($params as $param) { + if (!isset($this->parameters[$param])) { + throw new ParametersException('Missing parameter: ' . $param); + } + if (!is_numeric($this->parameters[$param])) { + throw new ParametersException('Parameter: ' . $param . ' is not a numeric value (' . $this->parameters[$param] . ')'); + } + } + } + + function check_values($parameters, $params) { + foreach ($params as $param => $test) { + if (!$test($parameters[$param])) { + throw new ParametersException('Parameter: ' . $param . ' has incorrect value (' . $parameters[$param] . ')'); + } + } + } + + function check_parameters() { + $this->ensure_parameters(array('type', 'contestants', 'title_sum')); + $this->check_values($this->parameters, array( + 'type' => function($r) { return ctype_digit($r) && intval($r) > 0; }, + 'contestants' => function($r) { return ctype_digit($r) && intval($r) > 0; }, + 'title_sum' => function($r) { return floatval($r) >= 0; } + )); + if (isset($this->parameters['players'])) { + $this->check_values($this->parameters, array( + 'players' => function($r) { return ctype_digit($r) && intval($r) > 0; } + )); + } + if (!isset($this->parameters['manual']) || !isset($this->parameters['manual']['min_points']) || !isset($this->parameters['manual']['tournament_weight'])) { + $this->ensure_parameters(array('tournament_rank', 'over39_boards')); + $this->check_values($this->parameters, array( + 'tournament_rank' => function($r) { return ctype_digit($r) && ((intval($r) >= 0 && intval($r) <= 7) || intval($r) == self::RANK_KMP); }, + 'over39_boards' => function($r) { return ctype_digit($r) && intval($r) >= 0 && intval($r) <= 1; } + )); + } else { + $this->check_values($this->parameters['manual'], array( + 'min_points' => function($r) { return ctype_digit($r) && intval($r) >= 0; }, + 'tournament_weight' => function($r) { return ctype_digit($r) && intval($r) > 0; } + )); + } + if (isset($this->parameters['manual']) && isset($this->parameters['manual']['players_coefficient'])) { + $this->check_values($this->parameters['manual'], array( + 'players_coefficient' => function($r) { return floatval($r) >= 0; } + )); + } + } + + function parse_parameters() { + $return = array(); + $return['type'] = intval($this->parameters['type']); + if ($return['type'] == 3 || $return['type'] > 4) { + throw new ParametersException('Parameter: type has incorrect value (' . $return['type'] . ')'); + } + if ($return['type'] != 2 && $this->parameters['tournament_rank'] == self::RANK_KMP) { + throw new ParametersException('Parameter: type has incorrect value (' . $return['type'] . ') for KMP tournament'); + } + $return['contestants'] = intval($this->parameters['contestants']); + $return['players'] = isset($this->parameters['players']) ? intval($this->parameters['players']) : intval($this->parameters['contestants']) * $return['type']; + $return['title_sum'] = floatval($this->parameters['title_sum']); + $weights = array( + array(1, 2, 4, 5, 7, 10, 15, 25, self::RANK_KMP => 0), + array(2, 3, 5, 7, 10, 15, 25, 40, self::RANK_KMP => 0) + ); + $return['tournament_weight'] = (isset($this->parameters['manual']) && isset($this->parameters['manual']['tournament_weight'])) ? intval($this->parameters['manual']['tournament_weight']) : $weights[intval($this->parameters['over39_boards'])][intval($this->parameters['tournament_rank'])]; + $min_points = array( + array(0, 0, 0, 0, 50, 75, 150, 200, self::RANK_KMP => 0), + array(0, 0, 0, 0, 70, 100, 200, 300, self::RANK_KMP => 0) + ); + $return['min_points'] = (isset($this->parameters['manual']) && isset($this->parameters['manual']['min_points'])) ? intval($this->parameters['manual']['min_points']) : $min_points[intval($this->parameters['over39_boards'])][intval($this->parameters['tournament_rank'])]; + $return['players_coefficient'] = (isset($this->parameters['manual']) && isset($this->parameters['manual']['players_coefficient'])) ? floatval($this->parameters['manual']['players_coefficient']) : 0.05; + $return['points_cutoffs'] = (isset($this->parameters['manual']) && isset($this->parameters['manual']['points_cutoffs']) && is_array($this->parameters['manual']['points_cutoffs'])) ? $this->parameters['manual']['points_cutoffs'] : array( + array(0.0, 1.0), + array(0.02, 0.9), + array(0.2, 0.2), + array(0.5, 0.0) + ); + recursive_ksort($return['points_cutoffs']); + if ($return['points_cutoffs'][0][0] != 0.0) { + array_unshift($return['points_cutoffs'], array(0.0, 1.0)); + } + if ($return['points_cutoffs'][count($return['points_cutoffs'])-1][1] != 0.0) { + array_push($return['points_cutoffs'], array(1.0, 0.0)); + } + foreach ($return['points_cutoffs'] as &$cutoff) { + if (($cutoff[0] < 0.0) || ($cutoff[0] > 1.0)) { + throw new ParametersException('Cutoff points need to be between 0.0 and 1.0: ' . $cutoff[0]); + } + $cutoff[0] = floatval($cutoff[0]); + if (($cutoff[1] < 0.0) || ($cutoff[1] > 1.0)) { + throw new ParametersException('Cutoff values need to be between 1.0 and 0.0: ' . $cutoff[1]); + } + $cutoff[1] = floatval($cutoff[1]); + } + unset($cutoff); + for ($prev = 0; $prev < count($return['points_cutoffs']) - 1; $prev++) { + $next = $prev + 1; + if ($return['points_cutoffs'][$prev][0] >= $return['points_cutoffs'][$next][0]) { + throw new ParametersException( + 'Cutoff points need to be ascending: ' . $return['points_cutoffs'][$prev][0] . ', ' . $return['points_cutoffs'][$next][0]); + } + if ($return['points_cutoffs'][$prev][1] < $return['points_cutoffs'][$next][1]) { + throw new ParametersException( + 'Cutoff values need to be non-ascending: ' . $return['points_cutoffs'][$prev][1] . ', ' . $return['points_cutoffs'][$next][1]); + } + } + return $return; + } + + function get_position_percentage_from_position($position, $contestants) { + return ($position - 1) / $contestants; + } + + function get_percentage_from_position($position, $contestants, $cutoffs) { + $position_percentage = $this->get_position_percentage_from_position($position, $contestants); + for ($prev = 0; $prev < count($cutoffs) - 1; $prev++) { + $next = $prev + 1; + if (($cutoffs[$prev][0] <= $position_percentage) && ($cutoffs[$next][0] >= $position_percentage)) { + $result = ($position_percentage - $cutoffs[$prev][0]) * ($cutoffs[$prev][1] - $cutoffs[$next][1]) / ($cutoffs[$prev][0] - $cutoffs[$next][0]) + $cutoffs[$prev][1]; + return $result; + } + } + return 0.0; + } + + function calculate_points() { + $max_points = safe_ceil(max( + $this->parameters['min_points'], + (1 + 0.25 * ($this->parameters['type'] > 2)) * (max(0.15, $this->parameters['title_sum'] / $this->parameters['players']) * $this->parameters['tournament_weight'] + $this->parameters['players_coefficient'] * $this->parameters['contestants'] * $this->parameters['type']) + )); + $min_points = 1; + $result = array("sum" => 0, "points" => array()); + for ($place = 1; $place <= $this->parameters['contestants']; $place++) { + $percentage = $this->get_percentage_from_position($place, $this->parameters['contestants'], $this->parameters['points_cutoffs']); + $points = safe_ceil(floatval($max_points) * $percentage); + $result['points'][$place] = max($min_points, intval($points)); + $result['sum'] += $this->parameters['type'] * $result['points'][$place]; + } + return $result; + } + + function calculate_kmp_points() { + $max_points = safe_ceil($this->parameters['contestants'] * 0.5); + $min_points = 1; + $result = array("sum" => 0, "points" => array(1 => $max_points)); + for ($place = 2; $place <= $this->parameters['contestants']; $place++) { + $result['points'][$place] = max($min_points, $result['points'][$place-1]-1); + $result['sum'] += $this->parameters['type'] * $result['points'][$place]; + } + if ($this->parameters['title_sum'] / $this->parameters['players'] >= 2.5) { + $result['points'][1] += 5; + $result['points'][2] += 3; + $result['points'][3] += 1; + $result['sum'] += $this->parameters['type'] * 8; + } + return $result; + } +} + +class ApiPklV1 extends ApiPkl {} + +class ApiPklV2 extends ApiPklV1 { + + function calculate_kmp_points() { + // the line below works only because you can't play > 39 boards in KMP + // please kill me if it ever changes + $this->parameters['tournament_weight'] = 4; + $this->parameters['min_points'] = 0; + $intermediate = $this->calculate_points(); + $this->parameters['min_points'] = $intermediate['points'][1] + 10; + return $this->calculate_points(); + } + +} + +?> diff --git a/http/api.php b/http/api.php index 3ab7f3d..acf2752 100644 --- a/http/api.php +++ b/http/api.php @@ -28,204 +28,23 @@ Parametry: */ -if (!function_exists('http_response_code')) { - function http_response_code($code = NULL) { - $codes = array(400 => "Bad Request", - 500 => "Internal Server Error"); - if (!isset($codes[$code])) { - return; - } - $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); - header($protocol . ' ' . $code . ' ' . $codes[$code]); - } -} - -class ParametersException extends Exception {}; - -function safe_ceil($value, $precision = 1e-6) { - $ceilValue = ceil($value); - return (abs($value - $ceilValue) < (1-$precision)) ? $ceilValue : round($value); -} - -function recursive_ksort(&$array, $flags = SORT_REGULAR) { - if (!is_array($array)) return false; - ksort($array, $flags); - foreach ($array as &$arr) { - recursive_ksort($arr, $flags); - } - return true; -} - -function ensure_parameters($parameters, $params) { - foreach ($params as $param) { - if (!isset($parameters[$param])) { - throw new ParametersException('Missing parameter: ' . $param); - } - if (!is_numeric($parameters[$param])) { - throw new ParametersException('Parameter: ' . $param . ' is not a numeric value (' . $parameters[$param] . ')'); - } - } -} - -function check_values($parameters, $params) { - foreach ($params as $param => $test) { - if (!$test($parameters[$param])) { - throw new ParametersException('Parameter: ' . $param . ' has incorrect value (' . $parameters[$param] . ')'); - } - } -} - -function check_parameters($parameters) { - ensure_parameters($parameters, array('type', 'contestants', 'title_sum')); - check_values($parameters, array( - 'type' => function($r) { return ctype_digit($r) && intval($r) > 0; }, - 'contestants' => function($r) { return ctype_digit($r) && intval($r) > 0; }, - 'title_sum' => function($r) { return floatval($r) >= 0; } - )); - if (isset($parameters['players'])) { - check_values($parameters, array( - 'players' => function($r) { return ctype_digit($r) && intval($r) > 0; } - )); - } - 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) || intval($r) == RANK_KMP); }, - 'over39_boards' => function($r) { return ctype_digit($r) && intval($r) >= 0 && intval($r) <= 1; } - )); - } else { - check_values($parameters['manual'], array( - 'min_points' => function($r) { return ctype_digit($r) && intval($r) >= 0; }, - 'tournament_weight' => function($r) { return ctype_digit($r) && intval($r) > 0; } - )); - } - if (isset($parameters['manual']) && isset($parameters['manual']['players_coefficient'])) { - check_values($parameters['manual'], array( - 'players_coefficient' => function($r) { return floatval($r) >= 0; } - )); - } -} - -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, 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, 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; - $return['points_cutoffs'] = (isset($parameters['manual']) && isset($parameters['manual']['points_cutoffs']) && is_array($parameters['manual']['points_cutoffs'])) ? $parameters['manual']['points_cutoffs'] : array( - array(0.0, 1.0), - array(0.02, 0.9), - array(0.2, 0.2), - array(0.5, 0.0) - ); - recursive_ksort($return['points_cutoffs']); - if ($return['points_cutoffs'][0][0] != 0.0) { - array_unshift($return['points_cutoffs'], array(0.0, 1.0)); - } - if ($return['points_cutoffs'][count($return['points_cutoffs'])-1][1] != 0.0) { - array_push($return['points_cutoffs'], array(1.0, 0.0)); - } - foreach ($return['points_cutoffs'] as &$cutoff) { - if (($cutoff[0] < 0.0) || ($cutoff[0] > 1.0)) { - throw new ParametersException('Cutoff points need to be between 0.0 and 1.0: ' . $cutoff[0]); - } - $cutoff[0] = floatval($cutoff[0]); - if (($cutoff[1] < 0.0) || ($cutoff[1] > 1.0)) { - throw new ParametersException('Cutoff values need to be between 1.0 and 0.0: ' . $cutoff[1]); - } - $cutoff[1] = floatval($cutoff[1]); - } - unset($cutoff); - for ($prev = 0; $prev < count($return['points_cutoffs']) - 1; $prev++) { - $next = $prev + 1; - if ($return['points_cutoffs'][$prev][0] >= $return['points_cutoffs'][$next][0]) { - throw new ParametersException( - 'Cutoff points need to be ascending: ' . $return['points_cutoffs'][$prev][0] . ', ' . $return['points_cutoffs'][$next][0]); - } - if ($return['points_cutoffs'][$prev][1] < $return['points_cutoffs'][$next][1]) { - throw new ParametersException( - 'Cutoff values need to be non-ascending: ' . $return['points_cutoffs'][$prev][1] . ', ' . $return['points_cutoffs'][$next][1]); - } - } - return $return; -} - -function get_position_percentage_from_position($position, $contestants) { - return ($position - 1) / $contestants; -} - -function get_percentage_from_position($position, $contestants, $cutoffs) { - $position_percentage = get_position_percentage_from_position($position, $contestants); - for ($prev = 0; $prev < count($cutoffs) - 1; $prev++) { - $next = $prev + 1; - if (($cutoffs[$prev][0] <= $position_percentage) && ($cutoffs[$next][0] >= $position_percentage)) { - $result = ($position_percentage - $cutoffs[$prev][0]) * ($cutoffs[$prev][1] - $cutoffs[$next][1]) / ($cutoffs[$prev][0] - $cutoffs[$next][0]) + $cutoffs[$prev][1]; - return $result; - } - } - return 0.0; -} - -function calculate_points($parameters) { - $max_points = safe_ceil(max( - $parameters['min_points'], - (1 + 0.25 * ($parameters['type'] > 2)) * (max(0.15, $parameters['title_sum'] / $parameters['players']) * $parameters['tournament_weight'] + $parameters['players_coefficient'] * $parameters['contestants'] * $parameters['type']) - )); - $min_points = 1; - $result = array("sum" => 0, "points" => array()); - for ($place = 1; $place <= $parameters['contestants']; $place++) { - $percentage = get_percentage_from_position($place, $parameters['contestants'], $parameters['points_cutoffs']); - $points = safe_ceil(floatval($max_points) * $percentage); - $result['points'][$place] = max($min_points, intval($points)); - $result['sum'] += $parameters['type'] * $result['points'][$place]; - } - 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; -} +require_once('api-inc.php'); function run($parameters) { + try { - check_parameters($parameters); - $params = parse_parameters($parameters); - if ($parameters['tournament_rank'] == RANK_KMP) { - $result = calculate_kmp_points($params); + $versionClasses = array( + '1' => 'ApiPklV1', // RegKlas 2018.11.01 + '2' => 'ApiPklV2', // RegKMP 2020.01.01 + '_default' => 'ApiPklV2' + ); + $version = isset($parameters['version']) ? $parameters['version'] : '_default'; + $apiClass = isset($versionClasses[$version]) ? $versionClasses[$version] : $versionClasses['_default']; + $api = new $apiClass($parameters); + if ($parameters['tournament_rank'] == ApiPkl::RANK_KMP) { + $result = $api->calculate_kmp_points(); } else { - $result = calculate_points($params); + $result = $api->calculate_points(); } return $result; } diff --git a/http/pkle.php b/http/pkle.php index 8159e28..0bc46be 100644 --- a/http/pkle.php +++ b/http/pkle.php @@ -1,3 +1,3 @@ <?php -Header('location: pkle2018.php'); +Header('location: pkle2020.php'); die(); diff --git a/http/pkle2018.php b/http/pkle2018.php index 4ea16f4..cbcc9a7 100644 --- a/http/pkle2018.php +++ b/http/pkle2018.php @@ -82,6 +82,7 @@ function display() { function sendit(form) { var params = { + version: '1', // 2018.11.01 version type: parseInt(form.typ.value), contestants: parseInt(form.iuc.value), players: parseInt(form.izw.value), diff --git a/http/pkle2020.php b/http/pkle2020.php new file mode 100644 index 0000000..8f350d6 --- /dev/null +++ b/http/pkle2020.php @@ -0,0 +1,298 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> + <head> + <meta http-equiv="pragma" content="no-cache"> + <meta http-equiv="cache-control" content="no-cache"> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <title>Kargulator PKLi</title> + <link rel="stylesheet" href="style.css" type="text/css"> + <link rel="icon" href="images/favicon.ico" type="image/x-icon"> + <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"> + <script type="text/javascript"> + <!-- +function valiuc(x,y){ + if( !(x.value==null || x.value=='') ){ + x.value = x.value.replace(',','.'); + if( isFinite(x.value)){ + if( y==1 ){ + if( document.getElementsByName("typ")[0].checked ){ + document.getElementById("izw").value = x.value; + } else { + if( document.getElementsByName("typ")[1].checked ){ + document.getElementById("izw").value = 2 * x.value; + } else { + if( document.getElementsByName("typ")[2].checked ){ + document.getElementById("izw").value = 4 * x.value; + } + } + } + } + if( y>=2 ){ + if (y==2) x = document.getElementById("swk"); + var z = document.getElementById('izw'); + var srednieWk = x.value/z.value; + if(srednieWk < 0.15) srednieWk = 0.15; + document.getElementById('srd').value = srednieWk; + } + return true; + } else { + alert(x.value+' to nie liczba!'); + x.select(); + x.focus(); + return false; + } + } +} + +function typtur(x){ + var t = document.getElementById("iuc"); + var z = document.getElementById("izw"); + if( t.value!=null && t.value!='' && isFinite(t.value) ){ + z.value = x * t.value; + } + document.getElementById('izw').readOnly = (x < 4); +} + +function loader(show) { + document.getElementById("loader").style.display = show ? 'block' : 'none'; + document.getElementById("sqlbuttons").style.display = show ? 'none' : 'block'; + document.getElementById("pkltablebox").style.display = show ? 'none' : 'block'; +} + +function display() { + if (this.status != 200) { + alert(this.responseText); + } else { + var response = JSON.parse(this.responseText); + var sqlPary = ['UPDATE `dodatki` SET `pkl` = 0;']; + var sqlTeamy = ['UPDATE `addons` SET `mastr` = 0;']; + var pklHTML = ['<tr><td class="t">Miejsce</td><td class="t"> PKL </td></tr>']; + for (var place = 1; place <= parseInt(document.getElementsByName('iuc')[0].value); place++) { + sqlPary.push('UPDATE `dodatki` SET `pkl` = ' + response.points[place] + ' WHERE `miejsce` = ' + place + ';'); + sqlTeamy.push('UPDATE `addons` SET `mastr` = ' + response.points[place] + ' WHERE `place` = ' + place + ';'); + pklHTML.push('<tr><td class="t">' + place + '</td><td class="t">' + response.points[place] + '</td></tr>'); + } + pklHTML.push('<tr><td class="p">SUMA PKL</td><td class="t">' + response.sum + '</td></tr>'); + document.getElementById('outsql').innerHTML = sqlPary.join("\n"); + document.getElementById('outsql2').innerHTML = sqlTeamy.join("\n"); + document.getElementById("pkltable").innerHTML = pklHTML.join(""); + } + loader(false); +} + +function sendit(form) { + var params = { + type: parseInt(form.typ.value), + contestants: parseInt(form.iuc.value), + players: parseInt(form.izw.value), + title_sum: parseFloat(form.swk.value), + tournament_rank: 8-form.rng.value, + 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); + for (var i = 0; i < 2; i++) { + params['manual[points_cutoffs]['+i+'][0]'] = parseFloat(form['pru'+(i+1)].value) / 100; + params['manual[points_cutoffs]['+i+'][1]'] = parseFloat(form['prp'+(i+1)].value) / 100; + } + params['manual[points_cutoffs][2][0]'] = parseFloat(form.pru3.value) / 100; + params['manual[points_cutoffs][2][1]'] = 0; + var paramString = []; + for (var param in params) { + paramString.push(param + '=' + params[param]); + } + loader(true); + var xhr = new XMLHttpRequest(); + xhr.addEventListener('load', display); + xhr.open('POST', 'api.php', true); + xhr.setRequestHeader("Content-Type", 'application/x-www-form-urlencoded'); + xhr.send(paramString.join('&')); +} + +function submitit(ev){ + if( document.getElementsByName("typ")[0].checked || + document.getElementsByName("typ")[1].checked || + document.getElementsByName("typ")[2].checked ){ + if( document.getElementsByName("rng")[0].checked || + document.getElementsByName("rng")[1].checked || + document.getElementsByName("rng")[2].checked || + document.getElementsByName("rng")[3].checked || + document.getElementsByName("rng")[4].checked || + document.getElementsByName("rng")[5].checked || + document.getElementsByName("rng")[6].checked || + document.getElementsByName("rng")[7].checked || + document.getElementsByName("rng")[8].checked || + document.getElementsByName("rng")[9].checked ){ + var t = document.getElementById("iuc") + if( t.value!=null && t.value!='' && isFinite(t.value) ){ + t = document.getElementById("izw"); + if( t.value!=null && t.value!='' && isFinite(t.value) ){ + t = document.getElementById("swk"); + if( t.value!=null && t.value!='' && isFinite(t.value) ){ + sendit(ev); + } else { + alert('Brak sumy WK!'); + t.select(); + } + } else { + alert('Brak liczby zawodników!'); + t.select(); + } + } else { + alert('Brak liczby uczestników!'); + t.select(); + } + } else { + alert('Wybierz rangę turnieju'); + document.getElementsByName("rng")[0].select(); + } + } else { + alert('Wybierz typ turnieju'); + document.getElementsByName("typ")[0].select(); + } +} + --> + </script> + </head> + <body style="background-color: #F0F0F0; background-image: none"> + <form id="pkl"> + <table border="0" cellspacing="0" cellpadding="0"> + <tr> + <td><img src="images/logo_pzbs.gif"></td> + <td colspan="3" align="center"><h3>KALKULATOR PKLI W TURNIEJACH PZBS<br> + zgodny z <span style="color:#d00">nowym regulaminem (obowiązującym od 01.11.2018)</span><br> + oraz <span style="color:#d00">nowym regulaminem KMP (obowiązującym od 01.01.2020)</span></h3> + Przejdź do <a href="pkle2018.php"><b>kalkulatora zgodnego ze starym regulaminem KMP</b></a>! + <br><br> + Możesz eksperymentować ze wszystkimi (prawie) parametrami.<br> + Dla przywrócenia stanu regulaminowego otwórz ponownie stronę.</td> + <td><img src="images/logo_pzbs.gif"></td> + </tr> + <tr><td colspan="5"> </td></tr> + <tr> + <td align="center" colspan="2"><b>turniej do 39 rozdań</b></td> + <td align="center" colspan="2"><b>turniej od 40 rozdań</b></td> + </tr> + <tr> + <td align="right">WAGA<br>turnieju</td><td align="left">MINIMUM<br>za 1sze miejsce</td> + <td align="right">WAGA<br>turnieju</td><td align="left">MINIMUM<br>za 1sze miejsce</td> + <td align="left" colspan="3">WSP:</td> + </tr> + <tr> + <td align="right" rowspan="3"> + OTP<sup>∗∗∗∗</sup>: <input type="text" id="rgg" name="rgg" maxlength="3" style="width:30px" value="25"><br /> + OTP<sup>∗∗∗</sup>: <input type="text" id="rgp" name="rgp" maxlength="3" style="width:30px" value="15"><br /> + OTP<sup>∗∗</sup>: <input type="text" id="rot" name="rot" maxlength="3" style="width:30px" value="10"><br /> + OTP<sup>∗</sup>: <input type="text" id="rok1" name="rok1" maxlength="3" style="width:30px" value="7"><br /> + 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"> + <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 /> + <input type="text" id="min3" name="min3" maxlength="3" style="width:30px" value="75"><br /> + <input type="text" id="min4" name="min4" maxlength="3" style="width:30px" value="50"><br /> + <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"> + <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 /> + OTP<sup>∗∗</sup>: <input type="text" id="rot_" name="rot_" maxlength="3" style="width:30px" value="15"><br /> + OTP<sup>∗</sup>: <input type="text" id="rok1_" name="rok1_" maxlength="3" style="width:30px" value="10"><br /> + 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"> + <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 /> + <input type="text" id="min3_" name="min3_" maxlength="3" style="width:30px" value="100"><br /> + <input type="text" id="min4_" name="min4_" maxlength="3" style="width:30px" value="70"><br /> + <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"> + <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> + <tr> + <td align="right" valign="top"><br /><br /><br /><br /><input type="text" id="prp1" name="prp1" style="width:18px" value="90">%<br /><input type="text" id="prp2" name="prp2" style="width:18px" value="20">%</td> + <td colspan="2" align="left"><img src="images/pkle.png"></td> + </tr> + <tr> + <td> </td> + <td colspan="2"><table cellspacing="0" cellpadding="0"><tr><td align="right" style="width:50px"><input type="text" id="pru1" name="pru1" style="width:18px" value="2">%</td><td align="right" style="width:25px"><input type="text" id="pru2" name="pru2" style="width:18px" value="20">%</td><td align="right" style="width:55px"><input type="text" id="pru3" name="pru3" style="width:18px" value="50">%</td></tr></table></td> + </tr> + + <tr><td colspan="5"> </td></tr> + <tr> + <td valign=top rowspan="2">TYP ZAWODÓW<br /> + <input type="radio" name="typ" id="tp1" value="1" onclick="typtur(1)"><label for="tp1"> Indywiduel</label><br /> + <input type="radio" name="typ" id="tp2" value="2" onclick="typtur(2)"><label for="tp2"> Pary</label><br /> + <input type="radio" name="typ" id="tp3" value="4" onclick="typtur(4)"><label for="tp3"> Teamy</label> + <br><br>LICZBA ROZDAŃ<br> + <input type="radio" name="rozdan" id="rozdan0" value="0"><label for="rozdan0"> do 39</label><br /> + <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 /> + <input type="radio" name="rng" id="rg4" value="4"><label for="rg4"> OTP<sup>∗</sup></label><br /> + <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> + <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> + <td align="CENTER" valign=top>ZAWODNIKÓW<br /> + <input type="text" id="izw" name="izw" readonly="readonly" maxlength="4" style="width:50px" onblur="valiuc(this,2)"><br /> + <small>To pole jest wyliczane<br />automatycznie, ale możesz poprawić je<br />dla teamów nieczterosobowych.</small></td> + <td align="CENTER" valign=top>SUMA WK<br /> + <input type="text" id="swk" name="swk" maxlength="7" style="width:70px" onblur="valiuc(this,3)"><br /> + <small>Suma WK wszystkich<br />zawodników.</small></td> + </tr> + <tr> + <td align="CENTER" colspan="3">Średnie WK zawodnika w turnieju: + <input type="text" id="srd" name="srd" readonly="readonly"><br /> + </td> + </tr> + <tr><td colspan="5"> </td></tr> + <tr> + <td align="CENTER" colspan="2"> + <input type="button" value="Policz PKLe" onclick="submitit(this.form)"></td> + <td colspan="3"> + <div id="sqlbuttons"> + <input type="button" value="SQL dla JFR Pary" onclick="document.getElementById('outsql').style.display=(document.getElementById('outsql').style.display=='none') ? 'block' : 'none';document.getElementById('outsql2').style.display='none'"><input type="button" value="SQL dla JFR Teamy" onclick="document.getElementById('outsql2').style.display=(document.getElementById('outsql2').style.display=='none') ? 'block' : 'none';document.getElementById('outsql').style.display='none'"> + </div> + </td> + </tr> + <tr><td colspan="2" align="center"> + <div id="pkltablebox"> + <table id="pkltable"><tr><td class="t">Miejsce</td><td class="t"> PKL </td></tr> + <tr><td class="p">SUMA PKL</td><td class="t"></td></tr> + </table> + </div> + </td><td colspan="3" valign="top"><pre id="outsql" style="display: none"></pre></td> + <td colspan="3" valign="top"><pre id="outsql2" style="display: none"></pre></td></tr> + <tr><td colspan="5" class="copyright">©'2009, Jan Romański dla PZBS</td></tr> + </table> + </form> + <div id="loader">Cierpliwości, liczę...</div> + </body> +</html> |