diff options
Diffstat (limited to 'jfr_playoff')
-rw-r--r-- | jfr_playoff/data.py | 38 | ||||
-rw-r--r-- | jfr_playoff/db.py | 3 | ||||
-rw-r--r-- | jfr_playoff/dto.py | 4 | ||||
-rw-r--r-- | jfr_playoff/filemanager.py | 11 | ||||
-rw-r--r-- | jfr_playoff/generator.py | 36 | ||||
-rw-r--r-- | jfr_playoff/settings.py | 1 | ||||
-rw-r--r-- | jfr_playoff/sql.py | 6 | ||||
-rw-r--r-- | jfr_playoff/template.py | 2 |
8 files changed, 45 insertions, 56 deletions
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py index db65393..6fc3c4b 100644 --- a/jfr_playoff/data.py +++ b/jfr_playoff/data.py @@ -49,8 +49,7 @@ class PlayoffData(object): self.match_info[match['id']].link = phase['link'] else: self.match_info[match['id']].link = urljoin( - phase['link'], self.match_info[match['id']].link - ) + phase['link'], self.match_info[match['id']].link) return self.match_info def get_match_link(self, match): @@ -67,8 +66,7 @@ class PlayoffData(object): teams = [Team(), Team()] row = self.database.fetch( match['database'], p_sql.MATCH_RESULTS, - (match['table'], match['round']) - ) + (match['table'], match['round'])) teams[0].name = row[0] teams[1].name = row[1] teams[0].score = row[3] + row[5] @@ -91,27 +89,24 @@ class PlayoffData(object): if 'winner' in match['teams'][i]: match_teams += [ self.match_info[winner_match].winner - for winner_match in match['teams'][i]['winner'] - ] + for winner_match in match['teams'][i]['winner']] if 'loser' in match['teams'][i]: match_teams += [ self.match_info[loser_match].loser - for loser_match in match['teams'][i]['loser'] - ] + for loser_match in match['teams'][i]['loser']] if 'place' in match['teams'][i]: match_teams += [ self.teams[place-1][0] - for place in match['teams'][i]['place'] - ] + for place in match['teams'][i]['place']] known_teams = [team for team in match_teams if team is not None] if len(known_teams) > 0: teams[i].name = '<br />'.join([ - team if team is not None else '??' for team in match_teams]) + team if team is not None + else '??' for team in match_teams]) else: teams[i].name = '' return teams - def get_match_info(self, match): info = Match() info.id = match['id'] @@ -132,14 +127,12 @@ class PlayoffData(object): try: towels = self.database.fetch( match['database'], p_sql.TOWEL_COUNT, - (match['table'], match['round']) - ) + (match['table'], match['round'])) row = [0 if r is None else r for r in self.database.fetch( match['database'], p_sql.BOARD_COUNT, - (match['table'], match['round']) - )] + (match['table'], match['round']))] if row[1] > 0: info.running = int(row[1]) if row[1] >= row[0] - towels[0]: @@ -170,15 +163,18 @@ class PlayoffData(object): winner_key = tuple(match['winner']) if winner_key not in leaderboard_teams: leaderboard_teams[winner_key] = [] - leaderboard_teams[winner_key].append(self.match_info[match['id']].winner) + leaderboard_teams[winner_key].append( + self.match_info[match['id']].winner) if 'loser' in match: loser_key = tuple(match['loser']) if loser_key not in leaderboard_teams: leaderboard_teams[loser_key] = [] - leaderboard_teams[loser_key].append(self.match_info[match['id']].loser) + leaderboard_teams[loser_key].append( + self.match_info[match['id']].loser) for positions, position_teams in leaderboard_teams.iteritems(): positions = list(positions) - if len(positions) == len([team for team in position_teams if team is not None]): + if len(positions) == len([ + team for team in position_teams if team is not None]): for table_team in self.teams: if table_team[0] in position_teams: position = positions.pop(0) @@ -192,9 +188,7 @@ class PlayoffData(object): len(phase['matches']) + len(phase['dummies']) if 'dummies' in phase else len(phase['matches']) - for phase in self.phases - ]) - ) + for phase in self.phases])) def get_shortname(self, fullname): for team in self.teams: diff --git a/jfr_playoff/db.py b/jfr_playoff/db.py index 19ec2fb..b94f3d5 100644 --- a/jfr_playoff/db.py +++ b/jfr_playoff/db.py @@ -10,8 +10,7 @@ class PlayoffDB(object): user=settings['user'], password=settings['pass'], host=settings['host'], - port=settings['port'] - ) + port=settings['port']) self.db_cursor = self.database.cursor(buffered=True) def get_cursor(self): diff --git a/jfr_playoff/dto.py b/jfr_playoff/dto.py index bf3e16a..f5e08ef 100644 --- a/jfr_playoff/dto.py +++ b/jfr_playoff/dto.py @@ -2,6 +2,7 @@ class Team(object): name = '' score = 0.0 + class Match(object): id = None teams = None @@ -12,10 +13,11 @@ class Match(object): winner_matches = None loser_matches = None + class Phase(object): title = None link = None matches = [] running = False -__all__ = ['Team', 'Match', 'Phase'] +__all__ = ('Team', 'Match', 'Phase') diff --git a/jfr_playoff/filemanager.py b/jfr_playoff/filemanager.py index 03dbaf7..5cd2a80 100644 --- a/jfr_playoff/filemanager.py +++ b/jfr_playoff/filemanager.py @@ -22,7 +22,6 @@ class PlayoffFileManager(object): if path.startswith(self.output_path): self.files.add(path.replace(self.output_path, '')) - def write_content(self, content): output = open(self.output_file, 'w') output.write(content.encode('utf8')) @@ -33,16 +32,18 @@ class PlayoffFileManager(object): def copy_scripts(self, script_path='sklady/playoff.js'): script_output_path = os.path.join(self.output_path, script_path) shutil.copy( - unicode(os.path.join(os.path.dirname(__main__.__file__), 'playoff.js')), - unicode(script_output_path) - ) + unicode(os.path.join( + os.path.dirname(__main__.__file__), 'playoff.js')), + unicode(script_output_path)) self.register_file(script_output_path) return script_output_path def send_files(self): if self.goniec['enabled']: try: - content_lines = [self.output_path] + list(self.files) + ['bye', ''] + content_lines = [self.output_path] + \ + list(self.files) + \ + ['bye', ''] print '\n'.join(content_lines) goniec = socket.socket() goniec.connect((self.goniec['host'], self.goniec['port'])) diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py index bc2a388..5868750 100644 --- a/jfr_playoff/generator.py +++ b/jfr_playoff/generator.py @@ -16,23 +16,18 @@ class PlayoffGenerator(object): return p_temp.PAGE % ( p_temp.PAGE_HEAD % ( p_temp.PAGE_HEAD_REFRESH % ( - self.page['refresh'] - ) if self.page['refresh'] > 0 else '', - self.page['title'] - ), + self.page['refresh']) + if self.page['refresh'] > 0 else '', + self.page['title']), p_temp.PAGE_BODY % ( self.page['logoh'], self.get_match_grid( self.data.get_dimensions(), self.data.generate_phases(), - self.data.fill_match_info() - ), + self.data.fill_match_info()), self.get_leaderboard_table(self.data.fill_leaderboard()), p_temp.PAGE_BODY_FOOTER.decode('utf8') % ( - datetime.now().strftime('%Y-%m-%d o %H:%M') - ) - ) - ) + datetime.now().strftime('%Y-%m-%d o %H:%M')))) def get_match_table(self, match): rows = '' @@ -46,16 +41,13 @@ class PlayoffGenerator(object): team.name, ' / '.join([ self.data.get_shortname(name) for name in - team.name.split('<br />') - ]), + team.name.split('<br />')]), match.link, - team.score - ) + team.score) html = p_temp.MATCH_TABLE.decode('utf8') % ( int(self.page['width'] * 0.75), int(self.page['width'] * 0.25), - rows - ) + rows) if match.running > 0: html += p_temp.MATCH_RUNNING % (match.link, match.running) return html @@ -69,8 +61,7 @@ class PlayoffGenerator(object): phase.link, self.page['width'], position, - phase.title - ) + phase.title) def get_match_box(self, match, position): if match is not None: @@ -83,8 +74,7 @@ class PlayoffGenerator(object): ' '.join([ str(m) for m in match.loser_matches ]) if match.loser_matches is not None else '', - self.get_match_table(match) - ) + self.get_match_table(match)) return '' def get_match_grid(self, dimensions, grid, matches): @@ -94,8 +84,7 @@ class PlayoffGenerator(object): ) - self.page['margin'], dimensions[1] * ( self.page['height'] + self.page['margin'] - ) - self.page['margin'] - ) + ) - self.page['margin']) grid_boxes = '' col_no = 0 for phase in grid: @@ -126,7 +115,8 @@ class PlayoffGenerator(object): position = 1 rows = '' for team in leaderboard: - rows += p_temp.LEADERBOARD_ROW % (position, self.get_flag(team), team or '') + rows += p_temp.LEADERBOARD_ROW % ( + position, self.get_flag(team), team or '') position += 1 html = p_temp.LEADERBOARD.decode('utf8') % (rows) return html diff --git a/jfr_playoff/settings.py b/jfr_playoff/settings.py index 3b765bc..da92458 100644 --- a/jfr_playoff/settings.py +++ b/jfr_playoff/settings.py @@ -7,6 +7,7 @@ import sys def complete_filename(text, state): return (glob.glob(text+'*')+[None])[state] + class PlayoffSettings(object): def __init__(self): diff --git a/jfr_playoff/sql.py b/jfr_playoff/sql.py index 76ea728..b01bd08 100644 --- a/jfr_playoff/sql.py +++ b/jfr_playoff/sql.py @@ -1,5 +1,6 @@ MATCH_RESULTS = ''' -SELECT t1.fullname, t2.fullname, matches.carry, matches.vph, matches.vpv, matches.corrh, matches.corrv +SELECT t1.fullname, t2.fullname, matches.carry, + matches.vph, matches.vpv, matches.corrh, matches.corrv FROM #db#.matches matches JOIN #db#.teams t1 ON t1.id = #db#.matches.homet @@ -9,7 +10,8 @@ WHERE matches.tabl = %s AND matches.rnd = %s ''' BOARD_COUNT = ''' -SELECT segmentsperround*boardspersegment, SUM(sc1.contract IS NOT NULL AND sc2.contract IS NOT NULL) +SELECT segmentsperround*boardspersegment, + SUM(sc1.contract IS NOT NULL AND sc2.contract IS NOT NULL) FROM #db#.scores sc1 JOIN #db#.scores sc2 ON sc1.rnd = sc2.rnd diff --git a/jfr_playoff/template.py b/jfr_playoff/template.py index 8713ab9..99e6225 100644 --- a/jfr_playoff/template.py +++ b/jfr_playoff/template.py @@ -1,4 +1,4 @@ -#encoding=utf-8 +# -*- coding: utf-8 -*- MATCH_TABLE = ''' <table border="0" cellspacing="0"> |