💾 Archived View for bacaliu.de › analyzing_gadgetbridge_data_in_python.html captured on 2023-07-22 at 17:11:08.

View Raw

More Information

⬅️ Previous capture (2023-07-10)

-=-=-=-=-=-=-

<!DOCTYPE html>
<html lang="en">
<head>
<!-- 2023-06-26 Mo 07:33 -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Analyzing Gadgetbridge-Data with Python</title>
<meta name="description" content="Analyzing the Data collected by Gadgedbridge-compatible Smartwatches" />
<meta name="keywords" content="Amazfit Neo, Mi Band, Gadgetbridge, Python, Pandas, Sqlite, DataFrame" />
<meta name="generator" content="Org Mode" />

<meta property="og:type" content="article">
<meta property="og:site_name" content="Bacaliu.de">
<link rel="stylesheet" type="text/css" href="/css/modus.css">
<link rel="shortcut icon" href="/favicon.ico" sizes="65x65">
<script src=/static/js/htmx.min.js></script>
<link rel="stylesheet" type="text/css" href="/css/colors/auto.css"
      id="ef-theme"
      hx-swap="outerHTML" hx-get="/data/colorscheme"
      hx-trigger="load">
</head>
<body>
<header id="preamble" class="status">
<a id='top'></a>
<pre style='text-align: left; font-size: min(2vw, 1rem); display: inline-block;'>
 ___               _ _           _
