示例#1
0
def main(args):
	tables = [ 
		('tournaments', ['CREATE table `tournaments` (tournamentid INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100) UNIQUE, url VARCHAR(100), decklisturl VARCHAR(100), password VARCHAR(100), rounds INT, pairings BOOLEAN, team BOOLEAN)']),
		("players", ["CREATE TABLE `players` (playerid INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), country VARCHAR(100), tournamentid INT, CONSTRAINT fkidtourp FOREIGN KEY (tournamentid) REFERENCES tournaments(tournamentid) ON DELETE CASCADE ON UPDATE CASCADE, UNIQUE KEY player_key (tournamentid, name, country))"]),
		('round', ["CREATE TABLE `round` (roundnum INT, tournamentid INT, CONSTRAINT fkidtourr FOREIGN KEY (tournamentid) REFERENCES tournaments(tournamentid) ON DELETE CASCADE ON UPDATE CASCADE)"]),
		('seatings', ["CREATE TABLE `seatings` (playerid INT UNIQUE, buildtable INT, tournamentid INT, INDEX ididx(playerid), CONSTRAINT fkidseat FOREIGN KEY (playerid) REFERENCES players(playerid) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fkidtours FOREIGN KEY (tournamentid) REFERENCES tournaments(tournamentid) ON DELETE CASCADE ON UPDATE CASCADE)"]),
		('pairings', ["CREATE TABLE `pairings` (playerid INT, round INT, score INT, tablenum INT, tournamentid INT, UNIQUE KEY pairings_key (tournamentid, playerid, round), INDEX ididx(playerid), CONSTRAINT fkidpair FOREIGN KEY (playerid) REFERENCES players(playerid) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fkidtoura FOREIGN KEY (tournamentid) REFERENCES tournaments(tournamentid) ON DELETE CASCADE ON UPDATE CASCADE)"]),
		('deckchecks', ["CREATE TABLE `deckchecks` (playerid INT, teamplayer INT, tournamentid INT, round INT, UNIQUE KEY checks_key (playerid, teamplayer, tournamentid, round), INDEX ididx(playerid), CONSTRAINT fkiddeck FOREIGN KEY (playerid) REFERENCES players(playerid) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fkidtourd FOREIGN KEY (tournamentid) REFERENCES tournaments(tournamentid) ON DELETE CASCADE ON UPDATE CASCADE)"]),
	]
	with DeckDB() as db:
		for (t, _) in reversed(tables):
			with db.cursor() as cur:
				try:
					print "DROP TABLE `%s`" % t
					cur.execute("DROP TABLE `%s`" % t)
				except:
					pass
		db.commit()
	with DeckDB() as db:
		for (_, queries) in tables:
				for q in queries:
					with db.cursor() as cur:
						try:
							print q
							cur.execute(q)
						except:
							pass
		db.commit()
示例#2
0
def docgi():

    print """Content-type: text/html

	<html>
		<head><title>Deck Checks - lookup player</title><link rel='stylesheet' href='style.css' /></head>
		<body>
			<h1>Lookup player</h1>
"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, output)
        roundnum = db.get_round(db.getEventId(form["event"].value))
        output.pageHeader(db, form['event'].value, roundnum, form)
    if not check_login(output, form['event'].value, form['password'].value
                       if 'password' in form else '', 'get_player'):
        return
    if "name" in form:
        print_player(form["event"].value, form["name"].value, form)
    else:
        print """
<form>
	<input type='hidden' name='password' value='%s'/>
	Enter name: <input type='text' name='name' /><input type='submit' />
</form>
<p>
You can enter any fragment of a name, all matches will be returned. Searches are case-insensitive. Typos will not match.
</p>
""" % (form['password'].value if 'password' in form else '')

    output.printLink(form, 'root', 'Return to menu')
    print """
