diff --git a/.gitignore b/.gitignore index ec59ba5..7a151b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ *~ *.db tournament_venv -*.log \ No newline at end of file +*.log +.idea +*.iml \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index a70f972..9dcac6c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,7 +1,10 @@ -from flask import Flask import logging + +from flask import Flask + import config + app = Flask(__name__) app.config.from_object('config') @@ -11,6 +14,7 @@ logging.basicConfig(filename=config.LOGFILE, level=logging.DEBUG, - format='%(asctime)s %(message)s', + format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') +logging.getLogger().addHandler(logging.StreamHandler()) \ No newline at end of file diff --git a/app/api.py b/app/api.py index 190707e..18ad52e 100644 --- a/app/api.py +++ b/app/api.py @@ -1,166 +1,188 @@ +from sqlite3 import IntegrityError + from flask import request -import json -import sqlite3 + from app import app from models import Player -import tournament_dao, player_dao, match_dao, tourney +import tournament_dao +import player_dao +import match_dao +import tourney from deepJson import jsonify -@app.route('/api/tournament', methods = ['POST']) + +@app.route('/api/tournament', methods=['POST']) def post_tournament(): try: description = request.form['description'] tourn_type = '' tournament = tourney.create_tournament(description, tourn_type) - except sqlite3.IntegrityError: + except IntegrityError: message = "DB ERROR!" - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: return jsonify(tournament) -@app.route('/api/tournament/status/', methods = ['GET']) + +@app.route('/api/tournament/status/', methods=['GET']) def get_new_tournaments(status): tourneys = tournament_dao.find_all_by_status(status) - return jsonify({'tournaments':tourneys}) + return jsonify({'tournaments': tourneys}) + -@app.route('/api/tournament/', methods = ['GET','POST','DELETE']) -def tournament2(id): +@app.route('/api/tournament/', methods=['GET', 'POST', 'DELETE']) +def tournament_http(tournament_id): if request.method == 'POST': - return _post_tourney_entries(id, request) + return _post_tourney_entries(tournament_id) elif request.method == 'DELETE': - return _delete_tournament(id) + return _delete_tournament(tournament_id) elif request.method == 'GET': - return _get_tournament(id) + return _get_tournament(tournament_id) + -def _post_tourney_entries(id, request): +def _post_tourney_entries(tournament_id): try: player_ids = request.form['entries'] - tourney.setup_round_robin(player_ids, id) - except sqlite3.IntegrityError: + tourney.setup_round_robin(player_ids, tournament_id) + except IntegrityError: message = "ERROR!" - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: - return jsonify({'success':True, 'id':id}) + return jsonify({'success': True, 'tournament_id': tournament_id}) -def _delete_tournament(id): + +def _delete_tournament(tournament_id): try: - tournament_dao.delete(id) - except sqlite3.IntegrityError: + tournament_dao.delete(tournament_id) + except IntegrityError: message = "ERROR!" - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: - return jsonify({'success':True, 'id':id}) + return jsonify({'success': True, 'tournament_id': tournament_id}) + -def _get_tournament(id): +def _get_tournament(tournament_id): try: - tournament = tournament_dao.find(id) - except sqlite3.IntegrityError: + tournament = tournament_dao.find(tournament_id) + except IntegrityError: message = "ERROR!" - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: if tournament: - return jsonify({'success':True, 'tournament':tournament}) + return jsonify({'success': True, 'tournament': tournament}) else: - return jsonify({'success':False, 'message':'Not Found'}),404 + return jsonify({'success': False, 'message': 'Not Found'}), 404 + -@app.route('/api/match/', methods = ['POST','DELETE']) -def match(id): +@app.route('/api/match/', methods=['POST', 'DELETE']) +def match_http(match_id): if request.method == 'POST': - return _post_match(id, request) + return _post_match(match_id) elif request.method == 'DELETE': - return _delete_match(id) + return _delete_match(match_id) -def _post_match(id, request): + +def _post_match(match_id): try: params = request.form - match = tourney.update_match(id, params['player1_id'], + match = tourney.update_match(match_id, params['player1_id'], params['player2_id'], params['score1'], params['score2']) - except sqlite3.IntegrityError: + except IntegrityError: message = "ERROR!" - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: - return jsonify({'match':match}) + return jsonify({'match': match}) + -def _delete_match(id): +def _delete_match(match_id): try: - match = tourney.undo_match(id) - except sqlite3.IntegrityError: + match = tourney.undo_match(match_id) + except IntegrityError: message = "ERROR!" - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: - return jsonify({'match':match}) - -@app.route('/api/tournament//match', methods = ['GET']) -def get_matches(id): - matches = match_dao.find_by_tournament(id) - return jsonify({'matches':matches}) - -@app.route('/api/tournament//standings', methods = ['GET']) -def get_standings(id): - standings = tourney.find_standings(id) - return jsonify({'standings':standings}) - -@app.route('/api/tournament//player', methods = ['GET']) -def get_entries(id): - players = player_dao.find_in_tournament(id) - return jsonify({'players':players}) - -@app.route('/api/tournament//player/', - methods = ['POST','DELETE']) -def add_or_delete_entry(tournament_id, player_id): + return jsonify({'match': match}) + + +@app.route('/api/tournament//match', methods=['GET']) +def get_matches(tournament_id): + matches = match_dao.find_by_tournament(tournament_id) + return jsonify({'matches': matches}) + + +@app.route('/api/tournament//standings', methods=['GET']) +def get_standings(tournament_id): + standings = tourney.find_standings(tournament_id) + return jsonify({'standings': standings}) + + +@app.route('/api/tournament//player', methods=['GET']) +def get_entries(tournament_id): + players = player_dao.find_in_tournament(tournament_id) + return jsonify({'players': players}) + + +@app.route('/api/tournament//player/', + methods=['POST', 'DELETE']) +def entry_http(tournament_id, player_id): try: if request.method == 'POST': player = player_dao.enter_tournament(player_id, tournament_id) elif request.method == 'DELETE': player = player_dao.unenter_tournament(player_id, tournament_id) - except sqlite3.IntegrityError: + except IntegrityError: message = "ERROR!" - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: - return jsonify({'success':True, 'player':player}) + return jsonify({'success': True, 'player': player}) + -@app.route('/api/tournament//status/', - methods = ['POST']) +@app.route('/api/tournament//status/', + methods=['POST']) def update_status(tournament_id, status): try: if status == '1': tourney.setup_round_robin(tournament_id) tournament_dao.update_status(tournament_id, status) - except sqlite3.IntegrityError: + except IntegrityError: message = "ERROR!" - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: - return jsonify({'success':True, 'id':tournament_id}) + return jsonify({'success': True, 'tournament_id': tournament_id}) + -@app.route('/api/player/', methods = ['DELETE']) -def delete_player(id): +@app.route('/api/player/', methods=['DELETE']) +def delete_player(player_id): try: - player_dao.delete(id) - except sqlite3.IntegrityError: + player_dao.delete(player_id) + except IntegrityError: message = "Players in tournaments cannot be deleted." - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: - return jsonify({'success':True, 'id':id}) + return jsonify({'success': True, 'tournament_id': player_id}) -@app.route('/api/player', methods = ['GET','POST']) -def api_player(): + +@app.route('/api/player', methods=['GET', 'POST']) +def player_http(): if request.method == 'POST': - return _post_player(request) + return _post_player() elif request.method == 'GET': return _get_player() -def _post_player(request): + +def _post_player(): try: fname = request.form['fname'] - id = player_dao.create(Player(fname)) - except sqlite3.IntegrityError: + player_id = player_dao.create(Player(fname)) + except IntegrityError: message = "Player name must be unique." - return jsonify({'success':False, 'message':message}),409 + return jsonify({'success': False, 'message': message}), 409 else: - return jsonify({'id':id,'fname':fname}) + return jsonify({'player_id': player_id, 'fname': fname}) + def _get_player(): players = player_dao.find_all() - return jsonify({'players':players}) + return jsonify({'players': players}) diff --git a/app/deepJson.py b/app/deepJson.py index d3ed645..2d50119 100644 --- a/app/deepJson.py +++ b/app/deepJson.py @@ -1,6 +1,7 @@ import types import json - + + def jsonify(obj): """Converts to JSON like json.dumps, but supports objects @@ -10,6 +11,7 @@ def jsonify(obj): The resulting collection is then passed into json.dumps() which produces a JSON representation of the input. """ + def _dictify(val): if type(val) in [int, long, float, bool, str, unicode, types.NoneType]: return val @@ -17,9 +19,7 @@ def _dictify(val): return [_dictify(item) for item in val] elif type(val) == dict: return {k: _dictify(val[k]) for k in val} - elif type(val) == complex: - return {"real": val.real, "imag": val.imag} - elif hasattr(val,'__dict__'): + elif hasattr(val, '__dict__'): return {k: _dictify(getattr(val, k)) for k in val.__dict__} else: raise TypeError('Type %s not serializable' % type(val)) diff --git a/app/match_dao.py b/app/match_dao.py index 58cc9d4..b13ec89 100644 --- a/app/match_dao.py +++ b/app/match_dao.py @@ -1,10 +1,11 @@ -from flask import g -import sqlite3 from datetime import datetime +from flask import g + from models import Match, Player -def find(id): + +def find(match_id): select = """ select p.fname, p.id, a.score, m.entered_time from player p, attempt a, match m @@ -12,8 +13,8 @@ def find(id): and a.match_id = ? and m.id = a.match_id """ - m = Match(id=id) - cur = g.db.execute(select, [id]) + m = Match(match_id=match_id) + cur = g.db.execute(select, [match_id]) attempts = cur.fetchall() player1 = Player(*attempts[0][:2]) m.player1 = player1 @@ -24,12 +25,14 @@ def find(id): m.entered_time = attempts[0][-1] return m + def find_by_tournament(tournament_id): select = "select id from match where tournament_id = ?" cur = g.db.execute(select, [tournament_id]) matches = [find(row[0]) for row in cur.fetchall()] return matches + def create(player_ids, tournament_id): insert_match = "insert into match (tournament_id) values (?)" insert_entry = """ @@ -37,33 +40,35 @@ def create(player_ids, tournament_id): values (?,?) """ g.db.execute("BEGIN TRANSACTION") - g.db.execute(insert_match,[tournament_id]) + g.db.execute(insert_match, [tournament_id]) cursor = g.db.execute('SELECT max(id) FROM match') match_id = cursor.fetchone()[0] for player_id in player_ids: - g.db.execute(insert_entry,[player_id, match_id]) + g.db.execute(insert_entry, [player_id, match_id]) g.db.commit() + def update(match): - update = """ + update_sql = """ update attempt set score = ?, opp_score = ? where player_id = ? and match_id = ?""" g.db.execute("BEGIN TRANSACTION") - g.db.execute(update,[match.score1,match.score2,match.player1.id,match.id]) - g.db.execute(update,[match.score2,match.score1,match.player2.id,match.id]) + g.db.execute(update_sql, [match.score1, match.score2, match.player1.player_id, match.match_id]) + g.db.execute(update_sql, [match.score2, match.score1, match.player2.player_id, match.match_id]) g.db.execute('update match set entered_time = ? where id = ?', - [datetime.now(),match.id]) + [datetime.now(), match.match_id]) g.db.commit() + def undo(match): - update = """ + update_sql = """ update attempt set score = 0, opp_score = 0 where player_id = ? and match_id = ? """ g.db.execute("BEGIN TRANSACTION") - g.db.execute(update,[match.player1.id,match.id]) - g.db.execute(update,[match.player2.id,match.id]) + g.db.execute(update_sql, [match.player1.player_id, match.match_id]) + g.db.execute(update_sql, [match.player2.player_id, match.match_id]) g.db.execute('update match set entered_time = null where id = ?', - [match.id]) + [match.match_id]) g.db.commit() diff --git a/app/match_dao_test.py b/app/match_dao_test.py deleted file mode 100644 index ed771f9..0000000 --- a/app/match_dao_test.py +++ /dev/null @@ -1,123 +0,0 @@ -import pytest -import sqlite3 - -import match_dao, player_dao, tournament_dao -import config -from models import Player, Match, Tournament - -class FakeG(object): - def __init__(self): - self.db = sqlite3.connect(config.TEST_DATABASE) - script = open(config.SCHEMA).read() - self.db.executescript(script) - self.db.execute('pragma foreign_keys = ON') - -@pytest.fixture -def g(): - fG = FakeG() - match_dao.g = fG - player_dao.g = fG - tournament_dao.g = fG - -def test_create_and_find_match(g): - p = Player("test player") - p2 = Player("test player 2") - player_dao.create(p) - p.id = 1 - player_dao.create(p2) - p2.id = 2 - t = Tournament(0,'','T1','type',0) - tournament_dao.create(t) - t.id = 1 - - match_dao.create([p.id, p2.id], t.id) - retrieved_match = match_dao.find(1) - - assert retrieved_match.id == 1 - assert retrieved_match.player1.fname == p.fname - assert retrieved_match.player2.fname == p2.fname - - -def test_create_and_find_scheduled_by_tournament(g): - p = Player("test player") - p2 = Player("test player 2") - p3 = Player("test player 3") - player_dao.create(p) - p.id = 1 - player_dao.create(p2) - p2.id = 2 - player_dao.create(p3) - p3.id = 3 - t = Tournament(0,'','T1','type',0) - tournament_dao.create(t) - t.id = 1 - t2 = Tournament(0,'','T2','type',0) - tournament_dao.create(t2) - t2.id = 2 - - match_dao.create([p.id,p2.id], t.id) - match_dao.create([p.id,p2.id], t2.id) - match_dao.create([p.id,p3.id], t2.id) - retrieved_matches = match_dao.find_by_tournament(t2.id) - - assert len(retrieved_matches) == 2 - assert retrieved_matches[0].player2.fname == p2.fname - assert retrieved_matches[1].id == 3 - -def test_update_match_with_result(g): - p = Player("test player") - p2 = Player("test player 2") - player_dao.create(p) - p.id = 1 - player_dao.create(p2) - p2.id = 2 - t = Tournament(0,'','T1','type',0) - tournament_dao.create(t) - t.id = 1 - match_dao.create([p.id, p2.id], t.id) - match_id = 1 - match = Match(player1=p,player2=p2,id=match_id) - match.score1 = 19 - match.score2 = 21 - - match_dao.update(match) - retrieved_match = match_dao.find(match_id) - matches = match_dao.find_by_tournament(t.id) - - assert retrieved_match.score1 == 19 - assert retrieved_match.score2 == 21 - assert retrieved_match.player1.fname == p.fname - assert retrieved_match.player2.fname == p2.fname - assert retrieved_match.player1.id == p.id - assert retrieved_match.player2.id == p2.id - assert matches[0].entered_time - -def test_undo_match(g): - p = Player("test player") - p2 = Player("test player 2") - player_dao.create(p) - p.id = 1 - player_dao.create(p2) - p2.id = 2 - t = Tournament(0,'','T1','type',0) - tournament_dao.create(t) - t.id = 1 - match_dao.create([p.id, p2.id], t.id) - match_id = 1 - match = Match(player1=p,player2=p2,id=match_id) - match.score1 = 19 - match.score2 = 21 - match_dao.update(match) - - match_dao.undo(match) - retrieved_match = match_dao.find(match_id) - matches = match_dao.find_by_tournament(t.id) - - assert retrieved_match.score1 == 0 - assert retrieved_match.score2 == 0 - assert retrieved_match.player1.fname == p.fname - assert retrieved_match.player2.fname == p2.fname - assert retrieved_match.player1.id == p.id - assert retrieved_match.player2.id == p2.id - assert not matches[0].entered_time - diff --git a/app/models.py b/app/models.py index 0cb5c9b..009640e 100644 --- a/app/models.py +++ b/app/models.py @@ -1,35 +1,38 @@ class Tournament(object): - def __init__(self, id=id, start_date='', description='', + def __init__(self, tournament_id=0, start_date='', description='', tourn_type='', status=0): - self.id = id + self.tournament_id = tournament_id self.start_date = start_date self.tourn_type = tourn_type self.description = description self.status = int(status) - + def __repr__(self): - return ('<(%d)%s:%s--%s, status=%s>' % - (self.id, self.description, - self.tourn_type, self.start_date,self.status)) + return ('<(%d)%s:%s--%s, status=%s>' % + (self.tournament_id, self.description, + self.tourn_type, self.start_date, self.status)) + class Player(object): - def __init__(self, fname='', id = 0): - self.id = id + def __init__(self, fname='', player_id=0): + self.player_id = player_id self.fname = fname - + def __str__(self): - return '<(%d)%s>' % (self.id, self.fname) + return '<(%d)%s>' % (self.player_id, self.fname) + class Match(object): - def __init__(self, player1=None, player2=None, score1=0, score2=0, id = 0): - self.id = id + def __init__(self, player1=None, player2=None, score1=0, score2=0, match_id=0): + self.match_id = match_id self.player1 = player1 self.player2 = player2 self.score1 = score1 self.score2 = score2 def __repr__(self): - return '<(%d): %s vs %s>' % (self.id, self.player1, self.player2) + return '<(%d): %s vs %s>' % (self.match_id, self.player1, self.player2) + class Standing(object): def __init__(self, pid=0, name=0, win=0, loss=0, tie=0, pf=0, pa=0): @@ -38,19 +41,19 @@ def __init__(self, pid=0, name=0, win=0, loss=0, tie=0, pf=0, pa=0): self.win = win self.loss = loss self.tie = tie - self.pf = pf if isinstance(pf,(int,float)) else 0 - self.pa = pa if isinstance(pa,(int,float)) else 0 + self.pf = pf if isinstance(pf, (int, float)) else 0 + self.pa = pa if isinstance(pa, (int, float)) else 0 self.perc = self.compute_percent() - self.percent_display = "%.1f" % self.perc + self.percent_display = "%.1f" % self.perc def compute_percent(self): games = self.win + self.loss + self.tie if games == 0: p = 0.0 else: - p = 100.0 * (self.win + 0.5*self.tie) / games + p = 100.0 * (self.win + 0.5 * self.tie) / games return p def __repr__(self): - return '(%d)--%s-- W: %d, L: %d' % (self. pid, self.name, self.win, self.loss) + return '(%d)--%s-- W: %d, L: %d' % (self.pid, self.name, self.win, self.loss) diff --git a/app/player_dao.py b/app/player_dao.py index eb345a9..04d7d51 100644 --- a/app/player_dao.py +++ b/app/player_dao.py @@ -1,46 +1,54 @@ +import logging + from flask import g -import sqlite3, logging from models import Player + def find_all(): select = '''select fname, id from player''' cur = g.db.execute(select) return [Player(*row) for row in cur.fetchall()] + def find(player_id): select = "select fname, id from player where id = ?" - cur = g.db.execute(select,[player_id]) + cur = g.db.execute(select, [player_id]) return Player(*cur.fetchone()) + def create(player): insert_player = "insert into player (fname) values (?)" logging.debug(insert_player) - g.db.execute(insert_player,[player.fname]) + g.db.execute(insert_player, [player.fname]) cur = g.db.execute('select last_insert_rowid() from player') id = cur.fetchone()[0] g.db.commit() return id -def delete(id): + +def delete(player_id): delete_player = "delete from player where id = ?" logging.debug(delete_player) - g.db.execute(delete_player,[id]) + g.db.execute(delete_player, [player_id]) g.db.commit() + def enter_tournament(player_id, tournament_id): insert_entry = "insert into entry (player_id, tournament_id) values (?, ?)" logging.debug(insert_entry) - g.db.execute(insert_entry,[player_id,tournament_id]) + g.db.execute(insert_entry, [player_id, tournament_id]) g.db.commit() return find(player_id) + def unenter_tournament(player_id, tournament_id): delete_entry = "delete from entry where player_id = ? and tournament_id= ?" logging.debug(delete_entry) - g.db.execute(delete_entry,[player_id,tournament_id]) + g.db.execute(delete_entry, [player_id, tournament_id]) return find(player_id) + def find_in_tournament(tournament_id): select = ''' select p.fname, p.id from player p, entry e diff --git a/app/scheduler.py b/app/scheduler.py index 8ac7351..c0862ea 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -1,43 +1,61 @@ +import math + import numpy as np + +def bracket(teams): + schedule = [] + num_teams = len(teams) + num_rounds = math.ceil(np.log2(num_teams)) + bracket_size = int(2 ** num_rounds) + for n in range(bracket_size / 2): + comp = bracket_size - n - 1 + player1 = {'player': teams[n], 'seed': n} + if comp < num_teams: + schedule.append((player1, {'player': teams[comp], 'seed': comp})) + else: # player1 gets a bye + schedule.append((player1,)) + return schedule + + def round_robin(teams): g = Graph(len(teams)) schedule = [] - def _choose_pair(first, options): - for option in options: - if g.is_not_edge(first,option): - g.add_edge(first,option) - schedule.append(set([teams[first],teams[option]])) + def _choose_pair(first, rest_opts): + for option in rest_opts: + if g.is_not_edge(first, option): + g.add_edge(first, option) + schedule.append({teams[first], teams[option]}) break while not g.finished(): options = list(g.at_minimum(0)) next_options = g.at_minimum(1) options.extend(next_options) - _choose_pair(options[0],options[1:]) + _choose_pair(options[0], options[1:]) return schedule - + class Graph(object): - def __init__(self,n): + def __init__(self, n): self.n = n - self.a = np.zeros(shape=(n,n)) + self.a = np.zeros(shape=(n, n)) self.num_edges = self.a.sum(axis=0) self.min_edges = 0 - def is_not_edge(self,x,y): - return self.a[x][y] == 0 + def is_not_edge(self, x, y): + return self.a[x][y] == 0 - def add_edge(self,x,y): + def add_edge(self, x, y): self.a[x][y] = 1 self.a[y][x] = 1 self.num_edges = self.a.sum(axis=0) self.min_edges = min(self.num_edges) - - def at_minimum(self,level): + + def at_minimum(self, level): return np.where(self.num_edges == self.min_edges + level)[0] def finished(self): return self.min_edges == (self.n - 1) - + diff --git a/app/scheduler_test.py b/app/scheduler_test.py deleted file mode 100644 index c24a5ed..0000000 --- a/app/scheduler_test.py +++ /dev/null @@ -1,46 +0,0 @@ -import scheduler - -def test_four_teams_scheduled(): - teams = ['alpha','bravo','charlie','delta'] - - schedule = scheduler.round_robin(teams) - - assert len(schedule) == 6 - assert schedule[0] == set(['alpha','bravo']) - assert schedule[1] == set(['charlie','delta']) - assert schedule[2] == set(['alpha','charlie']) - assert schedule[3] == set(['delta','bravo']) - assert schedule[4] == set(['alpha','delta']) - assert schedule[5] == set(['charlie','bravo']) - -def test_three_teams_scheduled(): - teams = ['alpha','bravo','charlie'] - - schedule = scheduler.round_robin(teams) - - assert len(schedule) == 3 - assert schedule[0] == set(['alpha','bravo']) - assert schedule[1] == set(['charlie','alpha']) - assert schedule[2] == set(['bravo','charlie']) - -def test_six_teams_scheduled(): - teams = ['alpha','bravo','charlie','delta','echo','foxtrot'] - - schedule = scheduler.round_robin(teams) - - assert len(schedule) == 15 - -def test_seven_teams_scheduled(): - teams = ['alpha','bravo','charlie','delta','echo','foxtrot','golf'] - - schedule = scheduler.round_robin(teams) - - assert len(schedule) == 21 - -def test_two_teams_scheduled(): - teams = ['alpha','bravo'] - - schedule = scheduler.round_robin(teams) - - assert len(schedule) == 1 - assert schedule[0] == set(['alpha','bravo']) diff --git a/app/standings_dao.py b/app/standings_dao.py index 11425a9..3fe7bf4 100644 --- a/app/standings_dao.py +++ b/app/standings_dao.py @@ -1,30 +1,31 @@ from flask import g -import sqlite3 + from models import Standing + def find(tournament_id): select = """ select pid, fname, - sum(result='W') win, - sum(result='L') loss, - sum(result='T') tie, - sum(score) pts, - sum(opp_score) pts_agst + sum(result='W') win, + sum(result='L') loss, + sum(result='T') tie, + sum(score) pts, + sum(opp_score) pts_agst from ( select p.id pid, p.fname, a.score, a.opp_score, - case when a.score > a.opp_score - then 'W' - else case when a.score < a.opp_score - then 'L' - else case when m.entered_time is not null - then 'T' - else '' - end - end - end as result - from attempt a, player p, match m - where a.player_id = p.id - and a.match_id = m.id + case when a.score > a.opp_score + then 'W' + else case when a.score < a.opp_score + then 'L' + else case when m.entered_time is not null + then 'T' + else '' + end + end + end as result + from attempt a, player p, match m + where a.player_id = p.id + and a.match_id = m.id and m.tournament_id = ? ) group by pid """ diff --git a/app/static/js/create-tournament.js b/app/static/js/create-tournament.js index 8e20e13..52962d5 100644 --- a/app/static/js/create-tournament.js +++ b/app/static/js/create-tournament.js @@ -72,7 +72,7 @@ jQuery(function ($) { }); Page.$description.val(''); } else { - alert('Description field is required.'); + bootbox.alert('Description field is required.'); } }, appendNewTournament: function(data) { diff --git a/app/static/js/edit-tournament.js b/app/static/js/edit-tournament.js index 4902400..cca1791 100644 --- a/app/static/js/edit-tournament.js +++ b/app/static/js/edit-tournament.js @@ -31,10 +31,10 @@ jQuery(function ($) { var all = allPlayers.players; var added = data.players; var added_ids = $.map(added, function(player, i) { - return player.id; + return player.player_id; }); var omitted = $.grep(all, function(player, i){ - return $.inArray(player.id, added_ids) == -1 + return $.inArray(player.player_id, added_ids) == -1 }); Page.appendPlayers(added,Page.$addedPlayers); Page.appendPlayers(omitted,Page.$omittedPlayers); diff --git a/app/static/js/play-tournament.js b/app/static/js/play-tournament.js index aeb8264..6a056fe 100644 --- a/app/static/js/play-tournament.js +++ b/app/static/js/play-tournament.js @@ -78,7 +78,7 @@ jQuery(function ($) { }, displayAllMatches: function(data) { $.each(data.matches, function(i, match) { - var matchTemplate = $(Page.$matchWellTemplate({'id':match.id})); + var matchTemplate = $(Page.$matchWellTemplate({'match_id':match.match_id})); if (match.entered_time) { var matchHtml = Page.$completeMatchTemplate(match); } else { diff --git a/app/templates/404.html b/app/templates/404.html index e7165f7..4c74227 100644 --- a/app/templates/404.html +++ b/app/templates/404.html @@ -2,9 +2,12 @@ {% block title %}Page Not Found{% endblock %} {% block content %}
-

Page Not Found

-

We weren't able to find what you were looking for.

-

Perhaps you typed a URL incorrectly, or the data has changed recently.

-

Return to main page +

Page Not Found

+ +

We weren't able to find what you were looking for.

+ +

Perhaps you typed a URL incorrectly, or the data has changed recently.

+ +

Return to main page

{% endblock %} diff --git a/app/templates/base.html b/app/templates/base.html index b5207ab..593d298 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1,6 +1,6 @@ - + Pools & Brackets @@ -9,31 +9,32 @@ - - -