diff options
author | emkael <emkael@tlen.pl> | 2019-01-18 01:15:37 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-01-18 01:15:37 +0100 |
commit | 033cd8f39d3e88283e4eb626f35f0e97c16e9e0e (patch) | |
tree | 49894d0624e8f25c0e2201954f413020c98cafdf /test/apitest/pzbs.py | |
parent | 8c92dbcc1fa093c3f28df21ecc13b42b4e701be3 (diff) |
Test suite for API <-> pzbs.pl comparison
Diffstat (limited to 'test/apitest/pzbs.py')
-rw-r--r-- | test/apitest/pzbs.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/apitest/pzbs.py b/test/apitest/pzbs.py new file mode 100644 index 0000000..1a1f69f --- /dev/null +++ b/test/apitest/pzbs.py @@ -0,0 +1,69 @@ +import urlparse + +from bs4 import BeautifulSoup as bs + +from .apitest import ApiTest + +class PzbsCalculator(ApiTest): + ranks = { + 'o++++': 1, + 'o+++': 2, + 'o++': 3, + 'o+': 4, + 'o-': 5, + 'r': 6, + 'o': 7, + 'k': 8 + } + def get_url(self): + return 'http://pzbs.pl/sedziowie/pkl/pkle2018.php' + def get_method(self): + return 'post' + def get_request(self, + tour_type, tour_rank, tour_boards, + cont_count, cont_rank, + override=None): + params = { + 'rgg': 25, 'rgp': 15, 'rot': 10, 'rok1': 7, 'rok': 5, 'rtp': 4, 'rto': 2, 'rtk': 1, + 'min1': 200, 'min2': 150, 'min3': 75, 'min4': 50, 'min5': 0, 'min6': 0, 'min7': 0, 'min8': 0, + 'rgg_': 40, 'rgp_': 25, 'rot_': 15, 'rok1_': 10, 'rok_': 7, 'rtp_': 5, 'rto_': 3, 'rtk_': 2, + 'min1_': 300, 'min2_': 200, 'min3_': 100, 'min4_': 70, 'min5_': 0, 'min6_': 0, 'min7_': 0, 'min8_': 0, + 'zaw': 0.05, 'prp1': 90, 'prp2': 20, 'pru1': 2, 'pru2': 20, 'pru3': 50, + 'typ': 0, + 'rozdan': 0, + 'rng': 0, + 'iuc': 0, + 'izw': 0, + 'swk': 0, + 'srd': 0 + } + params['typ'] = self.tourtypes[tour_type] + params['rozdan'] = tour_boards + params['rng'] = self.ranks[tour_rank] + params['iuc'] = cont_count + params['izw'] = cont_count * self.tourtypes[tour_type] + params['swk'] = cont_rank + params['srd'] = cont_rank / (cont_count * self.tourtypes[tour_type]) + if override: + if 'points' in override: + params['min' + str(params['typ']) + '_'*params['rozdan']] = override['points'] + if 'weight' in override: + params['r' + ['', 'gg', 'gp', 'ot', 'ok1', 'ok', 'tp', 'to', 'tk'][params['typ']] + '_'*params['rozdan']] = override['weight'] + if 'players' in override: + params['zaw'] = override['players'] + if 'cutoff' in override: + for i in range(0, 3): + params['pru' + str(i+1)] = override['cutoff'][i][0] * 100 + params['prp' + str(i+1)] = override['cutoff'][i][1] * 100 + return params + + def get_response(self, text): + results = {} + 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) + elif cells[0].text == 'SUMA PKL': + results[u'sum'] = int(cells[1].text) + return results |