示例#3
0
def docgi():
    print """Content-type: text/html

	<html>
		<head><title>Deck Checks - top tables</title><link rel='stylesheet' href='style.css' /></head>
		<body>
			<h1>Top tables</h1>
"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, output)
        roundnum = db.get_round(db.getEventId(form["event"].value))
        output.pageHeader(db, form['event'].value, roundnum, form)
    if not check_login(output, form['event'].value, form['password'].value
                       if 'password' in form else '', 'top_tables'):
        return
    print """ 
			<p>Key: 
				<span class='undefeated'>undefeated</span> 
				<span class='live'>definitely live for top 8</span> 
				<span class='marginal'>possibility of top 8</span> 
				<span class='unlikely'>theoretically possible</span> 
				<span class='dead'>cannot top 8</span> 
			</p>
"""
    top_tables(form["event"].value, form)
    output.printLink(form, 'export?type=top', 'Download as TSV')
    output.printLink(form, 'root', 'Return to menu')
    print """
示例#4
0
def import_pairings_reader(event, reader, clear, roundnum, wltr):
	count = 0
	with DeckDB() as db:
		try:
			id = db.getEventId(event)
			db.deleteRow('round', {'tournamentid':id})
			db.insert('round', [roundnum, id])
		except Exception as e:
			output.printMessage("Failed to update current round number: %s" % e)
		if clear:
			output.printMessage("Deleting previous data");
			db.deleteRow('pairings', {'tournamentid':id, 'round':roundnum})
		for row in reader:
			if len(row) == 0: continue
			try:
				(table, player1, player2) = parseRow(row, wltr)
				count = count + 1
			except Exception as e:
				output.printMessage("Failed to import row %s: %s" % (row, e))
				continue

			try:
				insertPairing(db, id, roundnum, table, player1)
			except Exception as e:
				output.printMessage("Failed to import row %s: %s" % (row, e))
			if False:
				try:
					insertPairing(db, id, roundnum, table, player2)
				except Exception as e:
					output.printMessage("Failed to import row %s: %s" % (row, e))
	output.printMessage("Imported %d pairings" % count)
示例#5
0
def import_seatings_reader(event, reader, clear):
	count = 0
	with DeckDB() as db:
		id = db.getEventId(event)
		if clear:
			output.printMessage("Deleting previous data");
			db.deleteRow('pairings', {'tournamentid':id})
			db.deleteRow('seatings', {'tournamentid':id})
			db.deleteRow('players', {'tournamentid':id})
		for row in reader:
			print str(row)
			output.printMessage("%s"%row)
			if len(row) == 0: continue
			try:
				(table, player1, player2) = parseSeatingRow(row)
				count = count + 1
			except Exception as e:
				output.printMessage("Failed to import row %s: %s" % (row, e))
				continue

			try:
				insertSeating(db, id, table, player1)
			except Exception as e:
				output.printMessage("Failed to import row %s: %s" % (row, e))
			if player2:
				try:
					insertSeating(db, id, table, player2)
				except Exception as e:
					output.printMessage("Failed to import row %s: %s" % (row, e))
	output.printMessage("Imported %d seatings" % count)
示例#6
0
def allchecks(tournament, form):

    try:
        with DeckDB() as db:
            id = db.getEventId(tournament)
            maxrounds = db.get_round(id)
            headers = output.getHeaders(maxrounds)

            checks = db.get_all_checks(id)
            total_names = set()
            for rn in checks.keys():
                total_names = total_names | set(
                    [name for (name, seat) in checks[rn]])
            output.printMessage("Total players checked: %s" % len(total_names))
            for rn in reversed(sorted(checks.keys())):
                output.heading("Round %s" % rn)
                names = set([name for (name, seat) in checks[rn]])
                output.printMessage("Total players checked this round: %s" %
                                    len(names))
                with output.table(*headers) as table:
                    for name in names:
                        players = db.get_players(id, name)
                        for p in players:
                            output.printPlayer(p,
                                               db,
                                               id,
                                               form,
                                               newbutton=('deckcheck', {
                                                   'player': p[0],
                                                   'remove': 'True',
                                                   'round': rn
                                               }, 'Remove check'))

    except Exception as e:
        output.printMessage("Failed to print check history: %s" % (e))
