From 3e4c93631acca9c82e5428979c62cad65ddf8f19 Mon Sep 17 00:00:00 2001 From: Ari Anisfeld Date: Sun, 3 Mar 2024 15:37:23 -0600 Subject: [PATCH] Add capability to download data for analysis (#158) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Describe Your Changes - created downloadable dataTables displayed at `/admin/dashboard_analysis` ## Non-Obvious Technical Information ## Checklist Before Requesting a Review - [x] The code runs successfully. Screenshot 2024-03-03 at 3 26 59 PM --- prijateli_tree/app/routers/administration.py | 39 +++- .../administration/analysis_dashboard.html | 185 ++++++++++++++++++ 2 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 prijateli_tree/app/templates/administration/analysis_dashboard.html diff --git a/prijateli_tree/app/routers/administration.py b/prijateli_tree/app/routers/administration.py index 57db7914..3c6a8ec5 100644 --- a/prijateli_tree/app/routers/administration.py +++ b/prijateli_tree/app/routers/administration.py @@ -24,6 +24,7 @@ from prijateli_tree.app.database import ( Game, + GameAnswer, GamePlayer, GameSession, GameSessionPlayer, @@ -483,7 +484,7 @@ def add_students( detail="Upload file is missing expected fields", ) - for index, student in student_df.iterrows(): + for _, student in student_df.iterrows(): student_in = User( created_by=user.id, **student, @@ -510,3 +511,39 @@ def add_students( redirect_url, status_code=HTTPStatus.FOUND, ) + + +@router.get("/dashboard_analysis", response_class=HTMLResponse) +def analysis_dashboard( + request: Request, + user=Depends(login_manager.optional), + db: Session = Depends(get_db), +) -> Response: + if user is None: + return RedirectResponse("login", status_code=HTTPStatus.FOUND) + + games = db.query(Game).all() + answers = db.query(GameAnswer).all() + students = db.query(User).filter_by(role=ROLE_STUDENT).all() + game_players = db.query(GamePlayer).all() + # student_dict = {} + # for s in students: + # student_dict[s.id] = s + + # for s in sessions: + # players: [str] = [] + # for p in s.players: + # players.append(student_dict[p.user_id].name_str) + # s.player_string = ", ".join(players) + + return templates.TemplateResponse( + "administration/analysis_dashboard.html", + { + "request": request, + "user": user, + "games": games, + "students": students, + "game_players": game_players, + "answers": answers, + }, + ) diff --git a/prijateli_tree/app/templates/administration/analysis_dashboard.html b/prijateli_tree/app/templates/administration/analysis_dashboard.html new file mode 100644 index 00000000..7e024a59 --- /dev/null +++ b/prijateli_tree/app/templates/administration/analysis_dashboard.html @@ -0,0 +1,185 @@ +{% extends "base.html" %} +{% block title %} + PrijateliTree - Analysis Dashboard +{% endblock title %} +{% block helper_script %} + +{% endblock helper_script %} +{% block content %} +
+
+ +
+

Game History

+ Each row is a session-game + + + + + + + + + + + + + + + + {% if games |length == 0 %} + + + + {% endif %} + {% for g in games %} + + + + + + + + + + + {% endfor %} + +
Game History
session idgame idnetwork typenames hiddenpracticen roundsnetwork visiblepoints
There are no game types currently in the system.
{{ g.game_session_id }}{{ g.id }}{{ g.game_type.network }}{{ g.game_type.names_hidden }}{{ g.practice }}{{ g.rounds }}{{ g.is_network_visible }}{{ g.winning_score }}
+
+ + +
+

Game Answers

+ Each row is a guess by player X in game Y during round Z + + + + + + + + + + + + + + + {% if answers|length == 0 %} + + + + {% endif %} + {% for a in answers %} + + + + + + + + + + {% endfor %} + +
Game Answers
session idgame iduser idpositionroundguesscorrect
There are no game types currently in the system.
{{ a.player.game.game_session_id }}{{ a.player.game_id }}{{ a.player.user.id }}{{ a.player.position }}{{ a.round }}{{ a.player_answer }}{{ a.correct_answer }}
+
+ + +
+

Signals

+ Each row is the signal shown to player X in game Y + + + + + + + + + + + + + + {% if answers|length == 0 %} + + + + {% endif %} + {% for gp in game_players %} + + + + + + + + + {% endfor %} + +
Signals
session idgame iduser idpositionroundsignal
There are no game types currently in the system.
{{ gp.game.game_session_id }}{{ gp.game.id }}{{ gp.user.id }}{{ gp.position }}0{{ gp.initial_ball }}
+
+ + +
+

Students

+ Each row is mapping from internal id to cid + + + + + + + + + + {% if answers|length == 0 %} + + + + {% endif %} + {% for s in students %} + + + + + {% endfor %} + +
Students
user idcid
There are no game types currently in the system.
{{ s.id }}{{ s.qualtrics_id }}
+
+ +
+
+{% endblock content %} +
+ +