From eaa70b734619af7dfbc316642c1a17c623ad6e1f Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 13 May 2020 18:06:52 +0200 Subject: API call reusable --- http/api-inc.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'http/api-inc.php') diff --git a/http/api-inc.php b/http/api-inc.php index 565e66c..96c9ca7 100644 --- a/http/api-inc.php +++ b/http/api-inc.php @@ -28,6 +28,23 @@ function recursive_ksort(&$array, $flags = SORT_REGULAR) { class ParametersException extends Exception {}; +function run($parameters) { + $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 = $api->calculate_points(); + } + return $result; +} + class ApiPkl { const RANK_KMP = 101; -- cgit v1.2.3 From a99cc025c68f4e1d7df0a20db8f2fe80cd19ce71 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 13 May 2020 18:10:12 +0200 Subject: New API version --- http/api-inc.php | 5 +- http/index.php | 2 +- http/pkle.php | 2 +- http/pkle2020a.php | 299 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 305 insertions(+), 3 deletions(-) create mode 100644 http/pkle2020a.php (limited to 'http/api-inc.php') diff --git a/http/api-inc.php b/http/api-inc.php index 96c9ca7..c2336af 100644 --- a/http/api-inc.php +++ b/http/api-inc.php @@ -32,7 +32,8 @@ function run($parameters) { $versionClasses = array( '1' => 'ApiPklV1', // RegKlas 2018.11.01 '2' => 'ApiPklV2', // RegKMP 2020.01.01 - '_default' => 'ApiPklV2' + '3' => 'ApiPklV3', // local BNET 2020.05.01 + '_default' => 'ApiPklV3' ); $version = isset($parameters['version']) ? $parameters['version'] : '_default'; $apiClass = isset($versionClasses[$version]) ? $versionClasses[$version] : $versionClasses['_default']; @@ -234,4 +235,6 @@ class ApiPklV2 extends ApiPklV1 { } +class ApiPklV3 extends ApiPklV2 {} + ?> diff --git a/http/index.php b/http/index.php index 0bc46be..13594c7 100644 --- a/http/index.php +++ b/http/index.php @@ -1,3 +1,3 @@ + + + + + + Kargulator PKLi + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

KALKULATOR PKLI W TURNIEJACH PZBS
+ zgodny z nowym regulaminem (obowiązującym od 01.11.2018)
+ oraz nowym regulaminem KMP (obowiązującym od 01.01.2020)

+ Przejdź do kalkulatora zgodnego ze starym regulaminem KMP! +

+ Możesz eksperymentować ze wszystkimi (prawie) parametrami.
+ Dla przywrócenia stanu regulaminowego otwórz ponownie stronę.
 
turniej do 39 rozdańturniej od 40 rozdań
WAGA
turnieju
MINIMUM
za 1sze miejsce
WAGA
turnieju
MINIMUM
za 1sze miejsce
WSP:
+ OTP∗∗∗∗:
+ OTP∗∗∗:
+ OTP∗∗:
+ OTP:
+ OTP:
+ Regionalny:
+ Okręgowy:
+ Klubowy: + +
+
+
+
+
+
+
+
+ +
+ OTP∗∗∗∗:
+ OTP∗∗∗:
+ OTP∗∗:
+ OTP:
+ OTP:
+ Regionalny:
+ Okręgowy:
+ Klubowy: + +
+
+
+
+
+
+
+
+ +
PKL za 1 m = śr.WK×WAGA + il.zaw×WSP




%
%
 
%%%
 
TYP ZAWODÓW
+
+
+ +

LICZBA ROZDAŃ
+
+ +
RANGA ZAWODÓW
+
+
+
+
+
+
+
+
+ +
UCZESTNIKÓW
+
+ W zależności od typu
ilość indywidualistów,
par lub teamów
ZAWODNIKÓW
+
+ To pole jest wyliczane
automatycznie, ale możesz poprawić je
dla teamów nieczterosobowych.
SUMA WK
+
+ Suma WK wszystkich
zawodników.
Średnie WK zawodnika w turnieju:  +
+
 
+ +
+ +
+
+
+ + +
Miejsce   PKL   
SUMA PKL
+
+
+
+
Cierpliwości, liczę...
+ + -- cgit v1.2.3 From b6cc0b7cf36820b6b31276468b05f00ca4b4ad4f Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 14 May 2020 00:24:46 +0200 Subject: Boards count instead of over/under parameter --- http/api-inc.php | 16 +++++++++++++++- test/ApiTest.php | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'http/api-inc.php') diff --git a/http/api-inc.php b/http/api-inc.php index c2336af..9cac20e 100644 --- a/http/api-inc.php +++ b/http/api-inc.php @@ -235,6 +235,20 @@ class ApiPklV2 extends ApiPklV1 { } -class ApiPklV3 extends ApiPklV2 {} +class ApiPklV3 extends ApiPklV2 { + + function check_parameters() { + if (!isset($this->parameters['manual']) || !isset($this->parameters['manual']['min_points']) || !isset($this->parameters['manual']['tournament_weight'])) { + if (isset($this->parameters['boards'])) { + $this->check_values($this->parameters, array( + 'boards' => function($r) { return ctype_digit($r); } + )); + $this->parameters['over39_boards'] = strval(intval($this->parameters['boards'] > 39)); + } + } + return parent::check_parameters(); + } + +} ?> diff --git a/test/ApiTest.php b/test/ApiTest.php index 93ed024..158c9dc 100644 --- a/test/ApiTest.php +++ b/test/ApiTest.php @@ -18,6 +18,15 @@ class ApiTest extends TestCase { } } + /** + * @dataProvider generatedDataProvider + */ + public function testBoardCounts($input, $expected) { + $input['boards'] = strval($input['over39_boards'] ? rand(40, 60) : rand(1, 39)); + unset($input['over39_boards']); + $this->testRandomResults($input, $expected); + } + public function generatedDataProvider() { $contents = file(dirname(__FILE__) . '/tests.txt'); $count = count($contents) / 2; -- cgit v1.2.3 From a5b1d76774850d86e41ed34e41e3c3269d4bf210 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 14 May 2020 01:00:03 +0200 Subject: Local B***eNET points --- http/api-inc.php | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'http/api-inc.php') diff --git a/http/api-inc.php b/http/api-inc.php index 9cac20e..fc0d48e 100644 --- a/http/api-inc.php +++ b/http/api-inc.php @@ -40,6 +40,8 @@ function run($parameters) { $api = new $apiClass($parameters); if ($parameters['tournament_rank'] == ApiPkl::RANK_KMP) { $result = $api->calculate_kmp_points(); + } else if ($parameters['tournament_rank'] == ApiPkl::RANK_BNET) { + $result = $api->calculate_bridgenet_points(); } else { $result = $api->calculate_points(); } @@ -49,6 +51,7 @@ function run($parameters) { class ApiPkl { const RANK_KMP = 101; + const RANK_BNET = 102; protected $parameters; @@ -92,7 +95,7 @@ class ApiPkl { 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) == ApiPkl::RANK_KMP); }, + 'tournament_rank' => function($r) { return ctype_digit($r) && ((intval($r) >= 0 && intval($r) <= 7) || in_array(intval($r), array(ApiPkl::RANK_KMP, ApiPkl::RANK_BNET))); }, 'over39_boards' => function($r) { return ctype_digit($r) && intval($r) >= 0 && intval($r) <= 1; } )); } else { @@ -121,13 +124,13 @@ class ApiPkl { $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, ApiPkl::RANK_KMP => 0), - array(2, 3, 5, 7, 10, 15, 25, 40, ApiPkl::RANK_KMP => 0) + array(1, 2, 4, 5, 7, 10, 15, 25, ApiPkl::RANK_KMP => 0, ApiPkl::RANK_BNET => 1), + array(2, 3, 5, 7, 10, 15, 25, 40, ApiPkl::RANK_KMP => 0, ApiPkl::RANK_BNET => 1) // not 2, according to MarcinW ); $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, ApiPkl::RANK_KMP => 0), - array(0, 0, 0, 0, 70, 100, 200, 300, ApiPkl::RANK_KMP => 0) + array(0, 0, 0, 0, 50, 75, 150, 200, ApiPkl::RANK_KMP => 0, ApiPkl::RANK_BNET => 0), + array(0, 0, 0, 0, 70, 100, 200, 300, ApiPkl::RANK_KMP => 0, ApiPkl::RANK_BNET => 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; @@ -185,16 +188,15 @@ class ApiPkl { return 0.0; } - function calculate_points() { + function calculate_points($min_points=1, $scale_factor=1.0) { $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); + $points = safe_ceil(floatval($max_points) * $percentage * $scale_factor); $result['points'][$place] = max($min_points, intval($points)); $result['sum'] += $this->parameters['type'] * $result['points'][$place]; } @@ -217,6 +219,10 @@ class ApiPkl { } return $result; } + + function calculate_bridgenet_points() { + throw new ParametersException('BridgeNET points not supported in this API version'); + } } class ApiPklV1 extends ApiPkl {} @@ -239,6 +245,10 @@ class ApiPklV3 extends ApiPklV2 { function check_parameters() { if (!isset($this->parameters['manual']) || !isset($this->parameters['manual']['min_points']) || !isset($this->parameters['manual']['tournament_weight'])) { + $this->ensure_parameters(array('tournament_rank')); + if ($this->parameters['tournament_rank'] == ApiPkl::RANK_BNET) { + $this->ensure_parameters(array('boards')); + } if (isset($this->parameters['boards'])) { $this->check_values($this->parameters, array( 'boards' => function($r) { return ctype_digit($r); } @@ -249,6 +259,11 @@ class ApiPklV3 extends ApiPklV2 { return parent::check_parameters(); } + function calculate_bridgenet_points() { + $factor = min($this->parameters['boards'] / 27.0, 1.0); + return $this->calculate_points(0, $factor); + } + } ?> -- cgit v1.2.3 From a649f90765f64392968c4d9bbe08bf9e7668c9e4 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 14 May 2020 01:33:23 +0200 Subject: Pass 'boards' argument through parameter checks, if present --- http/api-inc.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'http/api-inc.php') diff --git a/http/api-inc.php b/http/api-inc.php index fc0d48e..67a7fd7 100644 --- a/http/api-inc.php +++ b/http/api-inc.php @@ -120,6 +120,9 @@ class ApiPkl { if ($return['type'] != 2 && $this->parameters['tournament_rank'] == ApiPkl::RANK_KMP) { throw new ParametersException('Parameter: type has incorrect value (' . $return['type'] . ') for KMP tournament'); } + if (isset($this->parameters['boards'])) { + $return['boards'] = intval($this->parameters['boards']); + } $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']); -- cgit v1.2.3 From 1e0b0b0e93ad6efe1d9bfef2e52665f73b17df38 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 14 May 2020 01:33:53 +0200 Subject: Skip places with 0 points --- http/api-inc.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'http/api-inc.php') diff --git a/http/api-inc.php b/http/api-inc.php index 67a7fd7..1364195 100644 --- a/http/api-inc.php +++ b/http/api-inc.php @@ -200,8 +200,11 @@ class ApiPkl { 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 * $scale_factor); - $result['points'][$place] = max($min_points, intval($points)); - $result['sum'] += $this->parameters['type'] * $result['points'][$place]; + $points = max($min_points, intval($points)); + if ($points > 0) { + $result['points'][$place] = $points; + $result['sum'] += $this->parameters['type'] * $result['points'][$place]; + } } return $result; } -- cgit v1.2.3 From 316201fc806236d1ac1115f97caefcd514adc528 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 14 May 2020 01:35:33 +0200 Subject: Do not skip type/board number check for B***eNET even if manual overrides are provided --- http/api-inc.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'http/api-inc.php') diff --git a/http/api-inc.php b/http/api-inc.php index 1364195..7780e64 100644 --- a/http/api-inc.php +++ b/http/api-inc.php @@ -250,18 +250,18 @@ class ApiPklV2 extends ApiPklV1 { class ApiPklV3 extends ApiPklV2 { function check_parameters() { - if (!isset($this->parameters['manual']) || !isset($this->parameters['manual']['min_points']) || !isset($this->parameters['manual']['tournament_weight'])) { - $this->ensure_parameters(array('tournament_rank')); - if ($this->parameters['tournament_rank'] == ApiPkl::RANK_BNET) { - $this->ensure_parameters(array('boards')); - } - if (isset($this->parameters['boards'])) { - $this->check_values($this->parameters, array( - 'boards' => function($r) { return ctype_digit($r); } - )); - $this->parameters['over39_boards'] = strval(intval($this->parameters['boards'] > 39)); + if (isset($this->parameters['tournament_rank']) && $this->parameters['tournament_rank'] == ApiPkl::RANK_BNET) { + $this->ensure_parameters(array('boards', 'type')); + if ($this->parameters['type'] == 4) { + throw new ParametersException('Parameter: type has incorrect value (' . $this->parameters['type'] . ') for BridgeNET tournament'); } } + if (isset($this->parameters['boards'])) { + $this->check_values($this->parameters, array( + 'boards' => function($r) { return ctype_digit($r); } + )); + $this->parameters['over39_boards'] = strval(intval($this->parameters['boards'] > 39)); + } return parent::check_parameters(); } -- cgit v1.2.3 From 00d867eb3e83a23157f593593063c6dfffb49aa6 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 14 May 2020 18:47:27 +0200 Subject: Ignore manual parameters when calculating BridgeNET poitns --- http/api-inc.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'http/api-inc.php') diff --git a/http/api-inc.php b/http/api-inc.php index 7780e64..2606df7 100644 --- a/http/api-inc.php +++ b/http/api-inc.php @@ -255,6 +255,9 @@ class ApiPklV3 extends ApiPklV2 { if ($this->parameters['type'] == 4) { throw new ParametersException('Parameter: type has incorrect value (' . $this->parameters['type'] . ') for BridgeNET tournament'); } + if (isset($this->parameters['manual'])) { + unset($this->parameters['manual']); + } } if (isset($this->parameters['boards'])) { $this->check_values($this->parameters, array( -- cgit v1.2.3