示例#7
0
def docgi():
    print """Content-type: text/html

	<html>
		<head><title>Deck Checks - lookup table</title><link rel='stylesheet' href='style.css' /></head>
		<body>
			<h1>Lookup table</h1>
"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, output)
        roundnum = db.get_round(db.getEventId(form["event"].value))
        output.pageHeader(db, form['event'].value, roundnum, form)
    if not check_login(output, form['event'].value, form['password'].value
                       if 'password' in form else '', 'get_table'):
        return
    if "table" in form:
        print_table(form["event"].value, int(form["table"].value), form)
    else:
        print """
<form>
	<input type='hidden' name='password' value='%s'/>
	Enter table number: <input type='text' name='table' /><input type='submit' />
</form>
""" % (form['password'].value if 'password' in form else '')

    output.printLink(form, 'root', 'Return to menu')
    print """
示例#8
0
def docgi():
    print """Content-type: text/html

	<html>
		<head><title>Pairings</title><link rel='stylesheet' href='style.css' /></head>
		<body>
"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, output)
        maxrounds = db.get_round(db.getEventId(form["event"].value))
        roundnum = int(form['round'].value) if 'round' in form else maxrounds
        print "<h1>Pairings for %s round %s</h1>" % (db.getEventName(
            form['event'].value), roundnum)
        output.pageHeader(db, form['event'].value, roundnum, form)
    if not check_login(output, form['event'].value, form['password'].value
                       if 'password' in form else '', 'pairings'):
        return
    print '<div class="links">|'
    for i in range(1, maxrounds + 1):
        print output.makeLink(form, 'pairings?round=%s' % i, str(i))
        print '|'
    print '</div>'
    pairings(form["event"].value, roundnum)
    output.printLink(form, 'export?type=pairings&amp;round=%s' % roundnum,
                     'Download as TSV')
    output.printLink(form, 'root', 'Return to menu')
    print """
示例#9
0
文件: lists.py 项目: mjj29/deckchecks
def lists(tournament):

    try:
        with DeckDB() as db:
            id = db.getEventId(tournament)

            decklisturl = db.getDecklistUrl(id)
            if 'json' in decklisturl:
                t = CFBTournament({
                    'id': id,
                    'name': 'Event',
                    'pairingsurl': db.getEventUrl(id),
                    'decklist_list_url': decklisturl
                })
                online = set([
                    name.lower().strip()
                    for name in t.getPlayersWithDecklists()
                ])
            else:
                online = set()
            records = db.getAllPlayers(id)
            tables = {}
            for (name, buildtable) in records:
                tables[name.lower().strip()] = (name, buildtable)
            players = set(
                [name.lower().strip() for (name, buildtable) in records])
            paperLists = players - online
            extraLists = online - players

            paperTables = {}
            for player in paperLists:
                (name, buildtable) = tables[player]
                paperTables[name] = buildtable

            output.printMessage(
                "Players we can't find the list online for by name comparison:"
            )

            with output.table("Name", "Build table") as table:
                for player, tbl in sorted(paperTables.iteritems(),
                                          key=lambda (k, v): (v, k)):
                    try:
                        table.printRow(player, tbl)
                    except Exception as e:
                        print "<p>%s</p>" % str(e)

            output.printMessage(
                "Lists we seem to have with no player in the event (yet, could be byes):"
            )

            with output.table("Name") as table:
                for player in sorted(extraLists):
                    try:
                        table.printRow(player)
                    except Exception as e:
                        print "<p>%s</p>" % str(e)

    except Exception as e:
        output.printMessage("Failed to print lists: %s" % (e))
