Updated create_heart_rate_plot(df), new Zone + percentage_sum indicators
This commit is contained in:
@@ -1115,30 +1115,41 @@ def create_heart_rate_plot(df):
|
|||||||
max_hr_estimated = 200 # oder z. B. 220 - alter
|
max_hr_estimated = 200 # oder z. B. 220 - alter
|
||||||
|
|
||||||
## Definiere feste HR-Zonen in BPM
|
## Definiere feste HR-Zonen in BPM
|
||||||
#zones = [
|
|
||||||
# {"name": "Zone 1", "lower": 0, "upper": 124, "color": "#F4A4A3"}, # Regeneration (Recovery)
|
|
||||||
# {"name": "Zone 2", "lower": 124, "upper": 154, "color": "#EF7476"}, # Grundlagenausdauer (Endurance)
|
|
||||||
# {"name": "Zone 3", "lower": 154, "upper": 169, "color": "#EA4748"}, # Tempo (Aerob)
|
|
||||||
# {"name": "Zone 4", "lower": 169, "upper": 184, "color": "#E02628"}, # Schwelle (Threshold) (Anaerob)
|
|
||||||
# {"name": "Zone 5", "lower": 184, "upper": max_hr_estimated, "color": "#B71316"}, # Neuromuskulär (Neuromuskulär)
|
|
||||||
#]
|
|
||||||
zones = [
|
zones = [
|
||||||
{"name": "Zone 1", "lower": 0, "upper": 124, "color": "#4A4A4A"}, # Regeneration (Recovery) (#111111 Transparent)
|
{"name": "Zone 0", "lower": 0, "upper": 40, "color": "#333333"}, # Unrealistischer Wertebereich
|
||||||
|
{"name": "Zone 1", "lower": 40, "upper": 124, "color": "#4A4A4A"}, # Regeneration (Recovery) (#111111 Transparent)
|
||||||
{"name": "Zone 2", "lower": 124, "upper": 154, "color": "#87CEFA"}, # Grundlagenausdauer (Endurance)
|
{"name": "Zone 2", "lower": 124, "upper": 154, "color": "#87CEFA"}, # Grundlagenausdauer (Endurance)
|
||||||
{"name": "Zone 3", "lower": 154, "upper": 169, "color": "#90EE90"}, # Tempo (Aerob)
|
{"name": "Zone 3", "lower": 154, "upper": 169, "color": "#90EE90"}, # Tempo (Aerob)
|
||||||
{"name": "Zone 4", "lower": 169, "upper": 184, "color": "#FFDAB9"}, # Schwelle (Threshold) (Anaerob)
|
{"name": "Zone 4", "lower": 169, "upper": 184, "color": "#FFDAB9"}, # Schwelle (Threshold) (Anaerob)
|
||||||
{"name": "Zone 5", "lower": 184, "upper": max_hr_estimated, "color": "#FFB6C1"}, # Neuromuskulär (Neuromuskulär)
|
{"name": "Zone 5", "lower": 184, "upper": max_hr_estimated, "color": "#FFB6C1"}, # Neuromuskulär (Neuromuskulär)
|
||||||
]
|
]
|
||||||
|
|
||||||
# Zeichne Zonen als Hintergrund (horizontale Rechtecke)
|
# Berechne die Anzahl der Werte in jeder Zone
|
||||||
|
total_count = len(valid_hr)
|
||||||
for zone in zones:
|
for zone in zones:
|
||||||
|
# Filter für die Zone
|
||||||
|
zone_count = valid_hr[(valid_hr >= zone["lower"]) & (valid_hr < zone["upper"])].count()
|
||||||
|
zone_percentage = (zone_count / total_count) * 100 if total_count > 0 else 0
|
||||||
|
|
||||||
|
# Zeichne die Zone als Hintergrund
|
||||||
fig.add_hrect(
|
fig.add_hrect(
|
||||||
y0=zone["lower"], y1=zone["upper"],
|
y0=zone["lower"], y1=zone["upper"],
|
||||||
fillcolor=zone["color"],
|
fillcolor=zone["color"],
|
||||||
opacity=0.15,
|
opacity=0.15,
|
||||||
line_width=0,
|
line_width=0,
|
||||||
annotation_text=zone["name"], # optional: Name der Zone einblenden
|
)
|
||||||
annotation_position="top left"
|
|
||||||
|
# Annotation für die Zone (Name und Prozentsatz)
|
||||||
|
fig.add_annotation(
|
||||||
|
x=df['time_loc'].iloc[-1], # Rechts am Plot
|
||||||
|
y=zone["upper"] -6 , # Oben in der Zone
|
||||||
|
#y=(zone["lower"] + zone["upper"]) / 2, # Falls Pos. mittig je Zone gewünscht
|
||||||
|
text=f"{zone['name']}<br>{zone_percentage:.1f}%",
|
||||||
|
showarrow=False,
|
||||||
|
font=dict(color="white", size=10),
|
||||||
|
align="left",
|
||||||
|
bgcolor="rgba(0,0,0,0.5)",
|
||||||
|
bordercolor="gray",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Layout
|
# Layout
|
||||||
@@ -1155,7 +1166,7 @@ def create_heart_rate_plot(df):
|
|||||||
),
|
),
|
||||||
yaxis=dict(
|
yaxis=dict(
|
||||||
title='Herzfrequenz (bpm)',
|
title='Herzfrequenz (bpm)',
|
||||||
range=[80, 200] # Statt rangemode='tozero'
|
range=[70, 200] # instead of: rangemode='tozero'
|
||||||
),
|
),
|
||||||
template='plotly_dark',
|
template='plotly_dark',
|
||||||
paper_bgcolor='#1e1e1e',
|
paper_bgcolor='#1e1e1e',
|
||||||
|
|||||||
Reference in New Issue
Block a user