Exemple #1
0
def stats(session):
	show_id = flask.request.values.get("show")
	shows = botinteract.get_data(["shows"])
	if show_id is not None:
		show_id = show_id.lower()
		games = shows.get(show_id, {}).get("games", {})
		for game in games.values():
		    game["show_id"] = show_id
	else:
		games = {}
		for show_id, show in shows.items():
			show_name = show.get("name", show_id)
			for game_id, game in show['games'].items():
				game["show_id"] = show_id
				game["show"] = show_name
				games["%s-%s" % (show_id, game_id)] = game
		show_id = None
	shows = [{"name": show.get("name", name), "id": name} for name, show in shows.items()]
	shows = sorted(shows, key=lambda show: show["name"].lower())
	stats = botinteract.get_data(["stats"])
	# Calculate totals
	for statkey, stat in stats.items():
		stat['total'] = sum(g.get('stats',{}).get(statkey,0) for g in games.values())
	# Make our lives easier in the template - make sure all our defaults exist, and turn our major dicts into lists
	for gamekey, game in games.items():
		game.setdefault('display', game['name'])
		game.setdefault('stats', {})
		for statkey in stats.keys():
			game['stats'].setdefault(statkey, 0)
		game.setdefault('gamekey', gamekey)
		game.setdefault('votes', {})
		game['votecount'] = len(game['votes'])
		game['votegood'] = sum(game['votes'].values())
		if game['votecount']:
			game['voteperc'] = 100.0 * game['votegood'] / game['votecount']
		else:
			game['voteperc'] = 0.0
	for statkey, stat in stats.items():
		stat.setdefault('singular', statkey)
		stat.setdefault('statkey', statkey)
	games = list(games.values())
	games.sort(key=lambda g: g['display'].upper())
	votegames = [g for g in games if g['votecount']]
	votegames.sort(key=lambda g: -g['voteperc'])
	stats = list(stats.values())
	stats.sort(key=lambda s: -s['total'])
	# Calculate graph datasets
	if 'show' in game:
		game_name_format = "%(display)s (%(show)s)"
	else:
		game_name_format = "%(display)s"
	for stat in stats:
		stat['graphdata'] = [(game_name_format % game, game['stats'][stat['statkey']]) for game in games if game['stats'][stat['statkey']]]
		stat['graphdata'].sort(key=lambda pt:-pt[1])

	return flask.render_template('stats.html', games=games, votegames=votegames, stats=stats, session=session, shows=shows, show_id=show_id)
Exemple #2
0
def api_votes():
	game_id = botinteract.get_current_game()
	if game_id is None:
		return "-"
	show = botinteract.get_show()
	data = botinteract.get_data(["shows", show, "games", game_id, "votes"])
	count = len(data)
	good = sum(data.values())
	return "%.0f%% (%d/%d)" % (100*good/count, good, count)
Exemple #3
0
def api_stats(stat):
	game_id = botinteract.get_current_game()
	if game_id is None:
		return "-"
	show = botinteract.get_show()
	count = botinteract.get_data(["shows", show, "games", game_id, "stats", stat])
	if not count:
		count = 0
	return str(count)
Exemple #4
0
def votes(session):
	data = botinteract.get_data('games')
	current_game_id = botinteract.get_current_game()

	if current_game_id not in data:
		current_game_id = None
	games = [{
		"id": game_id,
		"name": game["name"],
		"display": game.get("display", game["name"]),
		"vote": game.get("votes", {}).get(session["user"]),
	} for game_id,game in data.items()]
	games.sort(key=lambda game:(1 if game['id'] == current_game_id else 2, game['display'].upper()))

	return flask.render_template("votes.html", games=games, current_game_id=current_game_id, session=session)
Exemple #5
0
def stats(session):
    data = botinteract.get_data([])

    games = data['games']
    stats = data['stats']
    # Calculate totals
    for statkey, stat in stats.items():
        stat['total'] = sum(
            g.get('stats', {}).get(statkey, 0) for g in games.values())
    # Make our lives easier in the template - make sure all our defaults exist, and turn our major dicts into lists
    for gamekey, game in games.items():
        game.setdefault('display', game['name'])
        game.setdefault('stats', {})
        for statkey in stats.keys():
            game['stats'].setdefault(statkey, 0)
        game.setdefault('gamekey', gamekey)
        game.setdefault('votes', {})
        game['votecount'] = len(game['votes'])
        game['votegood'] = sum(game['votes'].values())
        if game['votecount']:
            game['voteperc'] = 100.0 * game['votegood'] / game['votecount']
        else:
            game['voteperc'] = 0.0
    for statkey, stat in stats.items():
        stat.setdefault('singular', statkey)
        stat.setdefault('statkey', statkey)
    games = list(games.values())
    games.sort(key=lambda g: g['display'].upper())
    votegames = [g for g in games if g['votecount']]
    votegames.sort(key=lambda g: -g['voteperc'])
    stats = list(stats.values())
    stats.sort(key=lambda s: -s['total'])
    # Calculate graph datasets
    for stat in stats:
        stat['graphdata'] = [(game['display'], game['stats'][stat['statkey']])
                             for game in games
                             if game['stats'][stat['statkey']]]
        stat['graphdata'].sort(key=lambda pt: -pt[1])

    return flask.render_template('stats.html',
                                 games=games,
                                 votegames=votegames,
                                 stats=stats,
                                 session=session)
