{
  "schemaVersion": 1,
  "slug": "blood-alcohol-calculator",
  "category": "health",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "357c1f84226c40deb824eea2c967c1f88167917be1754d3cc7677baffb27b65a",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/blood-alcohol-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "BAC = max(100·14n/(1000·W·r) − 0.015t, 0)",
    "vars": [
      [
        "n",
        "Standard drinks (14 g alcohol each)"
      ],
      [
        "W",
        "Body weight (kg)"
      ],
      [
        "r",
        "Widmark factor (0.55 female, 0.68 male)"
      ],
      [
        "t",
        "Hours since drinking"
      ],
      [
        "BAC",
        "Blood alcohol content (%)"
      ]
    ],
    "note": "Estimate only; the body eliminates roughly 0.015% per hour; time to sober = peak ÷ 0.015; weight is converted from kilograms to grams."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const r=sex==='female'?0.55:0.68,grams=drinks*14,peak=(grams/(weight*1000*r))*100,bac=Math.max(peak-0.015*hours,0);return{bac,grams,hoursToSober:bac/0.015};",
    "inputs": [
      {
        "name": "sex",
        "type": "select",
        "default": "male",
        "options": [
          {
            "value": "male"
          },
          {
            "value": "female"
          }
        ]
      },
      {
        "name": "weight",
        "type": "number",
        "default": 75,
        "min": 20,
        "max": 400,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "drinks",
        "type": "number",
        "default": 2,
        "min": 0,
        "max": 50,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "hours",
        "type": "number",
        "default": 2,
        "min": 0,
        "max": 48,
        "step": 0.25,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "bac",
        "precision": 3,
        "unit": "%"
      },
      {
        "name": "grams",
        "precision": 1,
        "unit": "g"
      },
      {
        "name": "hoursToSober",
        "precision": 1,
        "unit": "h"
      }
    ],
    "interpret": null
  }
}
