-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleSweatRate.py
More file actions
153 lines (114 loc) · 4.54 KB
/
Copy pathSimpleSweatRate.py
File metadata and controls
153 lines (114 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""Simple sweat rate and dehydration estimators.
These functions implement a basic mass-balance approach commonly used in field
hydration monitoring.
Assumptions
- 1 kg body mass change is approximated as 1 L water change.
- Inputs represent a single session; extremely large acute mass losses are
treated as likely measurement/unit errors.
This module is intentionally small and import-safe.
"""
from __future__ import annotations
from typing import Final
_MAX_ACUTE_BODY_MASS_LOSS_FRACTION: Final[float] = 0.05 # 5% in a single session is treated as suspicious
def calculate_sweat_rate(
initial_weight_kg: float,
final_weight_kg: float,
fluid_intake_l: float,
urine_output_l: float,
duration_hours: float,
) -> float:
"""Estimate sweat rate in L/h from session measurements.
Sweat loss (L) is approximated as:
(initial_weight - final_weight) + fluid_intake - urine_output
Args:
initial_weight_kg: Body mass at start (kg).
final_weight_kg: Body mass at end (kg).
fluid_intake_l: Fluid intake during session (L).
urine_output_l: Urine output during session (L).
duration_hours: Session duration (h).
Returns:
Estimated sweat rate (L/h). Can be negative if weight increased.
Raises:
ValueError: For invalid ranges or suspiciously large acute mass losses.
"""
wi = float(initial_weight_kg)
wf = float(final_weight_kg)
intake = float(fluid_intake_l)
urine = float(urine_output_l)
hours = float(duration_hours)
if wi <= 0.0:
raise ValueError("initial_weight_kg must be > 0")
if wf <= 0.0:
raise ValueError("final_weight_kg must be > 0")
if intake < 0.0:
raise ValueError("fluid_intake_l must be >= 0")
if urine < 0.0:
raise ValueError("urine_output_l must be >= 0")
if hours <= 0.0:
raise ValueError("duration_hours must be > 0")
weight_loss_kg = wi - wf
if weight_loss_kg > _MAX_ACUTE_BODY_MASS_LOSS_FRACTION * wi:
raise ValueError("Unrealistic acute weight loss for a single session")
sweat_loss_l = weight_loss_kg + intake - urine
return sweat_loss_l / hours
def get_dehydration_percentage(initial_weight_kg: float, final_weight_kg: float) -> float:
"""Compute dehydration percentage as percent body mass change.
Returns negative values if final_weight_kg > initial_weight_kg.
"""
wi = float(initial_weight_kg)
wf = float(final_weight_kg)
if wi <= 0.0:
raise ValueError("initial_weight_kg must be > 0")
if wf <= 0.0:
raise ValueError("final_weight_kg must be > 0")
return ((wi - wf) / wi) * 100.0
def interpret_sweat_rate(sweat_rate_l_per_h: float) -> str:
"""Interpret sweat rate (L/h) into practical hydration categories."""
x = float(sweat_rate_l_per_h)
if x < 0.75:
return "Low sweat rate"
if x < 1.5:
return "Moderate sweat rate"
if x < 2.5:
return "High sweat rate"
return "Very high sweat rate"
def interpret_dehydration(dehydration_percent: float) -> str:
"""Interpret dehydration (% body mass loss) into severity categories."""
x = float(dehydration_percent)
if x < 1.0:
return "Minimal dehydration"
if x < 2.0:
return "Mild dehydration"
if x < 3.5:
return "Moderate dehydration"
return "Severe dehydration"
def calculate_replacement_fluid_needed(
sweat_rate_l_per_h: float,
duration_hours: float,
*,
replacement_fraction: float = 1.0,
) -> tuple[float, float]:
"""Estimate recommended fluid replacement rate and total volume.
This helper is commonly used in field hydration planning: replace some
fraction of estimated sweat losses to limit dehydration.
Args:
sweat_rate_l_per_h: Estimated sweat rate (L/h).
duration_hours: Planned duration (h).
replacement_fraction: Fraction of sweat losses to replace (0–1.5).
Values slightly above 1.0 can be used for planned rehydration.
Returns:
(recommended_rate_l_per_h, recommended_total_l)
Raises:
ValueError: If duration is not positive or replacement_fraction invalid.
"""
rate = float(sweat_rate_l_per_h)
hours = float(duration_hours)
frac = float(replacement_fraction)
if hours <= 0.0:
raise ValueError("duration_hours must be > 0")
if frac < 0.0 or frac > 1.5:
raise ValueError("replacement_fraction must be between 0 and 1.5")
if rate <= 0.0:
return 0.0, 0.0
recommended_rate = rate * frac
return recommended_rate, recommended_rate * hours