diff --git a/app/routers/score.py b/app/routers/score.py index 1e6cad1..4540454 100644 --- a/app/routers/score.py +++ b/app/routers/score.py @@ -41,4 +41,9 @@ def get_scores_for_deck_by_date(deck_id: int, db=Depends(get_db)): query = db.query(sub_query).filter(sub_query.c.row_number == 1) results = query.all() - return list(map(lambda x: x._asdict(), results)) + return list( + map( + lambda x: {k: v for k, v in x._asdict().items() if k not in ["row_number"]}, + results, + ) + ) diff --git a/app/static/css/base.css b/app/static/css/base.css index 8ec8305..e085e3d 100644 --- a/app/static/css/base.css +++ b/app/static/css/base.css @@ -153,4 +153,13 @@ footer #about { footer #credits { float: right; margin-right: 10px; +} + +/* + * Clearfix + */ +.clearfix::after { + content: ""; + clear: both; + display: table; } \ No newline at end of file diff --git a/app/static/js/player_detail.js b/app/static/js/player_detail.js new file mode 100644 index 0000000..bcf7753 --- /dev/null +++ b/app/static/js/player_detail.js @@ -0,0 +1,41 @@ +$(document).ready(function() { + (async () => await updateGraph())() +}); + +async function updateGraph() { + deck_info = $('ul a').map(function(idx, a) { + return { + "name": $(a).html(), + "id": parseInt($(a).attr('href').split('/')[2]) + } + }) + + deck_info_and_scores = deck_info.map(function(idx, info) { + return fetch('/api/score/' + info['id'] + '/by_date').then(result => result.json()).then(result => {return { + "label": info['name'], + "data": result + }}) + }) + + resolved_data = Promise.all(deck_info_and_scores) + window.chart = new Chart( + document.getElementById('graph_canvas'), + { + type: 'line', + data: { + datasets: await resolved_data + }, + options: { + scales: { + x: { + type: 'time' + } + }, + parsing: { + xAxisKey: 'date', + yAxisKey: 'score' + } + } + } + ) +} \ No newline at end of file diff --git a/app/templates/players/detail.html b/app/templates/players/detail.html index c1e023d..67715b4 100644 --- a/app/templates/players/detail.html +++ b/app/templates/players/detail.html @@ -4,17 +4,30 @@ {% block head %} {{ super() }} + + + + + {% endblock %} {% block content %}

This is the page for player {{ player.name }} who has id {{ player.id }}

{% if decks %} -

Decks

- +
+
+

Decks

+ +
+
+ +
+
+ {% endif %} {% endblock %}