{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyNzwzBxhj/ENtPvpC3sc3iq",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"b7d1a1e77d344a8e9b65fa0887859b6f": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ButtonModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "ButtonModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "ButtonView",
"button_style": "",
"description": "Download CSV",
"disabled": false,
"icon": "",
"layout": "IPY_MODEL_f4c0da5a7d7641bdab1fdf2d2a5a434c",
"style": "IPY_MODEL_c57ce657dd1b49bea27a6d5f9f232205",
"tooltip": ""
}
},
"f4c0da5a7d7641bdab1fdf2d2a5a434c": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"c57ce657dd1b49bea27a6d5f9f232205": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ButtonStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "ButtonStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"button_color": null,
"font_weight": ""
}
}
}
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "markdown",
"source": [
"# chatGPT analysis of Garmin stats"
],
"metadata": {
"id": "gsR7Ay0KuqGl"
}
},
{
"cell_type": "markdown",
"source": [
"## Setup"
],
"metadata": {
"id": "AuY_RBBruxkA"
}
},
{
"cell_type": "markdown",
"source": [
"Install [Garth](https://github.com/matin/garth) to download stats from Garmin Connect."
],
"metadata": {
"id": "yg5Hzyrbu2SV"
}
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "2YBVvyYJnRug"
},
"outputs": [],
"source": [
"%pip install garth >& /dev/null"
]
},
{
"cell_type": "markdown",
"source": [
"Set location of session tokens."
],
"metadata": {
"id": "ZTzxkfQQu-fJ"
}
},
{
"cell_type": "code",
"source": [
"GARTH_HOME = \"drive/MyDrive/garth\""
],
"metadata": {
"id": "FPkG6WzOnfdP"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Mount Google Drive to access session tokens."
],
"metadata": {
"id": "QeSi-VipvBa3"
}
},
{
"cell_type": "code",
"source": [
"from google.colab import drive\n",
"drive.mount(\"/content/drive\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "5nWiUmA5nh8k",
"outputId": "f8acf58a-3275-4b6f-b2b5-05c85a4585af"
},
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Mounted at /content/drive\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"Attempt to resume session. Otherwise, log in. Save updated session in both cases."
],
"metadata": {
"id": "youB5vWsvGwv"
}
},
{
"cell_type": "code",
"source": [
"import garth\n",
"from garth.exc import GarthException\n",
"from getpass import getpass\n",
"\n",
"try:\n",
" garth.resume(GARTH_HOME)\n",
" garth.client.username\n",
"except (FileNotFoundError, GarthException):\n",
" email = input(\"Email: \")\n",
" password = getpass(\"Password: \")\n",
" garth.client.login(email, password)\n",
"\n",
"garth.save(GARTH_HOME)"
],
"metadata": {
"id": "jFYjpHMwnmRF"
},
"execution_count": 4,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Import Pandas and define period for analysis."
],
"metadata": {
"id": "s09TVMCTvSEy"
}
},
{
"cell_type": "code",
"source": [
"import pandas as pd\n",
"\n",
"DAYS = 365 * 3"
],
"metadata": {
"id": "r18SHYm6n_i9"
},
"execution_count": 5,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Query stats"
],
"metadata": {
"id": "fHsEkJQNo_o0"
}
},
{
"cell_type": "markdown",
"source": [
"### Sleep"
],
"metadata": {
"id": "JFdWsRJHnw1H"
}
},
{
"cell_type": "code",
"source": [
"from datetime import timedelta\n",
"\n",
"sleep = pd.DataFrame(garth.DailySleep.list(period=DAYS))\n",
"sleep[\"calendar_date\"] = sleep[\"calendar_date\"].apply(lambda x: x - timedelta(days=1))\n",
"sleep.set_index(\"calendar_date\", inplace=True)\n",
"sleep.rename(columns={\"value\": \"sleep_quality\"}, inplace=True)"
],
"metadata": {
"id": "cKH4pkwtoHt9"
},
"execution_count": 6,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"### Steps"
],
"metadata": {
"id": "KXe5NV8HoYxZ"
}
},
{
"cell_type": "code",
"source": [
"steps = pd.DataFrame(garth.DailySteps.list(period=DAYS))\n",
"steps.set_index(\"calendar_date\", inplace=True)"
],
"metadata": {
"id": "uaG8YTPjobC8"
},
"execution_count": 7,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"### Stress"
],
"metadata": {
"id": "YbV8jW-QofcS"
}
},
{
"cell_type": "code",
"source": [
"stress = pd.DataFrame(garth.DailyStress.list(period=DAYS))\n",
"stress.set_index(\"calendar_date\", inplace=True)\n",
"stress[\"high_stress_duration\"].fillna(0, inplace=True)\n",
"stress[\"medium_stress_duration\"].fillna(0, inplace=True)"
],
"metadata": {
"id": "lThQ23Rjog-Z"
},
"execution_count": 8,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"### Intensity minutes"
],
"metadata": {
"id": "-NjiZ8OKoj3-"
}
},
{
"cell_type": "code",
"source": [
"im = pd.DataFrame(garth.DailyIntensityMinutes.list(period=DAYS))\n",
"im.set_index(\"calendar_date\", inplace=True)\n",
"im[\"intensity_minutes\"] = im[\"moderate_value\"] + 2 * im[\"vigorous_value\"]\n",
"im.rename(\n",
" columns={\n",
" \"weekly_goal\": \"intensity_minutes_goal\",\n",
" \"moderate_value\": \"moderate_intensity_minutes\",\n",
" \"vigorous_value\": \"vigorous_intensity_minutes\",\n",
" },\n",
" inplace=True\n",
")"
],
"metadata": {
"id": "9BcHMdXzol6U"
},
"execution_count": 9,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Join stats"
],
"metadata": {
"id": "NEaoXU7JpCve"
}
},
{
"cell_type": "code",
"source": [
"stats = (\n",
" sleep\n",
" .join(steps)\n",
" .join(stress)\n",
" .join(im)\n",
")\n",
"stats"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 475
},
"id": "hcLk5XzdpFZP",
"outputId": "9c7b40e3-7c58-4978-bcbe-38d20513199f"
},
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" sleep_quality total_steps total_distance step_goal \\\n",
"calendar_date \n",
"2021-09-08 64 2728 2259 8830 \n",
"2021-09-09 65 7601 6338 7610 \n",
"2021-09-10 81 25646 19797 7610 \n",
"2021-09-11 0 6869 5701 9420 \n",
"2021-09-13 76 17210 15660 8970 \n",
"... ... ... ... ... \n",
"2023-09-27 85 6367 5349 8740 \n",
"2023-09-28 80 2363 2072 8510 \n",
"2023-09-29 86 11261 8675 7280 \n",
"2023-09-30 79 8130 6742 7680 \n",
"2023-10-01 46 25434 21006 7770 \n",
"\n",
" overall_stress_level rest_stress_duration \\\n",
"calendar_date \n",
"2021-09-08 26 50100 \n",
"2021-09-09 32 29100 \n",
"2021-09-10 31 30780 \n",
"2021-09-11 28 37380 \n",
"2021-09-13 37 25440 \n",
"... ... ... \n",
"2023-09-27 30 34980 \n",
"2023-09-28 29 40740 \n",
"2023-09-29 38 32880 \n",
"2023-09-30 29 42120 \n",
"2023-10-01 30 36900 \n",
"\n",
" low_stress_duration medium_stress_duration \\\n",
"calendar_date \n",
"2021-09-08 14400 10020 \n",
"2021-09-09 24420 8520 \n",
"2021-09-10 16500 5880 \n",
"2021-09-11 18720 7380 \n",
"2021-09-13 16440 13680 \n",
"... ... ... \n",
"2023-09-27 20460 6600 \n",
"2023-09-28 23580 8520 \n",
"2023-09-29 11520 11400 \n",
"2023-09-30 15660 9840 \n",
"2023-10-01 8640 7680 \n",
"\n",
" high_stress_duration intensity_minutes_goal \\\n",
"calendar_date \n",
"2021-09-08 1500.0 150 \n",
"2021-09-09 1680.0 150 \n",
"2021-09-10 4020.0 150 \n",
"2021-09-11 1020.0 150 \n",
"2021-09-13 4200.0 150 \n",
"... ... ... \n",
"2023-09-27 1200.0 150 \n",
"2023-09-28 1200.0 150 \n",
"2023-09-29 8160.0 150 \n",
"2023-09-30 900.0 150 \n",
"2023-10-01 4140.0 150 \n",
"\n",
" moderate_intensity_minutes vigorous_intensity_minutes \\\n",
"calendar_date \n",
"2021-09-08 0.0 0.0 \n",
"2021-09-09 0.0 0.0 \n",
"2021-09-10 117.0 46.0 \n",
"2021-09-11 0.0 0.0 \n",
"2021-09-13 7.0 41.0 \n",
"... ... ... \n",
"2023-09-27 0.0 0.0 \n",
"2023-09-28 0.0 0.0 \n",
"2023-09-29 44.0 2.0 \n",
"2023-09-30 0.0 0.0 \n",
"2023-10-01 77.0 56.0 \n",
"\n",
" intensity_minutes \n",
"calendar_date \n",
"2021-09-08 0.0 \n",
"2021-09-09 0.0 \n",
"2021-09-10 209.0 \n",
"2021-09-11 0.0 \n",
"2021-09-13 89.0 \n",
"... ... \n",
"2023-09-27 0.0 \n",
"2023-09-28 0.0 \n",
"2023-09-29 48.0 \n",
"2023-09-30 0.0 \n",
"2023-10-01 189.0 \n",
"\n",
"[743 rows x 13 columns]"
],
"text/html": [
"\n",
"
| \n", " | sleep_quality | \n", "total_steps | \n", "total_distance | \n", "step_goal | \n", "overall_stress_level | \n", "rest_stress_duration | \n", "low_stress_duration | \n", "medium_stress_duration | \n", "high_stress_duration | \n", "intensity_minutes_goal | \n", "moderate_intensity_minutes | \n", "vigorous_intensity_minutes | \n", "intensity_minutes | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| calendar_date | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| 2021-09-08 | \n", "64 | \n", "2728 | \n", "2259 | \n", "8830 | \n", "26 | \n", "50100 | \n", "14400 | \n", "10020 | \n", "1500.0 | \n", "150 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 2021-09-09 | \n", "65 | \n", "7601 | \n", "6338 | \n", "7610 | \n", "32 | \n", "29100 | \n", "24420 | \n", "8520 | \n", "1680.0 | \n", "150 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 2021-09-10 | \n", "81 | \n", "25646 | \n", "19797 | \n", "7610 | \n", "31 | \n", "30780 | \n", "16500 | \n", "5880 | \n", "4020.0 | \n", "150 | \n", "117.0 | \n", "46.0 | \n", "209.0 | \n", "
| 2021-09-11 | \n", "0 | \n", "6869 | \n", "5701 | \n", "9420 | \n", "28 | \n", "37380 | \n", "18720 | \n", "7380 | \n", "1020.0 | \n", "150 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 2021-09-13 | \n", "76 | \n", "17210 | \n", "15660 | \n", "8970 | \n", "37 | \n", "25440 | \n", "16440 | \n", "13680 | \n", "4200.0 | \n", "150 | \n", "7.0 | \n", "41.0 | \n", "89.0 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 2023-09-27 | \n", "85 | \n", "6367 | \n", "5349 | \n", "8740 | \n", "30 | \n", "34980 | \n", "20460 | \n", "6600 | \n", "1200.0 | \n", "150 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 2023-09-28 | \n", "80 | \n", "2363 | \n", "2072 | \n", "8510 | \n", "29 | \n", "40740 | \n", "23580 | \n", "8520 | \n", "1200.0 | \n", "150 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 2023-09-29 | \n", "86 | \n", "11261 | \n", "8675 | \n", "7280 | \n", "38 | \n", "32880 | \n", "11520 | \n", "11400 | \n", "8160.0 | \n", "150 | \n", "44.0 | \n", "2.0 | \n", "48.0 | \n", "
| 2023-09-30 | \n", "79 | \n", "8130 | \n", "6742 | \n", "7680 | \n", "29 | \n", "42120 | \n", "15660 | \n", "9840 | \n", "900.0 | \n", "150 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| 2023-10-01 | \n", "46 | \n", "25434 | \n", "21006 | \n", "7770 | \n", "30 | \n", "36900 | \n", "8640 | \n", "7680 | \n", "4140.0 | \n", "150 | \n", "77.0 | \n", "56.0 | \n", "189.0 | \n", "
743 rows × 13 columns
\n", "