{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Health Report Analysis"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import HTML, display, display_html\n",
"import os\n",
"import pandas as pd\n",
"import numpy as np\n",
"import plotly.io as pio\n",
"# pio.renderers.default = \"sphinx_gallery\"\n",
"pio.renderers.default = \"jupyterlab\" # or \"plotly_mimetype\"\n",
"from IPython.display import display, HTML\n",
"display(HTML(''))\n",
"from vitalDSP.health_analysis.health_report_generator import HealthReportGenerator"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(42)\n",
"duration = 60\n",
"fs = 100\n",
"# Generate mock feature data\n",
"feature_data = {\n",
" \"sdnn\": np.random.normal(\n",
" 50, 10, duration\n",
" ).tolist(), # Normally distributed around 50 with std dev of 10\n",
" \"rmssd\": np.random.normal(\n",
" 30, 8, duration\n",
" ).tolist(), # Normally distributed around 30 with std dev of 8\n",
" \"total_power\": np.random.normal(\n",
" 1600, 300, duration\n",
" ).tolist(), # Normally distributed around 1600 with std dev of 300\n",
" \"lfnu_power\": np.random.normal(\n",
" 45, 5, duration\n",
" ).tolist(), # Normally distributed around 45 with std dev of 5\n",
" \"hfnu_power\": np.random.normal(\n",
" 35, 4, duration\n",
" ).tolist(), # Normally distributed around 35 with std dev of 4\n",
" \"fractal_dimension\": np.random.normal(\n",
" 1.25, 0.05, duration\n",
" ).tolist(), # Normally around 1.25 with std dev of 0.05\n",
" \"dfa\": np.random.normal(\n",
" 1.2, 0.08, duration\n",
" ).tolist(), # Normally distributed around 1.2 with std dev of 0.08\n",
" \"poincare_sd1\": np.random.normal(\n",
" 28.5, 3, duration\n",
" ).tolist(), # Normally around 28.5 with std dev of 3\n",
" \"poincare_sd2\": np.random.normal(\n",
" 45, 4, duration\n",
" ).tolist(), # Normally around 45 with std dev of 4\n",
" \"sample_entropy\": np.random.normal(\n",
" 0.85, 0.1, duration\n",
" ).tolist(), # Normally around 0.85 with std dev of 0.1\n",
" \"approximate_entropy\": np.random.normal(\n",
" 0.72, 0.1, duration\n",
" ).tolist(), # Normally around 0.72 with std dev of 0.1\n",
" \"recurrence_rate\": np.random.normal(\n",
" 0.65, 0.1, duration\n",
" ).tolist(), # Normally around 0.65 with std dev of 0.1\n",
" \"determinism\": np.random.normal(\n",
" 0.78, 0.1, duration\n",
" ).tolist(), # Normally around 0.78 with std dev of 0.1\n",
" \"laminarity\": np.random.normal(\n",
" 0.85, 0.05, duration\n",
" ).tolist(), # Normally around 0.85 with std dev of 0.05\n",
" \"systolic_duration\": np.random.normal(\n",
" 0.35, 0.05, duration\n",
" ).tolist(), # Normally around 0.35 with std dev of 0.05\n",
" \"diastolic_duration\": np.random.normal(\n",
" 0.5, 0.05, duration\n",
" ).tolist(), # Normally around 0.5 with std dev of 0.05\n",
" \"systolic_area\": np.random.normal(\n",
" 200, 20, duration\n",
" ).tolist(), # Normally around 200 with std dev of 20\n",
" \"diastolic_area\": np.random.normal(\n",
" 180, 20, duration\n",
" ).tolist(), # Normally around 180 with std dev of 20\n",
" \"systolic_slope\": np.random.normal(\n",
" 1.5, 0.1, duration\n",
" ).tolist(), # Normally around 1.5 with std dev of 0.1\n",
" \"diastolic_slope\": np.random.normal(\n",
" 1.2, 0.1, duration\n",
" ).tolist(), # Normally around 1.2 with std dev of 0.1\n",
" \"signal_skewness\": np.random.normal(\n",
" 0.1, 0.02, duration\n",
" ).tolist(), # Normally around 0.1 with std dev of 0.02\n",
" \"peak_trend_slope\": np.random.normal(\n",
" 0.05, 0.01, duration\n",
" ).tolist(), # Normally around 0.05 with std dev of 0.01\n",
" \"systolic_amplitude_variability\": np.random.normal(\n",
" 5.0, 0.5, duration\n",
" ).tolist(), # Normally around 5.0 with std dev of 0.5\n",
" \"diastolic_amplitude_variability\": np.random.normal(\n",
" 4.8, 0.5, duration\n",
" ).tolist(), # Normally around 4.8 with std dev of 0.5\n",
" # \"respiratory_rate\": np.random.normal(16, 3, duration).tolist(), # Normally around 16 breaths/min with std dev of 3\n",
" # \"pulse_pressure\": np.random.normal(40, 5, duration).tolist(), # Normally around 40 mmHg with std dev of 5\n",
" # \"stroke_volume\": np.random.normal(70, 10, duration).tolist(), # Normally around 70 mL with std dev of 10\n",
" # \"cardiac_output\": np.random.normal(5.5, 0.7, duration).tolist(), # Normally around 5.5 L/min with std dev of 0.7\n",
" # \"qt_interval\": np.random.normal(400, 20, duration).tolist(), # Normally around 400 ms with std dev of 20\n",
" # \"qrs_duration\": np.random.normal(90, 10, duration).tolist(), # Normally around 90 ms with std dev of 10\n",
" # \"p_wave_duration\": np.random.normal(100, 10, duration).tolist(), # Normally around 100 ms with std dev of 10\n",
" # \"pr_interval\": np.random.normal(160, 20, duration).tolist(), # Normally around 160 ms with std dev of 20\n",
"}\n",
"\n",
"# Initialize the health report generator\n",
"report_generator = HealthReportGenerator(\n",
" feature_data=feature_data, segment_duration=\"1_min\"\n",
")\n",
"\n",
"image_dir = \"../_static/images\"\n",
"os.makedirs(image_dir, exist_ok=True)\n",
"\n",
"# Generate the report (HTML)\n",
"report_html = report_generator.generate(output_dir=image_dir)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Display the health analysis report"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"display(HTML(report_html))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Save the health report as HTML file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Write the HTML content to a file\n",
"with open(\"../_static/report.html\", \"w\") as file:\n",
" file.write(report_html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Display the HTML file in the notebook"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Display the HTML file in the notebook\n",
"display_html('', raw=True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "wearables",
"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.17"
}
},
"nbformat": 4,
"nbformat_minor": 2
}