forked from tcgoetz/GarminDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
369 additions
and
31 deletions.
There are no files selected for viewing
Submodule Fit
updated
from e5a5ec to 85de3d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b8aada92", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import matplotlib.dates as dates\n", | ||
"import math\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"import datetime\n", | ||
"from IPython.display import display, Markdown\n", | ||
"import snakemd\n", | ||
"import pandas as pd\n", | ||
"\n", | ||
"from garmindb import ConfigManager, Graph\n", | ||
"from garmindb.garmindb import GarminSummaryDb, DaysSummary, MonitoringDb, MonitoringHeartRate, Sleep, GarminDb\n", | ||
"from garmindb.summarydb import DaysSummary, WeeksSummary, MonthsSummary, SummaryDb\n", | ||
"\n", | ||
"from jupyter_funcs import format_number" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "2d38e0f7-2ee5-40df-9373-b6485798d541", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def minsFromTime(t):\n", | ||
" return float(t.hour * 3600 + t.minute * 60 + t.second) / 60.0" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7353aa53-92a0-44d9-b476-e050295c4748", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# start date\n", | ||
"start_ts = datetime.datetime.combine(datetime.date(year=2022, month=5, day=1), datetime.datetime.min.time())\n", | ||
"# end date (today)\n", | ||
"end_ts = datetime.datetime.combine(datetime.date.today(), datetime.datetime.max.time())\n", | ||
"\n", | ||
"db_params = ConfigManager.get_db_params()\n", | ||
"garmin_db = GarminDb(db_params)\n", | ||
"sum_db = SummaryDb(db_params, False)\n", | ||
"data = DaysSummary.get_for_period(sum_db, start_ts, end_ts, DaysSummary)\n", | ||
"sleep = Sleep.get_for_period(garmin_db, start_ts, end_ts)\n", | ||
"\n", | ||
"time = [entry.day for entry in data]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e41203c2-d435-4045-9c84-3559b4d3b367", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"stress_avg = [entry.stress_avg for entry in data]\n", | ||
"bb_max = [entry.bb_max for entry in data]\n", | ||
"bb_min = [entry.bb_min for entry in data]\n", | ||
"rem_sleep_max = [minsFromTime(entry.rem_sleep_avg) for entry in data]\n", | ||
"sleep_avg = [minsFromTime(entry.sleep_avg) / 60 for entry in data]\n", | ||
"deep_sleep = [minsFromTime(sleep_event.deep_sleep) for sleep_event in sleep]\n", | ||
"dm_df = pd.DataFrame([time, stress_avg, bb_max, bb_min, rem_sleep_max,deep_sleep, sleep_avg]).T\n", | ||
"dm_df.columns = [\"Date\", \"stress_avg\", \"bb_max\", \"bb_min\", \"rem_sleep_max\", \"deep_sleep\", \"sleep_avg\"]\n", | ||
"# remove the last record 'cause it's noisy sometimes\n", | ||
"dm_df.drop(dm_df.tail(1).index,inplace=True) \n", | ||
"dm_df\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ed0fe315", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"\n", | ||
"columns = { \"stress_avg\" : \n", | ||
" {\n", | ||
" \"label\": \"Stress average\",\n", | ||
" \"trend_marker\": \"--\",\n", | ||
" \"color\": \"red\"\n", | ||
"\n", | ||
" }, \n", | ||
" \"bb_max\": \n", | ||
" {\n", | ||
" \"label\": \"Body battery max\",\n", | ||
" \"trend_marker\": \"--\",\n", | ||
" \"color\": \"orange\"\n", | ||
" },\n", | ||
" \n", | ||
" \"sleep_avg\": \n", | ||
" {\n", | ||
" \"label\": \"Sleep time (hrs)\",\n", | ||
" \"trend_marker\": \"-.\",\n", | ||
" \"color\": \"blue\"\n", | ||
" },\n", | ||
" \"rem_sleep_max\": \n", | ||
" {\n", | ||
" \"label\": \"Rem Sleep time (mins)\",\n", | ||
" \"trend_marker\": \"-\",\n", | ||
" \"color\": \"purple\"\n", | ||
" },\n", | ||
" \n", | ||
" \"deep_sleep\": \n", | ||
" {\n", | ||
" \"label\": \"Deep sleep (mins)\",\n", | ||
" \"trend_marker\": \"-\",\n", | ||
" \"color\": \"green\"\n", | ||
" }\n", | ||
" }\n", | ||
"\n", | ||
"# these are the data columns to plot\n", | ||
"show_cols = {\"deep_sleep\", \"stress_avg\", \"bb_max\"}\n", | ||
"\n", | ||
"fig, host = plt.subplots(figsize=(22,16))\n", | ||
"\n", | ||
"plots = []\n", | ||
"fit_summary = []\n", | ||
"step = 0\n", | ||
"\n", | ||
"for col in show_cols:\n", | ||
" label=columns[col][\"label\"]\n", | ||
" \n", | ||
" ax2 = host.twinx()\n", | ||
" ax2.set_ylabel(label)\n", | ||
" ax2.tick_params(axis='y', labelcolor=columns[col][\"color\"])\n", | ||
"\n", | ||
" # data\n", | ||
" plot, = ax2.plot(dm_df.Date, dm_df[col], 'o', ms=3.0, color=columns[col][\"color\"], label=label)\n", | ||
" plots.append(plot)\n", | ||
" \n", | ||
" # trend\n", | ||
" fitlabel = 'Fit {}'.format(label)\n", | ||
" x_dates = dates.date2num(dm_df.Date)\n", | ||
" trend = np.polyfit(x_dates, dm_df[col].astype(float) , 1)\n", | ||
" fit = np.poly1d(trend)\n", | ||
" x_fit = np.linspace(x_dates.min(), x_dates.max())\n", | ||
" fit, = ax2.plot(dates.num2date(x_fit), fit(x_fit), linestyle=columns[col][\"trend_marker\"], color=columns[col][\"color\"],label=fitlabel)\n", | ||
" plots.append(fit)\n", | ||
" \n", | ||
" ax2.spines['right'].set_position(('outward', step))\n", | ||
" \n", | ||
" step = step + 60\n", | ||
"\n", | ||
" fit_data = fit.get_ydata()\n", | ||
" \n", | ||
" fit_summary.append({\"\": fitlabel, \"min\": math.floor(fit_data.min()), \"max\":math.floor(fit_data.max())})\n", | ||
" \n", | ||
" \n", | ||
" \n", | ||
" \n", | ||
"host.legend(handles=plots, loc='best')\n", | ||
"\n", | ||
"col_label = \"\"\n", | ||
"for col in show_cols:\n", | ||
" if len(col_label):\n", | ||
" col_label += \", \"\n", | ||
" col_label += f\"{col}\"\n", | ||
"\n", | ||
"title = f\"{col_label} from {start_ts.date()} to {end_ts.date()}\"\n", | ||
"\n", | ||
"plt.title(label=title, fontsize=25)\n", | ||
"\n", | ||
"plt.show()\n", | ||
"pd.DataFrame(fit_summary)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cab36f4b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"interpreter": { | ||
"hash": "bfd9857ee3bb42c16b52c1ffe04453343fea53c05fc5f9f2d5ac6a881cdaa36c" | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3.9.10 ('.venv': venv)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
snakemd | ||
snakemd | ||
pandas |
Submodule Plugins
updated
from a0299c to fa1ae9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.