Stats: limit to recognized games
This commit is contained in:
parent
db5b7e5db9
commit
d15c30f63b
|
@ -18,15 +18,16 @@ from .models import Room
|
||||||
PLOT_WIDTH = 600
|
PLOT_WIDTH = 600
|
||||||
|
|
||||||
|
|
||||||
def get_db_data() -> typing.Tuple[typing.Dict[str, int], typing.Dict[datetime.date, typing.Dict[str, int]]]:
|
def get_db_data(known_games: str) -> typing.Tuple[typing.Dict[str, int], typing.Dict[datetime.date, typing.Dict[str, int]]]:
|
||||||
games_played = defaultdict(Counter)
|
games_played = defaultdict(Counter)
|
||||||
total_games = Counter()
|
total_games = Counter()
|
||||||
cutoff = date.today()-timedelta(days=30)
|
cutoff = date.today()-timedelta(days=30)
|
||||||
room: Room
|
room: Room
|
||||||
for room in select(room for room in Room if room.creation_time >= cutoff):
|
for room in select(room for room in Room if room.creation_time >= cutoff):
|
||||||
for slot in room.seed.slots:
|
for slot in room.seed.slots:
|
||||||
total_games[slot.game] += 1
|
if slot.game in known_games:
|
||||||
games_played[room.creation_time.date()][slot.game] += 1
|
total_games[slot.game] += 1
|
||||||
|
games_played[room.creation_time.date()][slot.game] += 1
|
||||||
return total_games, games_played
|
return total_games, games_played
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,10 +74,12 @@ def create_game_played_figure(all_games_data: typing.Dict[datetime.date, typing.
|
||||||
@app.route('/stats')
|
@app.route('/stats')
|
||||||
@cache.memoize(timeout=60 * 60) # regen once per hour should be plenty
|
@cache.memoize(timeout=60 * 60) # regen once per hour should be plenty
|
||||||
def stats():
|
def stats():
|
||||||
|
from worlds import network_data_package
|
||||||
|
known_games = set(network_data_package["games"])
|
||||||
plot = figure(title="Games Played Per Day", x_axis_type='datetime', x_axis_label="Date",
|
plot = figure(title="Games Played Per Day", x_axis_type='datetime', x_axis_label="Date",
|
||||||
y_axis_label="Games Played", sizing_mode="scale_both", width=PLOT_WIDTH, height=500)
|
y_axis_label="Games Played", sizing_mode="scale_both", width=PLOT_WIDTH, height=500)
|
||||||
|
|
||||||
total_games, games_played = get_db_data()
|
total_games, games_played = get_db_data(known_games)
|
||||||
days = sorted(games_played)
|
days = sorted(games_played)
|
||||||
|
|
||||||
color_palette = get_color_palette(len(total_games))
|
color_palette = get_color_palette(len(total_games))
|
||||||
|
|
Loading…
Reference in New Issue