血液酒精含量计算器
根据饮酒量、体重和时间估算血液酒精含量(BAC)。
常见问题
代码实现
def calculate_bac(
drinks: list[dict],
weight_kg: float,
gender: str,
hours_elapsed: float
) -> float:
"""
Estimate Blood Alcohol Content using the Widmark formula.
BAC = (alcohol_grams / (weight_kg * r * 10)) - (0.015 * hours)
r = 0.68 for male, 0.55 for female
drinks: list of {"abv": float (%), "volume_ml": float}
WARNING: For estimation only. Never use to determine fitness to drive.
"""
r = 0.68 if gender.lower() == "male" else 0.55
total_alcohol_grams = sum(
d["volume_ml"] * (d["abv"] / 100) * 0.789 # ethanol density = 0.789 g/ml
for d in drinks
)
bac = (total_alcohol_grams / (weight_kg * r * 10)) - (0.015 * hours_elapsed)
return max(bac, 0.0)
# Example: 80kg male, 2 beers (5%, 355ml), 1 hour elapsed
drinks = [
{"abv": 5, "volume_ml": 355},
{"abv": 5, "volume_ml": 355},
]
bac = calculate_bac(drinks, weight_kg=80, gender="male", hours_elapsed=1)
print(f"Estimated BAC: {bac:.4f}%") # ~0.0367%
Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.