Skip to content

Commit

Permalink
Not sure all this is actually used
Browse files Browse the repository at this point in the history
  • Loading branch information
Mjboothaus committed May 15, 2023
1 parent c5dbc82 commit a432bd5
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions src/datapipe.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/01_datapipe.ipynb (unless otherwise specified).

__all__ = ['calc_walk_stats', 'load_and_cache_raw_walk_data']

# Cell
import os
import pandas as pd
import activityio as aio
from dateutil.parser import parse
import datetime as dt
import sqlite3 as sql
from pathlib import Path
#import tomli


# Cell
def calc_walk_stats(walk_data):
total_time = dt.timedelta(0)
total_distance = 0

for iHike, hike in enumerate(walk_data):
for hike in walk_data:
total_time += hike.index.max()
# print(iHike+1, walk_date[iHike], hike.index.max(), hike['dist'].max() / 1e3)
total_distance += hike['dist'].max()
total_distance += hike["dist"].max()
total_distance /= 1e3

start_coord = walk_data[0][['lat', 'lon']].iloc[0].tolist()
end_coord = walk_data[-1][['lat', 'lon']].iloc[-1].tolist()
start_coord = walk_data[0][["lat", "lon"]].iloc[0].tolist()
end_coord = walk_data[-1][["lat", "lon"]].iloc[-1].tolist()
return total_time, total_distance, start_coord, end_coord


# TODO: use st.cache() and also look to pre-load and cache/feather data (or similar) - NB: use of @st.cache() below didn't work
def load_and_cache_raw_walk_data(walk_name, sample_freq, conn):
RAW_FIT_FILE_PATH = 'icloud/Data/HealthFit/FIT'
fit_dir = Path.home()/RAW_FIT_FILE_PATH
data_dir = fit_dir/walk_name[0:3]
RAW_FIT_FILE_PATH = "icloud/Data/HealthFit/FIT"
fit_dir = Path.home() / RAW_FIT_FILE_PATH
data_dir = fit_dir / walk_name[:3]
print(data_dir.ls())
data_files = [file for file in os.listdir(data_dir) if file.endswith('.fit')]
data_files = [file for file in os.listdir(data_dir) if file.endswith(".fit")]
walk_files = sorted(data_files)
print(walk_files)

Expand All @@ -45,15 +36,17 @@ def load_and_cache_raw_walk_data(walk_name, sample_freq, conn):
for iFile, file in enumerate(walk_files):
walk_df = pd.DataFrame(aio.read(data_dir + file))
walk_data.append(walk_df)
walk_date.append(parse(file[0:17]))
walk_df['WalkName'] = walk_name
walk_df['WalkNumber'] = iFile
walk_df[['alt', 'dist', 'lat', 'lon', 'speed', 'WalkName', 'WalkNumber']].to_sql('walks', conn, if_exists='append', index=False)

walk_date.append(parse(file[:17]))
walk_df["WalkName"] = walk_name
walk_df["WalkNumber"] = iFile
walk_df[
["alt", "dist", "lat", "lon", "speed", "WalkName", "WalkNumber"]
].to_sql("walks", conn, if_exists="append", index=False)
total_time, total_distance, start_coord, end_coord = calc_walk_stats(walk_data)
walk_stats = [total_time, total_distance, start_coord, end_coord]
#print(start_coord)
walk_merged = pd.concat(walk_data)
points = walk_merged[['lat', 'lon']].values.tolist()
points = [tuple(point) for ipoint, point in enumerate(points) if ipoint % sample_freq == 0]
return walk_data, walk_date, walk_files, points, walk_stats
points = walk_merged[["lat", "lon"]].values.tolist()
points = [
tuple(point) for ipoint, point in enumerate(points) if ipoint % sample_freq == 0
]
return walk_data, walk_date, walk_files, points, walk_stats

0 comments on commit a432bd5

Please sign in to comment.