示例#10
0
def top_tables(tournament, form):

    try:
        with DeckDB() as db:
            id = db.getEventId(tournament)

            currentRound = db.get_round(id)
            totalRounds = db.getEventRounds(id)
            playersWithEachByes = db.getPlayersForEachByeNumber(id)

            (currentMarginalThreshold, currentTop8Threshold,
             undefeatedThreshold) = calculateTop8Threshold(
                 playersWithEachByes, totalRounds, currentRound)
            output.printMessage(
                "Players with at least %s points can still make top 8" %
                currentTop8Threshold)

            tables = db.get_top_tables(id)
            with output.table("Table", "Score", "Name", "Previous Checks",
                              "Score", "Name", "Previous Checks") as table:
                for row in tables:
                    try:
                        score = row[0]
                        tablenum = row[1]
                        (player1, player2) = db.get_table(id, tablenum)
                        (name1, score1, _, _) = player1
                        (name2, score2, _, _) = player2
                        prevChecks1 = db.getPreviousChecks(id, name1)
                        prevChecks2 = db.getPreviousChecks(id, name2)
                        if (score1 == undefeatedThreshold
                                or score2 == undefeatedThreshold):
                            table.setNextRowType('undefeated')
                        elif (score1 < currentMarginalThreshold
                              and score2 < currentMarginalThreshold):
                            table.setNextRowType('dead')
                        elif (score1 >= currentTop8Threshold
                              or score2 >= currentTop8Threshold):
                            table.setNextRowType('live')
                        elif (score1 > currentMarginalThreshold
                              or score2 > currentMarginalThreshold):
                            table.setNextRowType('marginal')
                        else:
                            table.setNextRowType('unlikely')
                        table.printRow(
                            output.makeLink(form,
                                            'get_table?table=%s' % tablenum,
                                            tablenum), score1,
                            output.makeLink(form, 'get_player?name=%s' % name1,
                                            name1),
                            ", ".join([str(x) for x in prevChecks1]), score2,
                            output.makeLink(form, 'get_player?name=%s' % name2,
                                            name2),
                            ", ".join([str(x) for x in prevChecks2]))
                    except Exception as e:
                        print str(e)

    except Exception as e:
        output.printMessage("Failed to print top tables: %s" % (e))
示例#11
0
def update_settings(tournament, name, url, rounds, password, pairings, team, decklisturl):
	try:
		with DeckDB() as db:
			id = db.getEventId(tournament)
			db.update('tournaments', {'tournamentid':id}, {'name':name, 'url':url, 'rounds':rounds, 'password':password, 'pairings':'1' if pairings else '0', 'team':'1' if team else '0', 'decklisturl':decklisturl})
			output.printMessage('Tournament settings updated')

	except Exception as e:
		output.printMessage("Failed to update settings: %s" % (e))
示例#12
0
def main(args):
    with DeckDB() as db:
        db.checkEvent(args[0], output)
    table = None
    player = None
    try:
        table = int(args[1])
    except:
        player = args[1]
    mark_checked(args[0], player=player, table=table)
示例#13
0
def addevent(event, url, decklisturl=None):
    with DeckDB() as db:
        try:
            db.insert('tournaments',
                      [event, url, 15, '', False, False, decklisturl])
            id = db.getEventId(event)
            db.insert('round', [0, id])
        except Exception as e:
            output.printMessage("Failed to add event: %s" % e)
        output.printMessage("Added event %s" % event)
示例#14
0
def main(args):
    with DeckDB() as db:
        db.checkEvent(args[1], TextOutput())
    if "top" == args[0]:
        top_tables.output = TSVOutput()
        top_tables.top_tables(args[1])
    elif "checks" == args[0]:
        allchecks.output = TSVOutput()
        allchecks.allchecks(args[1])
    else:
        print "Type must be top or checks"
