Skip to content

Commit

Permalink
update pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Davis committed Jan 23, 2024
1 parent 9f0dde7 commit feaf198
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 104 deletions.
28 changes: 28 additions & 0 deletions pages/2_FIT utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import streamlit as st
from pyfitness.load_data import fitfileinfo, fit2df
"""
# Welcome to Vincent's experiments with cycling data files
#### Fit file utilities
- See fit file details
- Export to CSV
Questions, comments, contact me on discord: [Vincent.Davis](discordapp.com/users/vincent.davis)
"""

with st.form(key="FIT file upload"):
fit_buffer_1 = st.file_uploader("Upload a FIT file", type=["fit", "FIT"], key="fit_file1")
submit_button = st.form_submit_button(label='Submit')
if submit_button:
with st.spinner("Processing..."):
fit_file = fit_buffer_1.getbuffer()
df = fit2df(fit_file)
with st.expander("Expand file details"):
if fit_file is not None:
ffi1 = fitfileinfo(fit_file)
st.write(ffi1)
st.download_button(label="Download FIT file as CSV",
data=df.to_csv(index=False).encode('utf-8'),
file_name="fit_to_csv.csv",
mime='text/csv')

90 changes: 90 additions & 0 deletions pages/3_Compare Fit files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import pandas as pd
import streamlit as st
import plotly.express as px
from pyfitness.load_data import fitfileinfo, fit2df

"""
# Welcome to Vincent's experiments with cycling data files
#### Compare interesting stats between two fit files
Questions, comments, contact me on discord: [Vincent.Davis](discordapp.com/users/vincent.davis)
"""

def fit_stats(df: pd.DataFrame):
"""Display the stats of a dataframe"""
st.write("Preview of the FIT file.\nYou can expand this")
st.write(df.head(10))
st.write("Detailed stats of for each fields")
st.write(df.describe())
for field in ['heart_rate', 'power', 'cadence', 'speed', 'distance', 'altitude', 'temperature']:
try:
st.write(f"{field} mean, without zeros: {df[df[field] > 0][field].mean()}")
st.write(f"{field} max: {df[field].max()}")
st.write(f"{field} max change: {df[field].diff().max()}")
fig1 = px.histogram(df[df[f"{field}"] > 0], x=f"{field}", nbins=50,
title=f"{field} distribution", histnorm='probability density')
st.plotly_chart(fig1, theme="streamlit", use_container_width=True)
fig2 = px.histogram(df[df[f"{field}"] > 0][f"{field}"].diff(), nbins=50,
title=f"{field} change distribution", histnorm='probability density')
st.plotly_chart(fig2, theme="streamlit", use_container_width=True)
except Exception as e:
st.write(f" Error with Field name: {field}\nError:\n{e}.")


col1, col2 = st.columns(2)

with col1:
fit_buffer_1 = st.file_uploader("Upload a FIT file", type=["fit", "FIT"], key="fit_file1")
if fit_buffer_1 is not None:
fit_file1 = fit_buffer_1.getbuffer()
# Provide a CSV download option
# st.download_button(label="Download FIT file as CSV",
# data=fit_file1.to_csv(index=False).encode('utf-8'),
# file_name="fit_file1.csv",
# mime='text/csv')

with st.expander("Expand file details"):
if fit_file1 is not None:
ffi1 = fitfileinfo(fit_file1)
st.write(ffi1)
df1 = fit2df(fit_file1)
df1['seconds'] = pd.to_datetime(df1.index).astype(int) / 10 ** 9
df1['seconds'] = df1['seconds'].max() - df1['seconds']
st.write("Enter start and end times")
st.write("These values will be applied to the stats below")
start_time = st.number_input('Start time in seconds', min_value=0, max_value=int(df1.seconds.max()), value=0,
step=1)
end_time = st.number_input('End time in seconds', min_value=0, max_value=int(df1.seconds.max()),
value=int(df1.seconds.max()), step=1)
df_filtered = df1[(df1.seconds >= start_time) & (df1.seconds <= end_time)]
fig = px.line(df_filtered, x="seconds", y="power")
st.plotly_chart(fig, theme="streamlit", use_container_width=True)
fit_stats(df_filtered)

with col2:
fit_buffer_2 = st.file_uploader("Upload a FIT file", type=["fit", "FIT"], key="fit_file2")
if fit_buffer_2 is not None:
fit_file2 = fit_buffer_2.getbuffer()

with st.expander("Expand file details"):
if fit_file2 is not None:
ffi2 = fitfileinfo(fit_file2)
st.write(ffi2)
df2 = fit2df(fit_file2)
df2['seconds'] = pd.to_datetime(df2.index).astype(int) / 10 ** 9
df2['seconds'] = df2['seconds'].max() - df2['seconds']
st.write("Enter start and end times")
st.write("These values will be applied to the stats below")
start_time = st.number_input('Start time in seconds', min_value=0, max_value=int(df2.seconds.max()), value=0,
step=1)
end_time = st.number_input('End time in seconds', min_value=0, max_value=int(df2.seconds.max()),
value=int(df2.seconds.max()), step=1)
df_filtered = df2[(df2.seconds >= start_time) & (df2.seconds <= end_time)]
fig = px.line(df_filtered, x="seconds", y="power")
st.plotly_chart(fig, theme="streamlit", use_container_width=True)
fit_stats(df_filtered)
# Provide a CSV download option
# st.download_button(label="Download FIT file as CSV",
# data=fit_file2.to_csv(index=False).encode('utf-8'),
# file_name="fit_file2.csv",
# mime='text/csv')
File renamed without changes.
25 changes: 0 additions & 25 deletions pages/4_Zwift Profile.py

