summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-08-01 02:50:24 +0200
committeremkael <emkael@tlen.pl>2017-08-01 02:50:24 +0200
commit7f76c56ab258c8978c39507eb997852e2280449d (patch)
tree9ebb6dd2e0a217cb2e587ada8fb4e26596ae2b1e /jfr_playoff
parentcf11f2639f965c70dd8237580a23e7441c670693 (diff)
Code style improved
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/data.py51
-rw-r--r--jfr_playoff/db.py7
-rw-r--r--jfr_playoff/filemanager.py4
-rw-r--r--jfr_playoff/generator.py48
-rw-r--r--jfr_playoff/settings.py7
5 files changed, 84 insertions, 33 deletions
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py
index 2a965d1..3952c64 100644
--- a/jfr_playoff/data.py
+++ b/jfr_playoff/data.py
@@ -1,8 +1,8 @@
from urlparse import urljoin
import mysql
-from db import PlayoffDB
-import sql as p_sql
-from dto import *
+from jfr_playoff.db import PlayoffDB
+from jfr_playoff.dto import Team, Match, Phase
+import jfr_playoff.sql as p_sql
class PlayoffData(object):
def __init__(self, settings):
@@ -38,8 +38,12 @@ class PlayoffData(object):
for phase in self.phases:
for match in phase['matches']:
self.match_info[match['id']] = self.get_match_info(match)
- self.match_info[match['id']].link = phase['link'] if self.match_info[match['id']].link is None else urljoin(
- phase['link'], self.match_info[match['id']].link)
+ if self.match_info[match['id']].link is None:
+ self.match_info[match['id']].link = phase['link']
+ else:
+ self.match_info[match['id']].link = urljoin(
+ phase['link'], self.match_info[match['id']].link
+ )
return self.match_info
def get_match_link(self, match):
@@ -54,7 +58,10 @@ class PlayoffData(object):
def get_db_match_teams(self, match):
teams = [Team(), Team()]
- row = self.database.fetch(match['database'], p_sql.MATCH_RESULTS, (match['table'], match['round']))
+ row = self.database.fetch(
+ match['database'], p_sql.MATCH_RESULTS,
+ (match['table'], match['round'])
+ )
teams[0].name = row[0]
teams[1].name = row[1]
teams[0].score = row[3] + row[5]
@@ -89,12 +96,12 @@ class PlayoffData(object):
self.teams[place-1][0]
for place in match['teams'][i]['place']
]
- teams[i].name = '<br />'.join([
- team if team is not None else '??'
- for team in match_teams]
- ) if len([
- team for team in match_teams if team is not None
- ]) > 0 else ''
+ 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])
+ else:
+ teams[i].name = ''
return teams
@@ -115,14 +122,26 @@ class PlayoffData(object):
except (mysql.connector.Error, TypeError, IndexError):
info.teams = self.get_config_match_teams(match)
try:
- towels = self.database.fetch(match['database'], p_sql.TOWEL_COUNT, (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']))]
+ towels = self.database.fetch(
+ match['database'], p_sql.TOWEL_COUNT,
+ (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'])
+ )]
if row[1] > 0:
info.running = int(row[1])
if row[1] >= row[0] - towels[0]:
info.running = 0
- info.winner = info.teams[0].name if info.teams[0].score > info.teams[1].score else info.teams[1].name
- info.loser = info.teams[1].name if info.teams[0].score > info.teams[1].score else info.teams[0].name
+ if info.teams[0].score > info.teams[1].score:
+ info.winner = info.teams[0].name
+ info.loser = info.teams[1].name
+ else:
+ info.loser = info.teams[0].name
+ info.winner = info.teams[1].name
except (mysql.connector.Error, TypeError, KeyError):
pass
return info
diff --git a/jfr_playoff/db.py b/jfr_playoff/db.py
index aa0c2e2..8457dd4 100644
--- a/jfr_playoff/db.py
+++ b/jfr_playoff/db.py
@@ -13,7 +13,10 @@ class PlayoffDB(object):
)
self.db_cursor = self.database.cursor(buffered=True)
- def fetch(self, db, sql, params):
- self.db_cursor.execute(sql.replace('#db#', db), params)
+ def get_cursor(self):
+ return self.db_cursor
+
+ def fetch(self, db_name, sql, params):
+ self.db_cursor.execute(sql.replace('#db#', db_name), params)
row = self.db_cursor.fetchone()
return row
diff --git a/jfr_playoff/filemanager.py b/jfr_playoff/filemanager.py
index 8dc8b85..06374dd 100644
--- a/jfr_playoff/filemanager.py
+++ b/jfr_playoff/filemanager.py
@@ -1,4 +1,6 @@
-import os, shutil, socket
+import os
+import shutil
+import socket
import __main__
class PlayoffFileManager(object):
diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py
index 81ca6c9..7237c9f 100644
--- a/jfr_playoff/generator.py
+++ b/jfr_playoff/generator.py
@@ -1,6 +1,6 @@
from datetime import datetime
-import template as p_temp
-from data import PlayoffData
+import jfr_playoff.template as p_temp
+from jfr_playoff.data import PlayoffData
class PlayoffGenerator(object):
def __init__(self, settings):
@@ -14,14 +14,22 @@ class PlayoffGenerator(object):
def generate_content(self):
return p_temp.PAGE % (
p_temp.PAGE_HEAD % (
- p_temp.PAGE_HEAD_REFRESH % (self.page['refresh']) if self.page['refresh'] > 0 else '',
+ p_temp.PAGE_HEAD_REFRESH % (
+ 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.get_match_grid(
+ self.data.get_dimensions(),
+ self.data.generate_phases(),
+ 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'))
+ p_temp.PAGE_BODY_FOOTER.decode('utf8') % (
+ datetime.now().strftime('%Y-%m-%d o %H:%M')
+ )
)
)
@@ -29,11 +37,16 @@ class PlayoffGenerator(object):
rows = ''
for team in match.teams:
rows += p_temp.MATCH_TEAM_ROW % (
- ' '.join(['winner' if team.name == match.winner else '',
- 'loser' if team.name == match.loser else '']).strip(),
+ ' '.join([
+ 'winner' if team.name == match.winner else '',
+ 'loser' if team.name == match.loser else ''
+ ]).strip(),
match.link,
team.name,
- ' / '.join([self.data.get_shortname(name) for name in team.name.split('<br />')]),
+ ' / '.join([
+ self.data.get_shortname(name) for name in
+ team.name.split('<br />')
+ ]),
match.link,
team.score
)
@@ -74,8 +87,14 @@ class PlayoffGenerator(object):
grid_boxes += p_temp.MATCH_BOX % (
grid_x, grid_y,
match,
- ' '.join([str(m) for m in matches[match].winner_matches]) if matches[match].winner_matches is not None else '',
- ' '.join([str(m) for m in matches[match].loser_matches]) if matches[match].loser_matches is not None else '',
+ ' '.join([
+ str(m) for m in
+ matches[match].winner_matches
+ ]) if matches[match].winner_matches is not None else '',
+ ' '.join([
+ str(m) for m in
+ matches[match].loser_matches
+ ]) if matches[match].loser_matches is not None else '',
self.get_match_table(matches[match])
)
row_no += 1
@@ -85,7 +104,12 @@ class PlayoffGenerator(object):
canvas_attrs.append(
'data-%s="%s"' % (setting.replace('_', '-'), str(value))
)
- return p_temp.MATCH_GRID % (grid_width, grid_height, grid_width, grid_height, ' '.join(canvas_attrs), grid_boxes)
+ return p_temp.MATCH_GRID % (
+ grid_width, grid_height,
+ grid_width, grid_height,
+ ' '.join(canvas_attrs),
+ grid_boxes
+ )
def get_leaderboard_table(self, leaderboard):
if len([t for t in leaderboard if t is not None]) == 0:
@@ -94,7 +118,7 @@ class PlayoffGenerator(object):
rows = ''
for team in leaderboard:
rows += p_temp.LEADERBOARD_ROW % (position, self.get_flag(team), team or '')
- position +=1
+ position += 1
html = p_temp.LEADERBOARD.decode('utf8') % (rows)
return html
diff --git a/jfr_playoff/settings.py b/jfr_playoff/settings.py
index e69b1d3..3ed1774 100644
--- a/jfr_playoff/settings.py
+++ b/jfr_playoff/settings.py
@@ -1,9 +1,12 @@
-import glob, json, os, readline, sys
+import glob
+import json
+import readline
+import sys
def complete_filename(text, state):
return (glob.glob(text+'*')+[None])[state]
-class PlayoffSettings:
+class PlayoffSettings(object):
def __init__(self):
self.settings = None