boozelib

A Python module containing a couple of functions to calculate the blood alcohol content of people.

It’s at home at https://github.com/brutus/boozelib/

Install

You can install it from PyPi, it is known as boozelib and has no dependencies:

pip install --user boozelib

Global Variables

This uses some constants and one variable you might want to review:

  • ALCOHOL_DEGRADATION: the default value for alcohol degradation; meaning the amount of alcohol (in gram) your body is degrading per minute, per kilogram body weight. This is usually a value between 0.0017 and 0.0025 (about 0.1—0.2 per thousand per hour).

Functions

The two main functions are:

boozelib.get_blood_alcohol_content(*, age: int, weight: int, height: int, sex: bool, volume: int, percent: float) → float[source]

Return the blood alcohol contents raise (per mill) for a person after a drink.

Given a drink containing volume (ml) of alcohol with the percent (vol/vol), for a person with age (years), weight (kg) and height (cm), using the formular for “female body types” if sex is true.

boozelib.get_blood_alcohol_degradation(*, age: int, weight: int, height: int, sex: bool, minutes: int = 1, degradation: Optional[float] = None) → float[source]

Return the alcohol degradation (per mill) for a person over minutes.

For a person with age (years), weight (kg) and height (cm), using the formular for “female body types” if sex is true, over the given minutes. If degradation is not set, ALCOHOL_DEGRADATION is used as default.

Examples

Return the blood alcohol contents raise (per mill) for a person after a drink:

>>> get_blood_alcohol_content(
...     age=32, weight=96, height=186, sex=False, volume=500, percent=4.9
... )
0.28773587455687716
>>> get_blood_alcohol_content(
...     age=32, weight=48, height=162, sex=True, volume=500, percent=4.9
... )
0.5480779730398769

And to calculate alcohol degradation:

>>> get_blood_alcohol_degradation(
...     age=32, weight=96, height=186, sex=False, minutes=60
... )
0.21139778538872606
>>> get_blood_alcohol_degradation(
...     age=32, weight=48, height=162, sex=True, minutes=60
... )
0.20133476560648536

You can change the default for alcohol degradation globally via setting ALCOHOL_DEGRADATION. Or change the value for alcohol degradation per call:

>>> get_blood_alcohol_degradation(
...     age=32, weight=48, height=162, sex=True, minutes=60, degradation=0.002
... )
0.16106781248518828

Thanks and Contributions

  • Big hugs to Mathilda for hanging around and helping me figuring out all that math and biology stuff.

If you find any bugs, issues or anything, please use the issue tracker on GitHub.