示例#15
0
def main(args):
	with DeckDB() as db:
		db.checkEvent(args[0], output)
	if args[1] == "seatings":
		import_seatings_file(args[0], args[2], True)
	elif args[1] == "pairings":
		import_pairings_file(args[0], args[2], True, 0)
	elif args[1] == "url":
		importAllDataURL(args[0], args[2], True)
	else:
		print "Unknown type "+args[1]
示例#16
0
def docgi():
    print """Content-type: text/html

	<html>
		<head><title>Deck Checks - check history</title><link rel='stylesheet' href='style.css' /></head>
		<body>
			<h1>History of checks</h1>
"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, output)
        roundnum = db.get_round(db.getEventId(form["event"].value))
        output.pageHeader(db, form['event'].value, roundnum, form)
    if not check_login(output, form['event'].value, form['password'].value
                       if 'password' in form else '', 'allchecks'):
        return
    if "tables" in form and form['tables']:
        deckcheck.output = output
        for table in form['tables'].value.split():
            if ':' in table:
                (table, seat) = table.split(':')
                seat = seat.strip().lower()
                if 'a' == seat: seat = 0
                elif 'b' == seat: seat = 1
                elif 'c' == seat: seat = 2
                else: raise Exception("Seat must be A, B or C")
                deckcheck.mark_checked(form["event"].value,
                                       table=table,
                                       seat=seat,
                                       roundnum=form['round'].value)
            else:
                deckcheck.mark_checked(form["event"].value,
                                       table=table,
                                       roundnum=form['round'].value)
    else:
        print """
			<h2>Check tables</h2>
			<p>Enter one table per line (table number for individual, table:seat for team (eg '7:A')</p>
			<form>
			<input type='hidden' name='password' value='%s'/>
			<textarea name='tables' cols='30' rows='5'></textarea>
			<br/>
			<input type='text' name='round' value='%s'/>
			<br/>
			<input type='submit' value='Mark as checked' />
			</form>
""" % (form['password'].value if 'password' in form else '', roundnum)
        allchecks(form["event"].value, form)
    output.printLink(form, 'export?type=checks', 'Download as TSV')
    output.printLink(form, 'root', 'Return to menu')
    print """
示例#17
0
def docgi():
	print """Content-type: text/html

	<html>
		<head><title>Deck Checks - event settings</title><link rel='stylesheet' href='style.css' /></head>
		<body>
			<h1>Event Settings</h1>
"""
	form = cgi.FieldStorage()
	with DeckDB() as db:
		db.checkEvent(form["event"].value, output)
		currentround = db.get_round(db.getEventId(form['event'].value))
		output.pageHeader(db, form['event'].value, currentround, form)
	if not check_login(output, form['event'].value, form['password'].value if 'password' in form else '', 'settings'):
		return
	if 'name' in form:
	
		update_settings(form['event'].value, form['name'].value, form['url'].value if 'url' in form else '', form['rounds'].value if 'rounds' in form else '', form['newpassword'].value if 'newpassword' in form else '', form['pairings'].value if 'pairings' in form else '', form['team'].value if 'team' in form else '', form['decklisturl'].value if 'decklisturl' in form else '')
	else:
		with DeckDB() as db:
			id = db.getEventId(form['event'].value)
			(name, url, rounds, password, pairings, team, decklisturl) = db.getEventSettings(id)
		print """
<p>Update settings:</p>
<form method='post'>
<input type='hidden' name='password' value='%s'/>
Name: <input type='text' name='name' value='%s'/><br/>
URL: <input type='text' name='url' value='%s'/><br/>
Rounds: <input type='text' name='rounds' value='%s'/><br/>
Password: <input type='text' name='newpassword' value='%s'/><br/>
Pairings: <input type='checkbox' name='pairings' %s/><br/>
Team: <input type='checkbox' name='team' %s/><br/>
Decklist URL: <input type='text' name='decklisturl' value='%s'/><br/>
<input type='submit' />
</form>
""" % (form['password'].value if 'password' in form else '', name, url, rounds, password, 'checked="true"' if pairings else '', 'checked="true"' if team else '', decklisturl or '')
	output.printLink(form, 'root', 'Return to menu')
	print """
示例#18
0
def print_settings(tournament):
	output.printMessage('Current Settings')
	try:
		with DeckDB() as db:
			id = db.getEventId(tournament)
			(name, url, rounds, password, pairings, team, decklisturl) = db.getEventSettings(id)
			output.printMessage('Event name = %s' % name)
			output.printMessage('Event url = %s' % url)
			output.printMessage('Event max rounds = %s' % rounds)
			output.printMessage('Event password = %s' % password)
			output.printMessage('Event pairings = %s' % pairings)
			output.printMessage('Event team = %s' % team)
			output.printMessage('Event decklisturl = %s' % decklisturl)
	except Exception as e:
		output.printMessage('Failed to get settings: %s' % e)
示例#19
0
def print_player(event, name, form):

    try:
        with DeckDB() as db:
            id = db.getEventId(event)
            players = db.get_players(id, name)
            maxrounds = db.get_round(id)

            headers = output.getHeaders(maxrounds)

            with output.table(*headers):
                for player in players:
                    output.printPlayer(player, db, id, form)
    except Exception as e:
        output.printMessage("Failed to lookup player %s: %s" % (name, e))
示例#20
0
def check_login(output, event, password, redirect):
	with DeckDB() as db:
		id = db.getEventId(event)
		evPass = db.getEventPassword(id)
		if evPass == password:
			return True
		else:
			print """
<h2>Login required</h2>
<form method='post' action='%s'>
Password: <input type='text' name='password'/><br/>
<input type='submit' />
</form>
""" % redirect
			return False
示例#21
0
def print_table(tournament, tablenumber, form):

    with DeckDB() as db:
        id = db.getEventId(tournament)
        maxrounds = db.get_round(id)
        headers = output.getHeaders(maxrounds)

        if db.isEventTeam(tournament):
            output.createButton(form, "deckcheck", {
                "table": tablenumber,
                'seat': '0'
            }, "Check Seat A this round")
            output.createButton(form, "deckcheck", {
                "table": tablenumber,
                'seat': '1'
            }, "Check Seat B this round")
            output.createButton(form, "deckcheck", {
                "table": tablenumber,
                'seat': '2'
            }, "Check Seat C this round")
        else:
            output.createButton(form, "deckcheck", {"table": tablenumber},
                                "Check table this round")

        for r in range(maxrounds, 0, -1):
            try:
                (player1, player2) = db.get_table(id, tablenumber, roundnum=r)
                output.heading("Players at table %s in round %s" %
                               (tablenumber, r))

                with output.table(*headers):
                    output.printPlayer(player1, db, id, form)
                    output.printPlayer(player2, db, id, form)

            except Exception as e:
                output.printComment(
                    "Failed to lookup table %s in round %s: %s" %
                    (tablenumber, r, e))

        try:
            output.heading("Players at build table %s" % tablenumber)
            players = db.get_build_table(id, tablenumber)
            with output.table(*headers):
                for player in players:
                    output.printPlayer(player, db, id, form)
        except Exception as e:
            output.printMessage("Failed to lookup table %s: %s" %
                                (tablenumber, e))
示例#22
0
def pairings(tournament, roundnum=None):

    try:
        with DeckDB() as db:
            id = db.getEventId(tournament)
            pairings = db.get_pairings(id, roundnum)
            with output.table("Table", "Name", "Score", "Name",
                              "Score") as table:
                for row in pairings:
                    try:
                        table.printRow(*row)
                    except:
                        pass

    except Exception as e:
        output.printMessage("Failed to print pairings: %s" % (e))
示例#23
0
def docgi():
    print """Content-type: text/html

	<html>
		<head><title>Deck Checks - mark as checked</title><link rel='stylesheet' href='style.css' /></head>
		<body>
			<h1>Deck Checks</h1>
"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, output)
        roundnum = db.get_round(db.getEventId(form["event"].value))
        output.pageHeader(db, form['event'].value, roundnum, form)
    if not check_login(output, form['event'].value, form['password'].value
                       if 'password' in form else '', 'deckcheck'):
        return
    if "table" in form and form['table']:
        mark_checked(form["event"].value,
                     table=int(form["table"].value),
                     seat=int(form["seat"].value) if 'seat' in form else 0,
                     remove=form["remove"] if 'remove' in form else False,
                     roundnum=form['round'].value if 'round' in form else None)
        print """<script language="JavaScript" type="text/javascript"><!--
		setTimeout("window.history.go(-1)",3000);
		//--></script>"""

    elif 'player' in form and form['player']:
        mark_checked(form["event"].value,
                     player=form["player"].value,
                     seat=int(form["seat"].value) if 'seat' in form else 0,
                     remove=form["remove"] if 'remove' in form else False,
                     roundnum=form['round'].value if 'round' in form else None)
        print """<script language="JavaScript" type="text/javascript"><!--
		setTimeout("window.history.go(-2)",5000);
		//--></script>"""
    else:
        print """
<form>
			<input type='hidden' name='password' value='%s'/>
	Enter table number: <input type='text' name='table' /><input type='submit' /><br/>
	Enter player name: <input type='text' name='player' /><input type='submit' />
</form>
""" % (form['password'].value if 'password' in form else '')

    output.printLink(form, 'root', 'Return to menu')
    print """
示例#24
0
def import_all_xml(event, data, clear):
	with DeckDB() as db:
		id = db.getEventId(event)
		if clear:
			output.printMessage("Deleting previous data");
			db.deleteRow('pairings', {'tournamentid':id})
			db.deleteRow('seatings', {'tournamentid':id})
			db.deleteRow('players', {'tournamentid':id})

		root = ET.fromstring(data)
		participants = {}
		for team in root.findall('participation')[0].findall('team'):
			name = team.get('name')
			pid = team.get('id')
			participants[pid] = (name, '', 0)
		for person in root.findall('participation')[0].findall('person'):
			name = person.get('last')+', '+person.get('first')
			pid = person.get('id')
			participants[pid] = (name, person.get('country'), 0)

		roundnum = 0
		for rnd in root.findall('matches')[0].findall('round'):
			roundnum = rnd.get('number')
			output.printMessage('Importing data for round %s' % roundnum)
			table = 0
			for match in rnd.findall('match'):
				try:
					table = table + 1
					player1 = participants[match.get('person')]
					player2 = participants[match.get('opponent')]
					if int(roundnum) == 1:
						insertSeating(db, id, table, player1)
						insertSeating(db, id, table, player2)
					insertPairing(db, id, roundnum, table, player1)
					insertPairing(db, id, roundnum, table, player2)
				except Exception as e:
					output.printMessage('Failed to import match: %s' % e)
		output.printMessage("Imported %s rounds" % roundnum)
		try:
			db.deleteRow('round', {'tournamentid':id})
			db.insert('round', [roundnum, id])
		except Exception as e:
			output.printMessage("Failed to update current round number: %s" % e)
示例#25
0
def docgi():
    print """Content-type: text/html

	<html>
		<head><title>Deck Checks - recommend checks</title><link rel='stylesheet' href='style.css' /></head>
		<body>
			<h1>Recommended Checks</h1>
"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, output)
        roundnum = db.get_round(db.getEventId(form["event"].value))
        output.pageHeader(db, form['event'].value, roundnum, form)
    if not check_login(output, form['event'].value, form['password'].value
                       if 'password' in form else '', 'recommend'):
        return
    recommend_checks(form["event"].value, form)
    output.printLink(form, 'root', 'Return to menu')
    print """
示例#26
0
文件: lists.py 项目: mjj29/deckchecks
def docgi():
    print """Content-type: text/html

	<html>
		<head><title>Lists</title><link rel='stylesheet' href='style.css' /></head>
		<body>
"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, output)
        print "<h1>Lists excluding online</h1>"
        roundnum = db.get_round(db.getEventId(form["event"].value))
        output.pageHeader(db, form['event'].value, roundnum, form)
        print "<p>List of players who didn't submit online decklists, sorted by build table / starting table. Note, if this is not a CFB event with online decklists then this will just be the master list of all players by table numbers, with byes first on table '0', alphabetically.</p>"

    if not check_login(output, form['event'].value, form['password'].value
                       if 'password' in form else '', 'lists'):
        return
    lists(form["event"].value)
    output.printLink(form, 'root', 'Return to menu')
    print """
示例#27
0
def docgi():
    print """Content-type: text/html

	<html>
		<head><title>Pairings</title><link rel='stylesheet' href='style.css' /></head>
		<body>
"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, output)
        hasPairings = db.hasEventPairings(db.getEventId(form["event"].value))
        if not hasPairings:
            raise Exception("Pairings not enabled for this event")
        maxrounds = db.get_round(db.getEventId(form["event"].value))
        roundnum = int(form['round'].value) if 'round' in form else maxrounds
        print "<h1>Pairings for %s round %s</h1>" % (db.getEventName(
            form['event'].value), roundnum)
    print '<div class="links">|'
    for i in range(1, maxrounds + 1):
        print output.makeLink(form, 'pairings?round=%s' % i, str(i))
        print '|'
    print '</div>'
    pairings(form["event"].value, roundnum)
    print """
示例#28
0
def recommend_checks(tournament, form):
    try:
        with DeckDB() as db:
            id = db.getEventId(tournament)
            targetTables = db.get_recommendations(id, n=6, rand=False)
            randomTables = db.get_recommendations(id, n=4, rand=True)
            maxrounds = db.get_round(id)
            headers = output.getHeaders(maxrounds)
            for (tables, name) in [(targetTables, "Tables live for Top 8"),
                                   (randomTables, "Random Tables")]:
                output.heading(name)
                for (tablenumber, player1, player2) in tables:
                    output.heading("Table %s" % tablenumber)
                    if db.isEventTeam(tournament):
                        output.createButton(form, "deckcheck", {
                            "table": tablenumber,
                            'seat': '0'
                        }, "Checked Seat A this round")
                        output.createButton(form, "deckcheck", {
                            "table": tablenumber,
                            'seat': '1'
                        }, "Checked Seat B this round")
                        output.createButton(form, "deckcheck", {
                            "table": tablenumber,
                            'seat': '2'
                        }, "Checked Seat C this round")
                    else:
                        output.createButton(form, "deckcheck",
                                            {"table": tablenumber},
                                            "Checked this round")
                    with output.table(*headers):
                        output.printPlayer(player1, db, id, form)
                        output.printPlayer(player2, db, id, form)

    except Exception as e:
        output.printMessage("Failed to print recommendations: %s" % (e))
示例#29
0
def docgi():
    print """Content-type: text/tab-separated-values
Content-disposition: attachment; filename=data.tsv

"""
    form = cgi.FieldStorage()
    with DeckDB() as db:
        db.checkEvent(form["event"].value, TextOutput())
    if 'type' in form and form['type']:
        if "top" == form['type'].value:
            top_tables.output = TSVOutput()
            top_tables.top_tables(form["event"].value, {})
        elif "checks" == form['type'].value:
            allchecks.output = TSVOutput()
            allchecks.allchecks(form["event"].value, {})
        elif "pairings" == form['type'].value:
            pairings.output = TSVOutput()
            pairings.pairings(
                form["event"].value,
                int(form['round'].value) if 'round' in form else None)
        else:
            print "ERROR: type must be top, pairings or checks"
    else:
        print "ERROR: must specify type"
示例#30
0
def main(args):
	with DeckDB() as db:
		db.checkEvent(args[0], output)

	
	print_settings(args[0])