This file was deleted.

9 changes: 9 additions & 0 deletions pages/5_Efficiency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import streamlit as st
"""
# Welcome to Vincent's experiments with cycling data files
#### Something cool coming soon.
Questions, comments, contact me on discord: [Vincent.Davis](discordapp.com/users/vincent.davis)
"""
File renamed without changes.
File renamed without changes.
81 changes: 2 additions & 79 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,86 +10,9 @@
This is a work in progress.
You can also contact me on discord: [Vincent](discordapp.com/users/vincent.davis)
Questions, comments, contact me on discord: [Vincent.Davis](discordapp.com/users/vincent.davis)
See option in left menu
"""


def fit_stats(df: pd.DataFrame):
"""Display the stats of a dataframe"""
st.write("Preview of the FIT file.\nYou can expand this")
st.write(df.head(10))
st.write("Detailed stats of for each fields")
st.write(df.describe())
for field in ['heart_rate', 'power', 'cadence', 'speed', 'distance', 'altitude', 'temperature']:
try:
st.write(f"{field} mean, without zeros: {df[df[field] > 0][field].mean()}")
st.write(f"{field} max: {df[field].max()}")
st.write(f"{field} max change: {df[field].diff().max()}")
fig1 = px.histogram(df[df[f"{field}"] > 0], x=f"{field}", nbins=50,
title=f"{field} distribution", histnorm='probability density')
st.plotly_chart(fig1, theme="streamlit", use_container_width=True)
fig2 = px.histogram(df[df[f"{field}"] > 0][f"{field}"].diff(), nbins=50,
title=f"{field} change distribution", histnorm='probability density')
st.plotly_chart(fig2, theme="streamlit", use_container_width=True)
except Exception as e:
st.write(f" Error with Field name: {field}\nError:\n{e}.")


col1, col2 = st.columns(2)

with col1:
fit_buffer_1 = st.file_uploader("Upload a FIT file", type=["fit", "FIT"], key="fit_file1")
if fit_buffer_1 is not None:
fit_file1 = fit_buffer_1.getbuffer()
# Provide a CSV download option
# st.download_button(label="Download FIT file as CSV",
# data=fit_file1.to_csv(index=False).encode('utf-8'),
# file_name="fit_file1.csv",
# mime='text/csv')

with st.expander("Expand file details"):
if fit_file1 is not None:
ffi1 = fitfileinfo(fit_file1)
st.write(ffi1)
df1 = fit2df(fit_file1)
df1['seconds'] = pd.to_datetime(df1.index).astype(int) / 10 ** 9
df1['seconds'] = df1['seconds'].max() - df1['seconds']
st.write("Enter start and end times")
st.write("These values will be applied to the stats below")
start_time = st.number_input('Start time in seconds', min_value=0, max_value=int(df1.seconds.max()), value=0,
step=1)
end_time = st.number_input('End time in seconds', min_value=0, max_value=int(df1.seconds.max()),
value=int(df1.seconds.max()), step=1)
df_filtered = df1[(df1.seconds >= start_time) & (df1.seconds <= end_time)]
fig = px.line(df_filtered, x="seconds", y="power")
st.plotly_chart(fig, theme="streamlit", use_container_width=True)
fit_stats(df_filtered)

with col2:
fit_buffer_2 = st.file_uploader("Upload a FIT file", type=["fit", "FIT"], key="fit_file2")
if fit_buffer_2 is not None:
fit_file2 = fit_buffer_2.getbuffer()

with st.expander("Expand file details"):
if fit_file2 is not None:
ffi2 = fitfileinfo(fit_file2)
st.write(ffi2)
df2 = fit2df(fit_file2)
df2['seconds'] = pd.to_datetime(df2.index).astype(int) / 10 ** 9
df2['seconds'] = df2['seconds'].max() - df2['seconds']
st.write("Enter start and end times")
st.write("These values will be applied to the stats below")
start_time = st.number_input('Start time in seconds', min_value=0, max_value=int(df2.seconds.max()), value=0,
step=1)
end_time = st.number_input('End time in seconds', min_value=0, max_value=int(df2.seconds.max()),
value=int(df2.seconds.max()), step=1)
df_filtered = df2[(df2.seconds >= start_time) & (df2.seconds <= end_time)]
fig = px.line(df_filtered, x="seconds", y="power")
st.plotly_chart(fig, theme="streamlit", use_container_width=True)
fit_stats(df_filtered)
# Provide a CSV download option
# st.download_button(label="Download FIT file as CSV",
# data=fit_file2.to_csv(index=False).encode('utf-8'),
# file_name="fit_file2.csv",
# mime='text/csv')

0 comments on commit feaf198

Please sign in to comment.