| _ ) __ _ __ __ _| (_)_  _   __| |___
| _ \/ _` / _/ _` | | | || |_/ _` / -_)
|___/\__,_\__\__,_|_|_|\_,_(_)__,_\___|

</pre><br>
<a href='#top'>↑</a>
- <a href='/index.html'>Home</a>
- <a href='/search.html'>Search</a>
- <a href='#bottom'>↓</a>
<br>
<div hx-get="/data/colorlist" hx-trigger="load"></div>
<hr>
</header>
<main id="content" class="content">
<header>
<h1 class="title">Analyzing Gadgetbridge-Data with Python</h1>
<p class="subtitle" role="doc-subtitle">Amazfit Neo → Gadgetbridge → Sqlite → Python-Pandas</p>
</header>
<div id="outline-container-some-helpful-imports" class="outline-2">
<h2 id="some-helpful-imports"><span class="section-number-2">1.</span> <a href="#some-helpful-imports">Some helpful imports</a></h2>
<div class="outline-text-2" id="text-1">
<div class="org-src-container">
<label class="org-src-name"><span class="listing-number">Listing 1: </span>some helpful imports</label><pre class="src src-python"><span class="org-tree-sitter-hl-faceXkeyword">import</span> hsluv
<span class="org-tree-sitter-hl-faceXkeyword">import</span> matplotlib.pyplot <span class="org-tree-sitter-hl-faceXkeyword">as</span> plt
plt.<span class="org-tree-sitter-hl-faceXproperty">rcParams</span>[<span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"figure.figsize"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> (<span class="org-tree-sitter-hl-faceXnumber">8</span>, <span class="org-tree-sitter-hl-faceXnumber">4</span>)
<span class="org-tree-sitter-hl-faceXkeyword">import</span> seaborn <span class="org-tree-sitter-hl-faceXkeyword">as</span> sns
<span class="org-tree-sitter-hl-faceXkeyword">from</span> datetime <span class="org-tree-sitter-hl-faceXkeyword">import</span> datetime
</pre>
</div>
</div>
</div>

<div id="outline-container-getting-data" class="outline-2">
<h2 id="getting-data"><span class="section-number-2">2.</span> <a href="#getting-data">Getting the Data</a></h2>
<div class="outline-text-2" id="text-2">
<p>
The FOSS-Application Gadgedbridge (<a href="#citeproc_bib_item_1">“Gadgetbridge for android” 2022</a>) supports exporting the collected Data into an sqlite-file. Loading them into Python is not that difficult. In my case the file is automaticly mirrored into my <kbd>~/Sync</kbd>-folder through Syncthing (<a href="#citeproc_bib_item_4">“Syncthing” 2019</a>) and named <code>ggb.sqlite</code>.<br>
</p>
<div class="org-src-container">
<pre class="src src-python"><span class="org-tree-sitter-hl-faceXkeyword">import</span> pandas <span class="org-tree-sitter-hl-faceXkeyword">as</span> pd
<span class="org-tree-sitter-hl-faceXkeyword">import</span> sqlite3
<span class="org-tree-sitter-hl-faceXvariable">conn</span> <span class="org-tree-sitter-hl-faceXoperator">=</span> sqlite3.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">connect</span></span>(<span class="org-tree-sitter-hl-faceXstring">"/home/adrian/Sync/ggb.sqlite"</span>)
<span class="org-tree-sitter-hl-faceXvariable">df</span> <span class="org-tree-sitter-hl-faceXoperator">=</span> pd.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">read_sql_query</span></span>(
    <span class="org-tree-sitter-hl-faceXdoc"><span class="org-tree-sitter-hl-faceXstring">"""</span></span><span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXdoc">SELECT TIMESTAMP, RAW_INTENSITY, STEPS, RAW_KIND, HEART_RATE</span></span>
<span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXdoc">    FROM MI_BAND_ACTIVITY_SAMPLE;</span></span><span class="org-tree-sitter-hl-faceXdoc"><span class="org-tree-sitter-hl-faceXstring">"""</span></span>,
    conn
)

df.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">describe</span></span>().<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">to_markdown</span></span>(<span class="org-tree-sitter-hl-faceXlabel">tablefmt</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"orgtbl"</span>)
</pre>
</div>

<div id='getting-data,table--1' class='table'>
<div class='gutter'><a href='#getting-data,table--1'>#</a></div>
<div class='tabular'>
<table>


<colgroup>
<col  class="org-left">

<col  class="org-right">

<col  class="org-right">

<col  class="org-right">

<col  class="org-right">

<col  class="org-right">
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">&#xa0;</th>
<th scope="col" class="org-right">TIMESTAMP</th>
<th scope="col" class="org-right">RAW_INTENSITY</th>
<th scope="col" class="org-right">STEPS</th>
<th scope="col" class="org-right">RAW_KIND</th>
<th scope="col" class="org-right">HEART_RATE</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">count</td>
<td class="org-right">331004</td>
<td class="org-right">331004</td>
<td class="org-right">331004</td>
<td class="org-right">331004</td>
<td class="org-right">331004</td>
</tr>

<tr>
<td class="org-left">mean</td>
<td class="org-right">1.66892e+09</td>
<td class="org-right">24.3221</td>
<td class="org-right">4.33082</td>
<td class="org-right">125.133</td>
<td class="org-right">76.3764</td>
</tr>

<tr>
<td class="org-left">std</td>
<td class="org-right">5.7575e+06</td>
<td class="org-right">28.2967</td>
<td class="org-right">15.5202</td>
<td class="org-right">84.1054</td>
<td class="org-right">33.7458</td>
</tr>

<tr>
<td class="org-left">min</td>
<td class="org-right">1.65897e+09</td>
<td class="org-right">-1</td>
<td class="org-right">0</td>
<td class="org-right">1</td>
<td class="org-right">-1</td>
</tr>

<tr>
<td class="org-left">25%</td>
<td class="org-right">1.66394e+09</td>
<td class="org-right">0</td>
<td class="org-right">0</td>
<td class="org-right">80</td>
<td class="org-right">60</td>
</tr>

<tr>
<td class="org-left">50%</td>
<td class="org-right">1.6689e+09</td>
<td class="org-right">17</td>
<td class="org-right">0</td>
<td class="org-right">90</td>
<td class="org-right">71</td>
</tr>

<tr>
<td class="org-left">75%</td>
<td class="org-right">1.67387e+09</td>
<td class="org-right">38</td>
<td class="org-right">0</td>
<td class="org-right">240</td>
<td class="org-right">81</td>
</tr>

<tr>
<td class="org-left">max</td>
<td class="org-right">1.67895e+09</td>
<td class="org-right">198</td>
<td class="org-right">144</td>
<td class="org-right">251</td>
<td class="org-right">255</td>
</tr>
</tbody>
</table>
</div></div>

<p>
I did not include the useless columns <code>DEVICE_ID</code> and <code>USER_ID</code>. They always have the same value if you use only one device as one user; I don't load them to make the tables smaller; otherwise a <code class="src src-sql"><span class="org-keyword">SELECT</span> * <span class="org-keyword">FROM</span> MI_BAND_ACTIVITY_DATA</code> would be sufficient.<br>
</p>
</div>
</div>

<div id="outline-container-preperation" class="outline-2">
<h2 id="preperation"><span class="section-number-2">3.</span> <a href="#preperation">Preperation</a></h2>
<div class="outline-text-2" id="text-3">
</div>
<div id="outline-container-datetime" class="outline-3">
<h3 id="datetime"><span class="section-number-3">3.1.</span> <a href="#datetime">Datetime</a></h3>
<div class="outline-text-3" id="text-3-1">
<p>
But what is this strange <code>TIMESTAMP</code>-column? Oh, maybe just an unix-timestamp. Throw it into <code class="src src-python">pd.<span class="org-tree-sitter-hl-faceXproperty">to_datetime</span></code>:<br>
</p>

<div class="org-src-container">
<pre class="src src-python">pd.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">to_datetime</span></span>(df.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">TIMESTAMP</span></span></span>) \
  .<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">describe</span></span>(<span class="org-tree-sitter-hl-faceXlabel">datetime_is_numeric</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXconstantXbuiltin">True</span>) \
  .<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">to_markdown</span></span>(<span class="org-tree-sitter-hl-faceXlabel">tablefmt</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"orgtbl"</span>)
</pre>
</div>

<div id='datetime,table--1' class='table'>
<div class='gutter'><a href='#datetime,table--1'>#</a></div>
<div class='tabular'>
<table>


<colgroup>
<col  class="org-left">

<col  class="org-left">
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">&#xa0;</th>
<th scope="col" class="org-left">TIMESTAMP</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">count</td>
<td class="org-left">331004</td>
</tr>

<tr>
<td class="org-left">mean</td>
<td class="org-left">1970-01-01 00:00:01.668917075</td>
</tr>

<tr>
<td class="org-left">min</td>
<td class="org-left">1970-01-01 00:00:01.658969040</td>
</tr>

<tr>
<td class="org-left">25%</td>
<td class="org-left">1970-01-01 00:00:01.663935105</td>
</tr>

<tr>
<td class="org-left">50%</td>
<td class="org-left">1970-01-01 00:00:01.668900930</td>
</tr>

<tr>
<td class="org-left">75%</td>
<td class="org-left">1970-01-01 00:00:01.673866575</td>
</tr>

<tr>
<td class="org-left">max</td>
<td class="org-left">1970-01-01 00:00:01.678946580</td>
</tr>
</tbody>
</table>
</div></div>

<p>
Hmmm&#x2026; This don't look right. I ran into this type of problem last year when analyzing the Deutsche Bahn (results, not the progress: <a href="momentane_puenktlichkeit_der_deutschen_bahn_in_nrw.html">Momentane PĂĽnktlichkeit der Deutschen Bahn</a>). To safe memory and network capacity they divided the unix-timestamps by a factor of <code>1e6</code> or <code>1e9</code>.<br>
</p>

<div class="org-src-container">
<pre class="src src-python">pd.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">to_datetime</span></span>(df.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">TIMESTAMP</span></span></span> <span class="org-tree-sitter-hl-faceXoperator">*</span> <span class="org-tree-sitter-hl-faceXnumber">1e9</span>) \
  .<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">describe</span></span>(<span class="org-tree-sitter-hl-faceXlabel">datetime_is_numeric</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXconstantXbuiltin">True</span>) \
  .<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">to_markdown</span></span>(<span class="org-tree-sitter-hl-faceXlabel">tablefmt</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"orgtbl"</span>)
</pre>
</div>

<div id='datetime,table--2' class='table'>
<div class='gutter'><a href='#datetime,table--2'>#</a></div>
<div class='tabular'>
<table>


<colgroup>
<col  class="org-left">

<col  class="org-left">
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">&#xa0;</th>
<th scope="col" class="org-left">TIMESTAMP</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">count</td>
<td class="org-left">331004</td>
</tr>

<tr>
<td class="org-left">mean</td>
<td class="org-left">2022-11-20 04:04:35.349853696</td>
</tr>

<tr>
<td class="org-left">min</td>
<td class="org-left">2022-07-28 00:44:00</td>
</tr>

<tr>
<td class="org-left">25%</td>
<td class="org-left">2022-09-23 12:11:45</td>
</tr>

<tr>
<td class="org-left">50%</td>
<td class="org-left">2022-11-19 23:35:30</td>
</tr>

<tr>
<td class="org-left">75%</td>
<td class="org-left">2023-01-16 10:56:15</td>
</tr>

<tr>
<td class="org-left">max</td>
<td class="org-left">2023-03-16 06:03:00</td>
</tr>
</tbody>
</table>
</div></div>

<p>
Yes! This matches the span in which I used Gadgedbridge with my watch. Let's make some useful columns out of this. By using the <code>.dt</code>-accessor Object (<a href="#citeproc_bib_item_3">“pandas.Series.dt — pandas 1.5.3 documentation” 2023</a>) attributes like <code>date</code>, <code>hour</code>, etc. can be used easily:<br>
</p>

<div class="org-src-container">
<pre class="src src-python"><span class="org-variable-name">df</span>[<span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"utc"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> pd.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">to_datetime</span></span>(df.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">TIMESTAMP</span></span></span> <span class="org-tree-sitter-hl-faceXoperator">*</span> <span class="org-tree-sitter-hl-faceXnumber">1e9</span>)
<span class="org-variable-name">df</span>[<span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"date"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> df.<span class="org-tree-sitter-hl-faceXproperty">utc</span>.<span class="org-tree-sitter-hl-faceXproperty">dt</span>.<span class="org-tree-sitter-hl-faceXproperty">date</span>
<span class="org-variable-name">df</span>[<span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"weekday"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> df.<span class="org-tree-sitter-hl-faceXproperty">utc</span>.<span class="org-tree-sitter-hl-faceXproperty">dt</span>.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">day_name</span></span>()
<span class="org-variable-name">df</span>[<span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"hour"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> df.<span class="org-tree-sitter-hl-faceXproperty">utc</span>.<span class="org-tree-sitter-hl-faceXproperty">dt</span>.<span class="org-tree-sitter-hl-faceXproperty">hour</span>
<span class="org-variable-name">df</span>[<span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"hourF"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> df.<span class="org-tree-sitter-hl-faceXproperty">utc</span>.<span class="org-tree-sitter-hl-faceXproperty">dt</span>.<span class="org-tree-sitter-hl-faceXproperty">hour</span> <span class="org-tree-sitter-hl-faceXoperator">+</span> df.<span class="org-tree-sitter-hl-faceXproperty">utc</span>.<span class="org-tree-sitter-hl-faceXproperty">dt</span>.<span class="org-tree-sitter-hl-faceXproperty">minute</span><span class="org-tree-sitter-hl-faceXoperator">/</span><span class="org-tree-sitter-hl-faceXnumber">60</span>
</pre>
</div>

<p>
<code>date</code> and <code>weekday</code> can be used for grouping data; <code>hour</code> and espeically <code>hourF</code> (meaning the hour as floating point number) for x/y diagrams.<br>
</p>
</div>
</div>

<div id="outline-container-heart-rate" class="outline-3">
<h3 id="heart-rate"><span class="section-number-3">3.2.</span> <a href="#heart-rate">Heart Rate</a></h3>
<div class="outline-text-3" id="text-3-2">
<div class="org-src-container">
<pre class="src src-python">plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hist</span></span>(
    df.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">HEART_RATE</span></span></span>,
    <span class="org-tree-sitter-hl-faceXlabel">color</span><span class="org-tree-sitter-hl-faceXoperator">=</span>hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">75</span>, <span class="org-tree-sitter-hl-faceXnumber">25</span>)),
    <span class="org-tree-sitter-hl-faceXlabel">bins</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">256</span>
)
plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">title</span></span>(<span class="org-tree-sitter-hl-faceXstring">"Histogram: Heart rate"</span>)
plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">yscale</span></span>(<span class="org-tree-sitter-hl-faceXstring">"log"</span>)
plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">savefig</span></span>(<span class="org-builtin">file</span>)
plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">close</span></span>()
<span class="org-builtin">file</span>
</pre>
</div>


<figure id="org97fde7c">
<img src="./images/20230315-01.png" alt="20230315-01.png" class="invertable"><br>

<figcaption><span class="figure-number">Figure 1: </span>Histogram: Heart-Rate</figcaption>
</figure>

<p>
Looking at the Histogram of the Heart Rate it's obvious that the Values of <code>255</code> and below <code>0</code> are errors or failed measures. Therefore I set them to <code class="src src-python"><span class="org-tree-sitter-hl-faceXconstantXbuiltin">None</span></code>.<br>
</p>

<div class="org-src-container">
<pre class="src src-python"><span class="org-variable-name">df</span>[<span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"heartRate"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> df.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">HEART_RATE</span></span></span>
df.<span class="org-tree-sitter-hl-faceXproperty">loc</span>[df.<span class="org-tree-sitter-hl-faceXproperty">heartRate</span><span class="org-tree-sitter-hl-faceXoperator">&lt;=</span><span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"heartRate"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> <span class="org-tree-sitter-hl-faceXconstantXbuiltin">None</span>
df.<span class="org-tree-sitter-hl-faceXproperty">loc</span>[df.<span class="org-tree-sitter-hl-faceXproperty">heartRate</span><span class="org-tree-sitter-hl-faceXoperator">&gt;=</span><span class="org-tree-sitter-hl-faceXnumber">255</span>, <span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"heartRate"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> <span class="org-tree-sitter-hl-faceXconstantXbuiltin">None</span>
</pre>
</div>

<p>
To avoid strange problems when executing the org-babel-blocks in the wrong order, I follow the best-practise of copying and <b>not overwriting</b> the original data.<br>
</p>

<div class="org-src-container">
<pre class="src src-python">df[
    [<span class="org-tree-sitter-hl-faceXstring">"HEART_RATE"</span>, <span class="org-tree-sitter-hl-faceXstring">"heartRate"</span>]
].<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">describe</span></span>().<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">to_markdown</span></span>(<span class="org-tree-sitter-hl-faceXlabel">tablefmt</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"orgtbl"</span>)
</pre>
</div>

<div id='heart-rate,table--1' class='table'>
<div class='gutter'><a href='#heart-rate,table--1'>#</a></div>
<div class='tabular'>
<table>


<colgroup>
<col  class="org-left">

<col  class="org-right">

<col  class="org-right">
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">&#xa0;</th>
<th scope="col" class="org-right">HEART_RATE</th>
<th scope="col" class="org-right">heartRate</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">count</td>
<td class="org-right">331004</td>
<td class="org-right">321445</td>
</tr>

<tr>
<td class="org-left">mean</td>
<td class="org-right">76.3764</td>
<td class="org-right">71.0781</td>
</tr>

<tr>
<td class="org-left">std</td>
<td class="org-right">33.7458</td>
<td class="org-right">14.0401</td>
</tr>

<tr>
<td class="org-left">min</td>
<td class="org-right">-1</td>
<td class="org-right">39</td>
</tr>

<tr>
<td class="org-left">25%</td>
<td class="org-right">60</td>
<td class="org-right">59</td>
</tr>

<tr>
<td class="org-left">50%</td>
<td class="org-right">71</td>
<td class="org-right">71</td>
</tr>

<tr>
<td class="org-left">75%</td>
<td class="org-right">81</td>
<td class="org-right">81</td>
</tr>

<tr>
<td class="org-left">max</td>
<td class="org-right">255</td>
<td class="org-right">178</td>
</tr>
</tbody>
</table>
</div></div>

<p>
This is much better!<br>
</p>
</div>
</div>
</div>
<div id="outline-container-plotting-some-data" class="outline-2">
<h2 id="plotting-some-data"><span class="section-number-2">4.</span> <a href="#plotting-some-data">Plotting some Data</a></h2>
<div class="outline-text-2" id="text-4">
<p>
Now I want to see how the data looks. Today is a good day, because<br>
</p>
<ul class="org-ul">
<li>I slept (not that surprise)<br></li>
<li>I worked at the Computer (doing <i>this</i>)<br></li>
<li>I rode 47km with the bike<br></li>
</ul>

<div class="org-src-container">
<pre class="src src-python"><span class="org-tree-sitter-hl-faceXvariable">fig</span>, <span class="org-tree-sitter-hl-faceXvariable">ax</span> <span class="org-tree-sitter-hl-faceXoperator">=</span> plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">subplots</span></span>(<span class="org-tree-sitter-hl-faceXlabel">figsize</span><span class="org-tree-sitter-hl-faceXoperator">=</span>(<span class="org-tree-sitter-hl-faceXnumber">8</span>, <span class="org-tree-sitter-hl-faceXnumber">4</span>))
<span class="org-tree-sitter-hl-faceXvariable">span</span> <span class="org-tree-sitter-hl-faceXoperator">=</span> df[
    (
        df.<span class="org-tree-sitter-hl-faceXproperty">utc</span> <span class="org-tree-sitter-hl-faceXoperator">&gt;</span> <span class="org-tree-sitter-hl-faceXfunctionXcall">datetime</span>(<span class="org-tree-sitter-hl-faceXnumber">2023</span>, <span class="org-tree-sitter-hl-faceXnumber">3</span>, <span class="org-tree-sitter-hl-faceXnumber">15</span>, <span class="org-tree-sitter-hl-faceXnumber">3</span>)
    ) <span class="org-tree-sitter-hl-faceXoperator">&amp;</span> (  <span class="org-tree-sitter-hl-faceXcomment"># &amp; is the bitwise AND</span>
        df.<span class="org-tree-sitter-hl-faceXproperty">utc</span> <span class="org-tree-sitter-hl-faceXoperator">&lt;</span> <span class="org-tree-sitter-hl-faceXfunctionXcall">datetime</span>(<span class="org-tree-sitter-hl-faceXnumber">2023</span>, <span class="org-tree-sitter-hl-faceXnumber">3</span>, <span class="org-tree-sitter-hl-faceXnumber">15</span>, <span class="org-tree-sitter-hl-faceXnumber">15</span>)
    )
]
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">plot</span></span>(
    span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>, span.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">RAW_INTENSITY</span></span></span>,
    <span class="org-tree-sitter-hl-faceXlabel">label</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"Intensity"</span>,
    <span class="org-tree-sitter-hl-faceXlabel">color</span><span class="org-tree-sitter-hl-faceXoperator">=</span>hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">240</span>, <span class="org-tree-sitter-hl-faceXnumber">80</span>, <span class="org-tree-sitter-hl-faceXnumber">20</span>)),
    <span class="org-tree-sitter-hl-faceXlabel">linewidth</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">0.75</span>
)
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">plot</span></span>(
    span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>, span.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">RAW_KIND</span></span></span>,
    <span class="org-tree-sitter-hl-faceXlabel">label</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"Kind"</span>,
    <span class="org-tree-sitter-hl-faceXlabel">color</span><span class="org-tree-sitter-hl-faceXoperator">=</span>hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">120</span>, <span class="org-tree-sitter-hl-faceXnumber">80</span>, <span class="org-tree-sitter-hl-faceXnumber">40</span>)),
    <span class="org-tree-sitter-hl-faceXlabel">linewidth</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">0.5</span>
)
<span class="org-tree-sitter-hl-faceXvariable">bx</span> <span class="org-tree-sitter-hl-faceXoperator">=</span> ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">twinx</span></span>()
bx.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">plot</span></span>(
    span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>, span.<span class="org-tree-sitter-hl-faceXproperty">heartRate</span>,
    <span class="org-tree-sitter-hl-faceXlabel">label</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"Heart Rate"</span>,
    <span class="org-tree-sitter-hl-faceXlabel">color</span><span class="org-tree-sitter-hl-faceXoperator">=</span>hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">80</span>, <span class="org-tree-sitter-hl-faceXnumber">60</span>)),
    <span class="org-tree-sitter-hl-faceXlabel">linewidth</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">0.25</span>
)
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_ylim</span></span>([<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">256</span>])
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_yticks</span></span>(<span class="org-tree-sitter-hl-faceXfunctionXcall"><span class="org-tree-sitter-hl-faceXfunctionXbuiltin">list</span></span>(<span class="org-tree-sitter-hl-faceXfunctionXcall"><span class="org-tree-sitter-hl-faceXfunctionXbuiltin">range</span></span>(<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">256</span>, <span class="org-tree-sitter-hl-faceXnumber">32</span>)))
bx.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_ylim</span></span>([<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">160</span>])
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_xlim</span></span>([span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">min</span></span>(), span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">max</span></span>()])
fig.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">legend</span></span>()
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">grid</span></span>()
fig.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">autofmt_xdate</span></span>()  <span class="org-tree-sitter-hl-faceXcomment"># tilting the x-labels</span>
fig.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">tight_layout</span></span>()  <span class="org-tree-sitter-hl-faceXcomment"># less space around the plot</span>
fig.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">savefig</span></span>(<span class="org-builtin">file</span>)
plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">close</span></span>(fig)
<span class="org-builtin">file</span>
</pre>
</div>


<figure id="org1b18766">
<img src="./images/20230315-02.png" alt="20230315-02.png" class="invertable"><br>

<figcaption><span class="figure-number">Figure 2: </span>A normal day</figcaption>
</figure>

<p>
You can't clearly see what's going on, because the wiggeli wobbelyness of the lines. Try using a rolling mean:<br>
</p>


<div class="org-src-container">
<pre class="src src-python"><span class="org-tree-sitter-hl-faceXvariable">fig</span>, <span class="org-tree-sitter-hl-faceXvariable">ax</span> <span class="org-tree-sitter-hl-faceXoperator">=</span> plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">subplots</span></span>(<span class="org-tree-sitter-hl-faceXlabel">figsize</span><span class="org-tree-sitter-hl-faceXoperator">=</span>(<span class="org-tree-sitter-hl-faceXnumber">8</span>, <span class="org-tree-sitter-hl-faceXnumber">4</span>))
<span class="org-tree-sitter-hl-faceXvariable">span</span> <span class="org-tree-sitter-hl-faceXoperator">=</span> df[
    (
        df.<span class="org-tree-sitter-hl-faceXproperty">utc</span> <span class="org-tree-sitter-hl-faceXoperator">&gt;</span> <span class="org-tree-sitter-hl-faceXfunctionXcall">datetime</span>(<span class="org-tree-sitter-hl-faceXnumber">2023</span>, <span class="org-tree-sitter-hl-faceXnumber">3</span>, <span class="org-tree-sitter-hl-faceXnumber">15</span>, <span class="org-tree-sitter-hl-faceXnumber">3</span>)
    ) <span class="org-tree-sitter-hl-faceXoperator">&amp;</span> (
        df.<span class="org-tree-sitter-hl-faceXproperty">utc</span> <span class="org-tree-sitter-hl-faceXoperator">&lt;</span> <span class="org-tree-sitter-hl-faceXfunctionXcall">datetime</span>(<span class="org-tree-sitter-hl-faceXnumber">2023</span>, <span class="org-tree-sitter-hl-faceXnumber">3</span>, <span class="org-tree-sitter-hl-faceXnumber">15</span>, <span class="org-tree-sitter-hl-faceXnumber">15</span>)
    )
]
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">plot</span></span>(
    span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>,
    span.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">RAW_INTENSITY</span></span></span>.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">rolling</span></span>(<span class="org-tree-sitter-hl-faceXnumber">5</span>, <span class="org-tree-sitter-hl-faceXlabel">min_periods</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">1</span>).<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">mean</span></span>(),
    <span class="org-tree-sitter-hl-faceXlabel">label</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"Intensity"</span>,
    <span class="org-tree-sitter-hl-faceXlabel">color</span><span class="org-tree-sitter-hl-faceXoperator">=</span>hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">240</span>, <span class="org-tree-sitter-hl-faceXnumber">80</span>, <span class="org-tree-sitter-hl-faceXnumber">20</span>)),
    <span class="org-tree-sitter-hl-faceXlabel">linewidth</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">0.75</span>
)
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">plot</span></span>(
    span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>,
    span.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">RAW_KIND</span></span></span>.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">rolling</span></span>(<span class="org-tree-sitter-hl-faceXnumber">5</span>, <span class="org-tree-sitter-hl-faceXlabel">min_periods</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">1</span>).<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">median</span></span>(), <span class="org-tree-sitter-hl-faceXcomment"># !</span>
    <span class="org-tree-sitter-hl-faceXlabel">label</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"Kind"</span>,
    <span class="org-tree-sitter-hl-faceXlabel">color</span><span class="org-tree-sitter-hl-faceXoperator">=</span>hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">120</span>, <span class="org-tree-sitter-hl-faceXnumber">80</span>, <span class="org-tree-sitter-hl-faceXnumber">40</span>)),
    <span class="org-tree-sitter-hl-faceXlabel">linewidth</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">0.5</span>
)
<span class="org-tree-sitter-hl-faceXvariable">bx</span> <span class="org-tree-sitter-hl-faceXoperator">=</span> ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">twinx</span></span>()
bx.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">plot</span></span>(
    span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>,
    span.<span class="org-tree-sitter-hl-faceXproperty">heartRate</span>.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">rolling</span></span>(<span class="org-tree-sitter-hl-faceXnumber">5</span>, <span class="org-tree-sitter-hl-faceXlabel">min_periods</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">1</span>).<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">mean</span></span>(),
    <span class="org-tree-sitter-hl-faceXlabel">label</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"Heart Rate"</span>,
    <span class="org-tree-sitter-hl-faceXlabel">color</span><span class="org-tree-sitter-hl-faceXoperator">=</span>hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">80</span>, <span class="org-tree-sitter-hl-faceXnumber">60</span>)),
    <span class="org-tree-sitter-hl-faceXlabel">linewidth</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXnumber">0.25</span>
)
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_ylim</span></span>([<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">256</span>])
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_yticks</span></span>(<span class="org-tree-sitter-hl-faceXfunctionXcall"><span class="org-tree-sitter-hl-faceXfunctionXbuiltin">list</span></span>(<span class="org-tree-sitter-hl-faceXfunctionXcall"><span class="org-tree-sitter-hl-faceXfunctionXbuiltin">range</span></span>(<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">256</span>, <span class="org-tree-sitter-hl-faceXnumber">32</span>)))
bx.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_ylim</span></span>([<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">160</span>])
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_xlim</span></span>([span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">min</span></span>(), span.<span class="org-tree-sitter-hl-faceXproperty">utc</span>.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">max</span></span>()])
fig.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">legend</span></span>()
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">grid</span></span>()
fig.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">autofmt_xdate</span></span>()
fig.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">tight_layout</span></span>()
fig.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">savefig</span></span>(<span class="org-builtin">file</span>)
plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">close</span></span>(fig)
<span class="org-builtin">file</span>
</pre>
</div>


<figure id="org9943fb9">
<img src="./images/20230315-02-rolling.png" alt="20230315-02-rolling.png" class="invertable"><br>

<figcaption><span class="figure-number">Figure 3: </span>A normal day but with rolling mean</figcaption>
</figure>

<p>
<i>Now</i> you can clearly see<br>
</p>
<ul class="org-ul">
<li>Low activity and pulse while sleeping until 06:30 UTC<br></li>
<li>Normal activity while working until 11:00 UTC<br></li>
<li>High activity and pulse from 11:00-13:30 UTC<br></li>
</ul>

<p>
For <code>RAW_KIND</code> I used the rolling <b>median</b>, because this looks more discrete than continuous. There might be some strange encoding happening: Sleep is very high, the spikes towards arround 100 are short occurrences of me waking up and turning around; while working the value is arround 80 and during sport it drops to below 20.<br>
</p>
</div>

<div id="outline-container-x-y-combining" class="outline-3">
<h3 id="x-y-combining"><span class="section-number-3">4.1.</span> <a href="#x-y-combining">x/y - combining features!</a></h3>
<div class="outline-text-3" id="text-4-1">
<p>
Now combine features. And to add a color-dimension let's assume <code>RAW_KIND</code> above 192 means sleep; below 32 activity.<br>
</p>

<div class="org-src-container">
<pre class="src src-python"><span class="org-variable-name">df</span>[<span class="org-tree-sitter-hl-faceXstring"><span class="org-tree-sitter-hl-faceXvariable">"assumption"</span></span>] <span class="org-tree-sitter-hl-faceXoperator">=</span> [
    <span class="org-tree-sitter-hl-faceXstring">"sleep"</span> <span class="org-tree-sitter-hl-faceXkeyword">if</span> r<span class="org-tree-sitter-hl-faceXoperator">&gt;</span><span class="org-tree-sitter-hl-faceXnumber">192</span> <span class="org-tree-sitter-hl-faceXkeyword">else</span> <span class="org-tree-sitter-hl-faceXstring">"normal"</span> <span class="org-tree-sitter-hl-faceXkeyword">if</span> r<span class="org-tree-sitter-hl-faceXoperator">&gt;</span><span class="org-tree-sitter-hl-faceXnumber">32</span> <span class="org-tree-sitter-hl-faceXkeyword">else</span> <span class="org-tree-sitter-hl-faceXstring">"activity"</span>
    <span class="org-tree-sitter-hl-faceXkeyword">for</span> <span class="org-tree-sitter-hl-faceXvariable">r</span> <span class="org-tree-sitter-hl-faceXoperator">in</span> df.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXconstructor"><span class="org-tree-sitter-hl-faceXconstant">RAW_KIND</span></span></span>
]
<span class="org-tree-sitter-hl-faceXvariable">fig</span>, <span class="org-tree-sitter-hl-faceXvariable">ax</span> <span class="org-tree-sitter-hl-faceXoperator">=</span> plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">subplots</span></span>(<span class="org-tree-sitter-hl-faceXlabel">figsize</span><span class="org-tree-sitter-hl-faceXoperator">=</span>(<span class="org-tree-sitter-hl-faceXnumber">6</span>, <span class="org-tree-sitter-hl-faceXnumber">6</span>))
sns.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">scatterplot</span></span>(
    <span class="org-tree-sitter-hl-faceXlabel">ax</span><span class="org-tree-sitter-hl-faceXoperator">=</span>ax,
    <span class="org-tree-sitter-hl-faceXlabel">data</span><span class="org-tree-sitter-hl-faceXoperator">=</span>df.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">sample</span></span>(<span class="org-tree-sitter-hl-faceXnumber">2048</span>), <span class="org-tree-sitter-hl-faceXcomment"># use not /all/ but only 2048 data-points</span>
    <span class="org-tree-sitter-hl-faceXlabel">x</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"heartRate"</span>,
    <span class="org-tree-sitter-hl-faceXlabel">y</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"RAW_INTENSITY"</span>,
    <span class="org-tree-sitter-hl-faceXlabel">hue</span><span class="org-tree-sitter-hl-faceXoperator">=</span><span class="org-tree-sitter-hl-faceXstring">"assumption"</span>,
    <span class="org-tree-sitter-hl-faceXlabel">palette</span><span class="org-tree-sitter-hl-faceXoperator">=</span>{
        <span class="org-tree-sitter-hl-faceXstring">"sleep"</span>: hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">240</span>, <span class="org-tree-sitter-hl-faceXnumber">60</span>, <span class="org-tree-sitter-hl-faceXnumber">60</span>)),
        <span class="org-tree-sitter-hl-faceXstring">"normal"</span>: hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">120</span>, <span class="org-tree-sitter-hl-faceXnumber">80</span>, <span class="org-tree-sitter-hl-faceXnumber">40</span>)),
        <span class="org-tree-sitter-hl-faceXstring">"activity"</span>: hsluv.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">hsluv_to_hex</span></span>((<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXnumber">100</span>, <span class="org-tree-sitter-hl-faceXnumber">20</span>)),
    }
)
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_xlim</span></span>([<span class="org-tree-sitter-hl-faceXnumber">30</span>, <span class="org-tree-sitter-hl-faceXnumber">130</span>])
ax.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">set_ylim</span></span>([<span class="org-tree-sitter-hl-faceXnumber">0</span>, <span class="org-tree-sitter-hl-faceXconstantXbuiltin">None</span>])
fig.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">savefig</span></span>(<span class="org-builtin">file</span>)
plt.<span class="org-tree-sitter-hl-faceXproperty"><span class="org-tree-sitter-hl-faceXmethodXcall">close</span></span>(fig)
<span class="org-builtin">file</span>
</pre>
</div>


<figure id="org6bf726b">
<img src="./images/20230315-03.png" alt="20230315-03.png" class="invertable"><br>

<figcaption><span class="figure-number">Figure 4: </span>heartRate against Raw-Intensity</figcaption>
</figure>

<p>
It seems intuitive that intensity and heart rate are lower while sleeping. But do you see some strangeness? There are Lines of frequent heart rates when awake but not while sleep.<br>
</p>

<p>
I assume my watch has a high precission, but a medium accuracy. Randall Munroe made a useful table to keep in mind the difference between them:<br>
</p>


<figure id="orgaa2284c">
<img src="https://imgs.xkcd.com/comics/precision_vs_accuracy.png" alt="precision_vs_accuracy.png" class="invertable has-border"><br>

<figcaption><span class="figure-number">Figure 5: </span>Precision vs Accuracy (<a href="#citeproc_bib_item_2">Munroe 2022</a>)</figcaption>
</figure>

<p>
Maybe it's like the following: While sleeping I don't move that much (like the position on the y-axis implies) so the precision is as high as possible. But when moving around the watch measures just the moments it can and estimates the pulse with a lower precision.<br>
</p>
</div>
</div>
</div>

<div id="outline-container-bibliography" class="outline-2">
<h2 id="bibliography"><a href="#bibliography">Bibliography</a></h2>
<div class="outline-text-2" id="text-bibliography">
<style>.csl-entry{text-indent: -0; margin-left: 0;}</style><div class="csl-bib-body">
  <div class="csl-entry"><a id="citeproc_bib_item_1"></a>“Gadgetbridge for android,”. 2022. September 10, 2022, URL: <a href="https://www.gadgetbridge.org">https://www.gadgetbridge.org</a>.</div>
  <div class="csl-entry"><a id="citeproc_bib_item_2"></a>Munroe, R. 2022. “Precision vs Accuracy,” <i>Xkcd</i> November 9, 2022, URL: <a href="https://xkcd.com/2696">https://xkcd.com/2696</a>.</div>
  <div class="csl-entry"><a id="citeproc_bib_item_3"></a>“pandas.Series.dt — pandas 1.5.3 documentation,”. 2023. January 19, 2023, URL: <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.dt.html">https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.dt.html</a>.</div>
  <div class="csl-entry"><a id="citeproc_bib_item_4"></a>“Syncthing,”. 2019. September 5, 2019, URL: <a href="https://syncthing.net">https://syncthing.net</a>.</div>
</div>
</div>
</div>

<div id="outline-container-nav" class="outline-2">
<h2 id="nav"><a href="#nav">Nav</a></h2>
<div class="outline-text-2" id="text-nav">
<ul class="org-ul">
<li>Tags: <a href="./tags/Python.html">Python</a> - <a href="./tags/Data.html">Data</a><br></li>
</ul>
<!-- BEGIN insert Backlinks (but there are no) -->
<ul class="org-ul">
<li>Formats: <a href="./analyzing_gadgetbridge_data_in_python.md">md</a> - <a href="./analyzing_gadgetbridge_data_in_python.txt">txt</a> - <a href="./analyzing_gadgetbridge_data_in_python.html">html</a> - <a href="./analyzing_gadgetbridge_data_in_python.gmi">gmi</a></li>
</ul>
</div>
</div>
</main>
<footer id="postamble" class="status">

<hr>
2023-03-15 
<br>
<img alt="CC BY-4.0" style="border-width:0; vertical-align: middle; height: 1em;" src="/icons/cc-by-4.0-80x15.svg">
<a rel='license' href='http://creativecommons.org/licenses/by/4.0/'>
        CC BY-4.0.
</a>
<br>
running at <a href='https://www.hosting.de/'>hosting.de</a>
<br>
Creator: <a href="https://www.gnu.org/software/emacs/">Emacs</a> 28.2 (<a href="https://orgmode.org">Org</a> mode 9.5.5);
<br>
<a href='/impressum-datenschutz.html' id='impressum-dings'>
    Impressum und Datenschutzerklärung
</a>
<a id='bottom'></a>
</footer>
</body>
</html>