<jupyter_start><jupyter_text>Ouraring Sleep data into Pandas DataFrameRead Ouraring Sleep records from the database into Pandas DataFrame and do some analysis.NOTE: Do not edit this file, but create your own copy.NEVER commit your personal data into Github or similar public place in the Internet!<jupyter_code># Set up Django
import os

# You should have env.local file available, having all necessary variables defined correctly
with open(os.path.join("..", "env.local"), 'r') as fh:
    lines = fh.read().splitlines()
    tuples = [tuple(line.split('=', maxsplit=1)) for line in lines if not line.startswith('#')]
    vars_dict = dict(tuples)

os.environ.update(vars_dict)
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mydata.settings')

import django

django.setup()

from django.conf import settings
from django.contrib.auth.models import User
from django.utils import timezone

# timezone.activate(pytz.timezone(settings.TIME_ZONE))
print(f"Timezone: {settings.TIME_ZONE}")

user = User.objects.get(id=1)
# Set up Matplotlib

import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import pandas as pd
import seaborn as sns
from pandas.plotting import register_matplotlib_converters
import datetime
import pytz

register_matplotlib_converters()

# Use white grid plot background from seaborn
sns.set(font_scale=1.0, style="whitegrid")<jupyter_output><empty_output><jupyter_text>Get Sleep Records<jupyter_code>from ouraring.models import Sleep

# Get all Records having Sleep type
sleeps = Sleep.objects.order_by("summary_date")
if sleeps.count() == 0:
    print("No Sleep records available. :( Perhaps you should import them first?")

# Keep only some columns
df = pd.DataFrame.from_records(sleeps.values(
    "summary_date", "bedtime_start", "bedtime_end", "deep", "hr_lowest", "temperature_delta")).set_index("summary_date")
df.tail(30).shape<jupyter_output><empty_output><jupyter_text>Plot some data<jupyter_code>ax = df["temperature_delta"].plot.hist(bins=4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10577389616690927, 'fraction_numerical': 0.0038816108685104317, 'mean_word_length': 6.39068100358423, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '624550', 'license': 'MIT', 'n_tokens_mistral': 680, 'n_tokens_neox': 671, 'n_words': 183, 'path': 'services/django_server/mydata/ouraring/sleep_example.ipynb', 'repo_name': 'aapris/MyData', 'size': '2061'}