diff --git a/freezing/web/templates/explore/team_weekly_points.html b/freezing/web/templates/explore/team_weekly_points.html index 6b01dab..e7a6c18 100644 --- a/freezing/web/templates/explore/team_weekly_points.html +++ b/freezing/web/templates/explore/team_weekly_points.html @@ -1,54 +1,56 @@ {% extends "base.html" %} -{% block head %} +{% block foot %} + + + {% endblock %} {% block content %} @@ -56,7 +58,7 @@

Team Weekly Points

-
+
+ + + {% endblock %} {% block content %} @@ -109,7 +152,7 @@

-
+
-
+
") @@ -672,32 +659,23 @@ def user_weekly_points(athlete_id): """ ) - cols = [{"id": "week", "label": "Week No.", "type": "string"}] - cols.append({"id": "athlete_{0}".format(athlete_id), "label": "", "type": "number"}) - + # Slow garbage. # This is a really inefficient way to do this, but it's also super simple. And I'm feeling lazy :) week_r = rrule.rrule( rrule.WEEKLY, dtstart=competition_start(), until=now_or_competition_end() ) - rows = [] + weeks = [] + points = [] for i, dt in enumerate(week_r): week_no = dt.date().isocalendar()[1] - # these are 1-based, whereas mysql uses 0-based - cells = [ - {"v": "Week {0}".format(i + 1), "f": "Week {0}".format(i + 1)}, - # Competition always starts at week 1, regardless of isocalendar week no - ] total_score = meta.engine.execute( week_q, athlete_id=athlete_id, week=week_no - 1 ).scalar() # @UndefinedVariable - if total_score is None: - total_score = 0 - cells.append({"v": total_score, "f": "{0:.2f}".format(total_score)}) + weeks.append(i + 1) + points.append(0 if total_score is None else total_score) - rows.append({"c": cells}) - - return gviz_api_jsonify({"cols": cols, "rows": rows}) + return jsonify({"weeks": weeks, "points": points}) @blueprint.route("/team_weekly_points") @@ -729,22 +707,19 @@ def team_weekly_points(): teams = sorted({(r["team_id"], r["team_name"]) for r in res}, key=lambda t: t[1]) scores = {(r["week_num"], r["team_id"]): r["total_score"] for r in res} - team_cols = [ - {"id": f"team_{id}", "label": name, "type": "number"} for id, name in teams - ] - cols = [{"id": "week", "label": "Week No.", "type": "string"}, *team_cols] - - def week_cells(week: int) -> [dict]: - def team_cell(id: int) -> dict: - total_score = scores.get((week, id), 0.0) - return {"v": total_score, "f": "{0:.2f}".format(total_score)} + response = {} + xs = ["x"] + for week in weeks: + xs.append(week + 1) + response["x"] = xs + response["teams"] = [name for id, name in teams] + for id, name in teams: + team = [name] + for week in weeks: + team.append(scores.get((week, id), 0.0)) + response[name] = team - team_cells = [team_cell(id) for id, _ in teams] - return [{"v": f"Week {week + 1}", "f": f"Week {week + 1}"}, *team_cells] - - rows = [{"c": week_cells(week)} for week in weeks] - - return gviz_api_jsonify({"cols": cols, "rows": rows}) + return jsonify(response) @blueprint.route("/team_cumul_points") @@ -945,25 +920,22 @@ def riders_by_lowtemp(): """ ) - cols = [ - {"id": "date", "label": "Date", "type": "date"}, - {"id": "riders", "label": "Riders", "type": "number"}, - {"id": "day_temp_min", "label": "Low Temp", "type": "number"}, - ] - rows = [] for res in meta.scoped_session().execute(q): # @UndefinedVariable if res["low_temp"] is None: # This probably only happens for *today* since that isn't looked up yet. continue - cells = [ - {"v": res["start_date"]}, - {"v": res["riders"], "f": "{0}".format(res["riders"])}, - {"v": res["low_temp"], "f": "{0:.1f}F".format(res["low_temp"])}, - ] - rows.append({"c": cells}) + # res['start_date'] + dt = res["start_date"] + rows.append( + { + "date": {"year": dt.year, "month": dt.month, "day": dt.day}, + "riders": res["riders"], + "low_temp": res["low_temp"], + } + ) - return gviz_api_jsonify({"cols": cols, "rows": rows}) + return jsonify({"data": rows}) @blueprint.route("/distance_by_lowtemp") diff --git a/freezing/web/views/general.py b/freezing/web/views/general.py index c0fd46b..8907a2c 100644 --- a/freezing/web/views/general.py +++ b/freezing/web/views/general.py @@ -398,7 +398,7 @@ def indiv_elev_dist(): @blueprint.route("/explore/distance_by_lowtemp") -def riders_by_lowtemp(): +def distance_by_lowtemp(): return render_template( "explore/distance_by_lowtemp.html", )