Skip to content

Commit

Permalink
General Refactor (#39)
Browse files Browse the repository at this point in the history
* Route Creation Centralized

Now the route creation is centralised in Tab, and just inheritted by
all subtabs, so all subtabs just need to focus on creating their JSON
responses, and not the intricacies of Flask route creation. Less copied
code.

* Util to flatten the gui_tree structure

Remove some duplication by providing an easy way to get a flattened
version of the gui_tree

* Frontend tab error looks better

Max page height is now 100% and not 100% + 1/3*100% margin.

* Actually fix the error screen

* Move tab logic into tabs and out of server / queue

Big refactor move the logic around 'what should we do for each tab re-
processing, and viewing. Now instead of an expanding list of if/else
statements in the task queue, there is one if/else in each tab! Yay!

* Fix github icon alignment in firefox/safari

* Shuffle tab files around + fix tidbit local bug

* Mock s3 and add tests ensuring data is entering s3

This allows us to check that plot, table, and image data is serialised
correctly allowing it to be placed into S3.

* Generalise Cumulative Plots

I generalised cumulative plots. So instead of having two plot files for
cumulative time and cumulative distance, now I have 1 file for
cumulative time, distance, elevation, and kudos.

* Fix test using wrong function
  • Loading branch information
JohnScolaro authored Dec 31, 2023
1 parent bafa406 commit 92f41fa
Show file tree
Hide file tree
Showing 39 changed files with 1,055 additions and 808 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ __pycache__
tmp_storage
*.egg-info
build
tmp_image_dir
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ envs/*
!envs/prod.sh
*/logs/*
storage*
local_image_dir
182 changes: 57 additions & 125 deletions backend/active_statistics/gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
from active_statistics.gui.image_tab import ImageTab
from active_statistics.gui.plot_tabs import PlotTab
from active_statistics.gui.tab_group import TabGroup
from active_statistics.gui.table_tab import TableTab
from active_statistics.gui.tabs import Tab
from active_statistics.gui.trivia_tabs import TriviaTab
from active_statistics.statistics.images import polyline_grid, polyline_overlay
from active_statistics.statistics.plots import (
average_heartrate_by_average_speed,
cumulative_distance_travelled,
cumulative_gear_distance,
cumulative_gear_time,
cumulative_time_spent,
github_style_activities,
histogram_of_activity_time,
pace_timeline,
personal_bests,
from active_statistics.gui.tabs import (
average_hr_by_average_speed_tab,
calendar_tab,
cumulative_distance_tab,
cumulative_elevation_tab,
cumulative_gear_distance_tab,
cumulative_gear_time_tab,
cumulative_kudos_tab,
cumulative_time_tab,
detailed_trivia_tab,
flagged_activities_tab,
general_trivia_tab,
histogram_of_activity_times_tab,
min_and_max_distance_activities_tab,
min_and_max_elevation_activities_tab,
pace_timeline_tab,
personal_bests_tab,
polyline_grid_tab,
polyline_overlay_tab,
)
from active_statistics.statistics.tables.flagged_activities import (
flagged_activities_table,
)
from active_statistics.statistics.trivia.detailed_trivia import (
detailed_trivia_processor,
)
from active_statistics.statistics.trivia.min_max_summary_trivia import (
min_and_max_distance_trivia_processor,
min_and_max_elevation_trivia_processor,
)
from active_statistics.statistics.trivia.summary_trivia import general_trivia
from active_statistics.tabs.tab_group import TabGroup
from active_statistics.tabs.tabs import Tab

all_tabs: list[Tab | TabGroup] = [
tab_tree: list[Tab | TabGroup] = [
TabGroup(
name="Summary Data",
key="summary_data",
Expand All @@ -37,90 +30,32 @@
name="Plots",
key="summary_plots",
children=[
PlotTab(
name="Cumulative Time",
description="A cumulative plot of how much time you've logged on Strava for each of your activity types.",
plot_function=cumulative_time_spent.plot,
detailed=False,
),
PlotTab(
name="Cumulative Distance",
description="A cumulative plot of the total distance you've travelled from the activities that you've logged on Strava.",
plot_function=cumulative_distance_travelled.plot,
detailed=False,
),
PlotTab(
name="Calendar",
description="This plot draws inspiration from the GitHub contributions plot to show how much you're running over a calendar year.",
plot_function=github_style_activities.plot,
detailed=False,
),
PlotTab(
name="Average HR by Average Speed",
description="This plot shows your average heartrate by your average speed for all running activities. It needs activities with an average heartrate to work, so if you don't record your heartrate with your activities, then this plot will be blank.",
plot_function=average_heartrate_by_average_speed.plot,
detailed=False,
),
PlotTab(
name="Pace Timeline",
description="This plot shows the pace of your runs on a timeline. Overlaid, there is a 30 day moving average line. At any point on this line, the value is the average pace of all runs 15 days in front and behind it.",
plot_function=pace_timeline.plot,
detailed=False,
),
PlotTab(
name="Histogram of Activity Times",
description="This is a histogram of all your activity start times.",
plot_function=histogram_of_activity_time.plot,
detailed=False,
),
cumulative_time_tab,
cumulative_distance_tab,
cumulative_elevation_tab,
cumulative_kudos_tab,
calendar_tab,
average_hr_by_average_speed_tab,
pace_timeline_tab,
histogram_of_activity_times_tab,
],
),
TabGroup(
name="Tables",
key="summary_tables",
children=[
TriviaTab(
name="Min and Max Distance Activities",
detailed=False,
description="Some Trivia about your longest and shortest Strava activities.",
trivia_processor=min_and_max_distance_trivia_processor,
),
TriviaTab(
name="Min and Max Elevation Activities",
detailed=False,
description="Some Trivia about your hilliest and flattest Strava activities.",
trivia_processor=min_and_max_elevation_trivia_processor,
),
TriviaTab(
name="General Trivia",
detailed=False,
description="Some miscellaneous trivia about your Strava activities.",
trivia_processor=general_trivia,
),
TableTab(
name="Flagged Activities",
detailed=False,
description="If any of your activities have been flagged for cheating on Strava, they will be displayed in a table below.",
table_function=flagged_activities_table,
),
min_and_max_distance_activities_tab,
min_and_max_elevation_activities_tab,
general_trivia_tab,
flagged_activities_tab,
],
),
TabGroup(
name="Images",
key="summary_images",
children=[
ImageTab(
name="Polyline Overlay",
detailed=False,
description="yeet",
create_images_function=polyline_overlay.create_images,
),
ImageTab(
name="Polyline Grid",
detailed=False,
description="yeet",
create_images_function=polyline_grid.create_images,
),
polyline_overlay_tab,
polyline_grid_tab,
],
),
],
Expand All @@ -129,30 +64,27 @@
name="Detailed Data",
key="detailed_data",
children=[
PlotTab(
name="Personal Bests",
description='This is a chart that shows a timeline of your personal bests. It is calculated using Strava\'s "Best Efforts" from all of your activities.',
plot_function=personal_bests.plot,
detailed=True,
),
PlotTab(
name="Cumulative Gear Time",
description="A cumulative plot of the time logged with Strava using different gear.",
plot_function=cumulative_gear_time.plot,
detailed=True,
),
PlotTab(
name="Cumulative Gear Distance",
description="A cumuative plot of the distance travelled while using different gear that you've logged on Strava.",
plot_function=cumulative_gear_distance.plot,
detailed=True,
),
TriviaTab(
name="Detailed Trivia",
detailed=True,
description="Some more in-depth trivia about your Strava activities, which requires downloading your detailed activities to see.",
trivia_processor=detailed_trivia_processor,
),
personal_bests_tab,
cumulative_gear_time_tab,
cumulative_gear_distance_tab,
detailed_trivia_tab,
],
),
]


def get_all_tabs() -> list[Tab]:
"""
Return a flattened list of all the tabs in the tab tree. Just the actual tabs, not the TabGroups.
"""

def flatten(tabs: list[Tab | TabGroup]) -> list[Tab]:
flattened_tabs = []
for tab in tabs:
if isinstance(tab, TabGroup):
flattened_tabs.extend(flatten(tab.children))
else:
flattened_tabs.append(tab)
return flattened_tabs

return flatten(tab_tree)
101 changes: 0 additions & 101 deletions backend/active_statistics/gui/image_tab.py

This file was deleted.

Loading

0 comments on commit 92f41fa

Please sign in to comment.