diff options
author | emkael <emkael@tlen.pl> | 2019-01-20 13:20:52 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-01-20 13:20:52 +0100 |
commit | 080dea366e57db032e1928019f7ea599f11dabea (patch) | |
tree | 4c5dcc0b577521d842ee65f5cd9ee96487a41ce8 | |
parent | 8227f1561781e8ed1b3acca140bb611559e25a98 (diff) |
Detailed output structure
-rw-r--r-- | API.md | 6 | ||||
-rw-r--r-- | http/api.php | 10 | ||||
-rw-r--r-- | http/pkle2018-test.php | 8 | ||||
-rw-r--r-- | test/apitest/pzbs.py | 4 |
4 files changed, 14 insertions, 14 deletions
@@ -67,7 +67,7 @@ Format odpowiedzi API zwraca odpowiedź sformatowaną jako JSON. -Zwracany jest jeden obiekt-słownik. Jego elementy indeksowane kolejnymi liczbami naturalnymi to liczba PKL za kolejne miejsca, a element `sum` to suma PKL w turnieju (w turnieju teamów - przy założeniu czterosobowych teamów). +Zwracany jest pojedynczy obiekt. Element `points` jest słownikiem indeksowanym kolejnymi liczbami naturalnymi i podaje liczby PKL za kolejne miejsca, a element `sum` to suma PKL w turnieju (w turnieju teamów - przy założeniu czterosobowych teamów). Prawidłowa odpowiedź zwaracana jest z kodem HTTP 200 (OK). W przypadku błędów parametróé wejściowych, treść błędu zwracana jest łańcuchem tekstowym, a odpowiedź HTTP ma ustawiony kod 400 (Bad Request). W przypadku błędu serwera zwracany jest kod HTTP 500 (Internal Server Error). @@ -77,8 +77,8 @@ Przykładowa odpowiedź ``` HTTP/1.1 200 OK Content-Type: application/json -Content-Length: 928 +Content-Length: 939 -{"sum":1626,"1":38,"2":37,"3":35,"4":34,"5":33,"6":32,"7":31,"8":29,"9":28,"10":27,"11":26,"12":25,"13":23,"14":22,"15":21,"16":20,"17":19,"18":18,"19":16,"20":15,"21":14,"22":13,"23":12,"24":10,"25":9,"26":8,"27":8,"28":8,"29":7,"30":7,"31":7,"32":7,"33":7,"34":6,"35":6,"36":6,"37":6,"38":6,"39":5,"40":5,"41":5,"42":5,"43":5,"44":4,"45":4,"46":4,"47":4,"48":4,"49":3,"50":3,"51":3,"52":3,"53":3,"54":2,"55":2,"56":2,"57":2,"58":2,"59":1,"60":1,"61":1,"62":1,"63":1,"64":1,"65":1,"66":1,"67":1,"68":1,"69":1,"70":1,"71":1,"72":1,"73":1,"74":1,"75":1,"76":1,"77":1,"78":1,"79":1,"80":1,"81":1,"82":1,"83":1,"84":1,"85":1,"86":1,"87":1,"88":1,"89":1,"90":1,"91":1,"92":1,"93":1,"94":1,"95":1,"96":1,"97":1,"98":1,"99":1,"100":1,"101":1,"102":1,"103":1,"104":1,"105":1,"106":1,"107":1,"108":1,"109":1,"110":1,"111":1,"112":1,"113":1,"114":1,"115":1,"116":1,"117":1,"118":1,"119":1,"120":1,"121":1,"122":1,"123":1,"124":1,"125":1} +{"sum":1626,"points":{"1":38,"2":37,"3":35,"4":34,"5":33,"6":32,"7":31,"8":29,"9":28,"10":27,"11":26,"12":25,"13":23,"14":22,"15":21,"16":20,"17":19,"18":18,"19":16,"20":15,"21":14,"22":13,"23":12,"24":10,"25":9,"26":8,"27":8,"28":8,"29":7,"30":7,"31":7,"32":7,"33":7,"34":6,"35":6,"36":6,"37":6,"38":6,"39":5,"40":5,"41":5,"42":5,"43":5,"44":4,"45":4,"46":4,"47":4,"48":4,"49":3,"50":3,"51":3,"52":3,"53":3,"54":2,"55":2,"56":2,"57":2,"58":2,"59":1,"60":1,"61":1,"62":1,"63":1,"64":1,"65":1,"66":1,"67":1,"68":1,"69":1,"70":1,"71":1,"72":1,"73":1,"74":1,"75":1,"76":1,"77":1,"78":1,"79":1,"80":1,"81":1,"82":1,"83":1,"84":1,"85":1,"86":1,"87":1,"88":1,"89":1,"90":1,"91":1,"92":1,"93":1,"94":1,"95":1,"96":1,"97":1,"98":1,"99":1,"100":1,"101":1,"102":1,"103":1,"104":1,"105":1,"106":1,"107":1,"108":1,"109":1,"110":1,"111":1,"112":1,"113":1,"114":1,"115":1,"116":1,"117":1,"118":1,"119":1,"120":1,"121":1,"122":1,"123":1,"124":1,"125":1}} ``` diff --git a/http/api.php b/http/api.php index e83420b..a3f155d 100644 --- a/http/api.php +++ b/http/api.php @@ -11,7 +11,7 @@ Parametry: - ręczna waga (opcjonalny) - ręczny współczynnik zawodniczy (opcjonalny) - ręczne progi (opcjonalne) - + { "type": 2, "contestants": 20, @@ -73,7 +73,7 @@ function check_parameters($parameters) { 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')); @@ -174,12 +174,12 @@ function calculate_points($parameters) { (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); + $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[$place] = max($min_points, intval($points)); - $result['sum'] += $parameters['type'] * $result[$place]; + $result['points'][$place] = max($min_points, intval($points)); + $result['sum'] += $parameters['type'] * $result['points'][$place]; } return $result; } diff --git a/http/pkle2018-test.php b/http/pkle2018-test.php index 3826d3a..9b056c1 100644 --- a/http/pkle2018-test.php +++ b/http/pkle2018-test.php @@ -68,11 +68,11 @@ function display() { 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[place] + ' WHERE `miejsce` = ' + place + ';'); - sqlTeamy.push('UPDATE `addons` SET `mastr` = ' + response[place] + ' WHERE `place` = ' + place + ';'); - pklHTML.push('<tr><td class="t">' + place + '</td><td class="t">' + response[place] + '</td></tr>'); + 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>'); + 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(""); diff --git a/test/apitest/pzbs.py b/test/apitest/pzbs.py index 84488ff..18274ff 100644 --- a/test/apitest/pzbs.py +++ b/test/apitest/pzbs.py @@ -58,12 +58,12 @@ class PzbsCalculator(ApiTest): return params def get_response(self, text): - results = {} + results = {u'points': {}} content = bs(text, 'lxml') for row in content.select('table')[-1].select('tr'): cells = row.select('td') if cells[0].text.isdigit(): - results[cells[0].text] = int(cells[1].text) + results[u'points'][cells[0].text] = int(cells[1].text) elif cells[0].text == 'SUMA PKL': results[u'sum'] = int(cells[1].text) return results |