Skip to content

Commit c0b0798

Browse files
committed
minor
1 parent 1b94c0d commit c0b0798

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

activityStats2.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3.10
1+
#!/usr/bin/env python3.11
22

33
"""
44
Stats for Strava App V2.
@@ -13,41 +13,38 @@
1313
import pandas as pd
1414

1515
# requirements
16-
# pip3.10 install numpy pandas
16+
# pip3.11 install numpy pandas
1717

18-
if len(sys.argv) == 2:
19-
session = sys.argv[1]
20-
else:
21-
session = "SessionIdPlaceholder"
18+
session = sys.argv[1] if len(sys.argv) == 2 else "SessionIdPlaceholder" # noqa: PLR2004
2219

2320
# Path(__file__).parents[0] = location of current Python script
24-
pathStatsExport = Path(__file__).parents[0] / "download" / session
25-
if not pathStatsExport.is_dir():
21+
path_stats_export = Path(__file__).parents[0] / "download" / session
22+
if not path_stats_export.is_dir():
2623
# raise FileNotFoundError(f"session {session} invalid")
2724
sys.stderr.write(f"session {session} invalid")
2825
sys.exit(1)
2926

30-
pathToActivityListJsonDump = pathStatsExport / "activityList.json"
31-
if not pathToActivityListJsonDump.is_file():
27+
path_to_activity_list_json_dump = path_stats_export / "activityList.json"
28+
if not path_to_activity_list_json_dump.is_file():
3229
# raise FileNotFoundError(f"file activityList.json missing")
3330
sys.stderr.write("file activityList.json missing")
3431
sys.exit(1)
3532

36-
p = pathStatsExport / "activityStats2_year.json"
33+
p = path_stats_export / "activityStats2_year.json"
3734
if p.is_file():
3835
# nothing to do
39-
exit()
36+
sys.exit()
4037

4138

42-
def read_activityListJson(pathToActivityListJsonDump: Path) -> pd.DataFrame:
39+
def read_activity_list_json(path_to_activity_list_json_dump: Path) -> pd.DataFrame:
4340
"""
4441
Read "activityList.json" file.
4542
4643
parse date columns
4744
return DataFrame
4845
"""
4946
# read json to DataFrame
50-
df_all = pd.read_json(pathToActivityListJsonDump) # type: ignore
47+
df_all = pd.read_json(path_to_activity_list_json_dump) # type: ignore
5148

5249
# print(sorted(df.columns))
5350
# 'achievement_count', 'athlete', 'athlete_count', 'average_cadence', 'average_heartrate', 'average_speed', 'average_temp', 'average_watts', 'comment_count', 'commute', 'device_watts', 'display_hide_heartrate_option', 'distance', 'elapsed_time', 'elev_high', 'elev_low', 'end_latlng', 'external_id', 'flagged', 'from_accepted_tag', 'gear_id', 'has_heartrate', 'has_kudoed', 'heartrate_opt_out', 'id', 'kilojoules', 'km/h', 'kudos_count', 'location_city', 'location_country', 'location_state', 'manual', 'map', 'max_heartrate', 'max_speed', 'moving_time', 'name', 'photo_count', 'pr_count', 'private', 'resource_state', 'sport_type', 'start_date', 'start_date_local', 'start_latlng', 'timezone', 'total_elevation_gain', 'total_photo_count', 'trainer', 'type', 'upload_id', 'upload_id_str', 'utc_offset', 'visibility', 'workout_type', 'x_date', 'x_dist_start_end_km', 'x_elev_%', 'x_elev_m/km', 'x_end_locality', 'x_gear_name', 'x_km', 'x_max_km/h', 'x_max_mph', 'x_mi', 'x_min', 'x_min/km', 'x_min/mi', 'x_mph', 'x_nearest_city_start', 'x_start_h', 'x_start_locality', 'x_url' # noqa: E501 # cspell:disable-line
@@ -58,17 +55,17 @@ def read_activityListJson(pathToActivityListJsonDump: Path) -> pd.DataFrame:
5855
df_all[col] = pd.to_datetime(df_all[col]) # type: ignore
5956

6057
# filter out act < 10min
61-
df_all = df_all[df_all["x_min"] >= 10]
58+
df_all = df_all[df_all["x_min"] >= 10] # noqa: PLR2004
6259

6360
return df_all
6461

6562

66-
def gen_types_time_series(df_all: pd.DataFrame, pathStatsExport: Path) -> None:
63+
def gen_types_time_series(df_all: pd.DataFrame, _path_stats_export: Path) -> None:
6764
"""
6865
Perform GROUP BY aggregation for time_freq (month, week, quarter, year) and activity_type.
6966
7067
exports resulting df as JSONs to pathStatsExport
71-
"""
68+
""" # noqa: E501
7269
df = df_all[
7370
[
7471
"id",
@@ -222,8 +219,7 @@ def types_time_series_json_export(
222219
cols.extend(measures)
223220

224221
for act_type, data in df.groupby(level="type"): # type: ignore
225-
data = data.droplevel("type")
226-
data.reset_index(inplace=True)
222+
data = data.droplevel("type").reset_index() # noqa: PLW2901
227223
if freq == "week":
228224
data["date"] = data["date"].dt.strftime("%Y-W%W")
229225
elif freq == "month":
@@ -237,7 +233,7 @@ def types_time_series_json_export(
237233
d[col] = data[col].values.tolist() # type: ignore
238234
json_data[act_type] = d
239235

240-
with Path(pathStatsExport / f"activityStats2_{freq}.json").open(
236+
with Path(path_stats_export / f"activityStats2_{freq}.json").open(
241237
"w",
242238
encoding="UTF-8",
243239
) as fh:
@@ -251,7 +247,7 @@ def types_time_series_json_export(
251247

252248

253249
if __name__ == "__main__":
254-
df_all = read_activityListJson(
255-
pathToActivityListJsonDump=pathToActivityListJsonDump,
250+
df_all = read_activity_list_json(
251+
path_to_activity_list_json_dump=path_to_activity_list_json_dump,
256252
)
257-
gen_types_time_series(df_all=df_all, pathStatsExport=pathStatsExport)
253+
gen_types_time_series(df_all=df_all, _path_stats_export=path_stats_export)

0 commit comments

Comments
 (0)