Exemple #6
0
def commands(session):
    mode = flask.request.values.get("mode", "responses")
    assert mode in ("responses", "explanations")

    data = botinteract.get_data(mode)

    # Prepare the data, and group equivalent commands together
    data_reverse = {}
    for command, response in data.items():
        if isinstance(response, list):
            response = tuple(response)
        elif not isinstance(response, tuple):
            response = (response,)
        data_reverse.setdefault(response, []).append(command)
        # Sort some things
    for commands in data_reverse.values():
        commands.sort()
    data = [(commands, response) for response, commands in data_reverse.items()]
    data.sort()

    return flask.render_template("commands.html", commands=data, len=len, mode=mode, session=session)
Exemple #7
0
def votes(session):
	data = botinteract.get_data('shows')
	current_game_id = botinteract.get_current_game()
	current_show_id = botinteract.get_show()

	if current_game_id not in data[current_show_id]["games"]:
		current_game_id = None
	shows = [{
		"id": show_id,
		"name": show.get("name", show_id),
		"games": sorted([{
				"id": game_id,
				"name": game["name"],
				"display": game.get("display", game["name"]),
				"vote": game.get("votes", {}).get(session["user"]),
			    } for game_id,game in show['games'].items()],
			key=lambda game: (1 if game['id'] == current_game_id and show_id == current_show_id else 2, game['display'].upper()))
	} for show_id, show in data.items()]
	shows.sort(key=lambda show: (1 if show["id"] == current_show_id and current_game_id is not None else 2, show["name"].upper()))

	return flask.render_template("votes.html", shows=shows, current_show_id=current_show_id, current_game_id=current_game_id, session=session)
Exemple #8
0
def commands(session):
	mode = flask.request.values.get('mode', 'responses')
	assert(mode in ('responses', 'explanations'))

	data = botinteract.get_data(mode)

	# Prepare the data, and group equivalent commands together
	data_reverse = {}
	for command, response_data in data.items():
		if isinstance(response_data['response'], list):
			response_data['response'] = tuple(response_data['response'])
		elif not isinstance(response_data['response'], tuple):
			response_data['response'] = (response_data['response'],)
		response_data = (response_data['response'], response_data['access'])
		data_reverse.setdefault(response_data, []).append(command)
	# Sort some things
	for commands in data_reverse.values():
		commands.sort()
	data = [(commands, response[0], response[1]) for response, commands in data_reverse.items()]
	data.sort()

	return flask.render_template("commands.html", commands=data, len=len, mode=mode, session=session)
Exemple #9
0
def stats(session):
	data = botinteract.get_data([])

	games = data['games']
	stats = data['stats']
	# Calculate totals
	for statkey, stat in stats.items():
		stat['total'] = sum(g.get('stats',{}).get(statkey,0) for g in games.values())
	# Make our lives easier in the template - make sure all our defaults exist, and turn our major dicts into lists
	for gamekey, game in games.items():
		game.setdefault('display', game['name'])
		game.setdefault('stats', {})
		for statkey in stats.keys():
			game['stats'].setdefault(statkey, 0)
		game.setdefault('gamekey', gamekey)
		game.setdefault('votes', {})
		game['votecount'] = len(game['votes'])
		game['votegood'] = sum(game['votes'].values())
		if game['votecount']:
			game['voteperc'] = 100.0 * game['votegood'] / game['votecount']
		else:
			game['voteperc'] = 0.0
	for statkey, stat in stats.items():
		stat.setdefault('singular', statkey)
		stat.setdefault('statkey', statkey)
	games = list(games.values())
	games.sort(key=lambda g: g['display'].upper())
	votegames = [g for g in games if g['votecount']]
	votegames.sort(key=lambda g: -g['voteperc'])
	stats = list(stats.values())
	stats.sort(key=lambda s: -s['total'])
	# Calculate graph datasets
	for stat in stats:
		stat['graphdata'] = [(game['display'], game['stats'][stat['statkey']]) for game in games if game['stats'][stat['statkey']]]
		stat['graphdata'].sort(key=lambda pt:-pt[1])

	return flask.render_template('stats.html', games=games, votegames=votegames, stats=stats, session=session)
Exemple #10
0
def spam(session):
    data = botinteract.get_data('spam_rules')
    return flask.render_template("spam.html", rules=data, session=session)
Exemple #11
0
def spam(session):
	data = botinteract.get_data('spam_rules')
	return flask.render_template("spam.html", rules=data, session=session)
Exemple #12
0
def stormcount():
	today = datetime.datetime.now(TIMEZONE).date().toordinal()
	data = botinteract.get_data("storm")
	if data.get("date") != today:
		return "0"
	return str(data.get("count", 0))