Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
[MOD] demo
Browse files Browse the repository at this point in the history
  • Loading branch information
marcjulianschwarz committed Feb 17, 2022
1 parent 243ff45 commit c67be5a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,30 @@ To install watchlib simply run:
pip install watchlib
```

## Update to newest version
```
pip install --upgrade watchlib
```

## Run watchlib demonstrator
First you will have to download the demonstrator Python file [here](https://github.com/marcjulianschwarz/watchlib/blob/main/demonstrator/watchlib_demonstrator.py).

To run it, you will need to install streamlit:
```
pip install streamlit
```
and watchlib:
```
pip install watchlib
```

After you have installed both modules, navigate to the `watchlib_demonstrator.py` file and run the following command:
```
streamlit run watchlib_demonstrator.py
```


## How to export Apple Watch health data
To use this Python package you first have to export the health data like this:

1. Open *Health* app
2. Open your profile in the upper right corner
Expand Down
25 changes: 18 additions & 7 deletions demonstrator/watchlib_demonstrator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys
sys.path.append("../")

import streamlit as st
import streamlit.components.v1 as components
from datetime import datetime as dt
Expand All @@ -9,14 +6,15 @@
from watchlib.animation import WorkoutAnimation, constants, WorkoutAnimationConfig
from watchlib.filtering import CountryFilter, DiagonalBBoxFilter, TimeFilter, FilterPipeline
from watchlib.data_handler import DataLoader, CacheHandler
from watchlib.analysis import heart_rate_variability, bpm
from watchlib.plot import plot_ecg
from watchlib.analysis import heart_rate_variability, bpm, stats
from watchlib.plot import plot_ecg, distribution_for
from watchlib.utils.structs import ECG, WorkoutRoute


def header():
st.write("# Watchlib Demo")


def set_selected_route():
st.session_state.selected_route = [
route for route in st.session_state.all_routes if route.name == st.session_state.route_option][0]
Expand Down Expand Up @@ -229,19 +227,32 @@ def start():
f"{len(list(data))} dataframes have been loaded.")

if "data" in st.session_state:
st.sidebar.selectbox('Select a key', list(
st.session_state.data.keys()), key="data_option", on_change=set_selected_data)
st.sidebar.selectbox('Select a key', sorted(list(
st.session_state.data.keys())), key="data_option", on_change=set_selected_data)
selected_data = st.session_state.data[st.session_state.data_option]
st.session_state.selected_data = selected_data

if "data" in st.session_state:
st.write("## Health Data")

# left_c, right_c = st.columns(2)
# with left_c:
st.write("### Distribution")
st.slider("Bins", min_value=0, max_value=400, value=35, step=1, key="bins")
st.write(distribution_for(st.session_state.selected_data, st.session_state.bins))
# with right_c:
# _max, _min = stats(st.session_state.selected_data)
# st.write("### Stats")
# st.write(f"Max: {_max}")
# st.write(f"Min {_min}")

if st.button("Show dataframe"):
if st.session_state.selected_data is None:
st.error("Please specify a health path in the sidebar first.")
else:
st.write(f"## {st.session_state.data_option}")
st.write(st.session_state.selected_data)



if __name__ == "__main__":
Expand Down

0 comments on commit c67be5a

Please sign in to comment.