"""DOTS score: a powerlifting total adjusted for bodyweight and sex by the DOTS formula (Konertz, BVDK 2019), with the Wilks2 (Wilks 2020, 600-point) score beside it. Coefficients and bodyweight clamps as in the OpenPowerlifting reference implementation. Inputs: sex (male or female, default male), bodyweight_kg (30 to 250, default 83), total_kg (squat + bench + deadlift, 0.1 to 2000, default 500). Returns: dotsScore and wilksScore, in points. mysi, DOTS score, mysi.dev/dots-score, version 1, changed 2026-12-04. MIT. """ def _dots_score_num(name, value, low, high): if isinstance(value, bool) or not isinstance(value, (int, float)) or not low <= value <= high: raise ValueError(f"{name} must be a number from {low} to {high}") return float(value) def dots_score(sex="male", bodyweight_kg=83, total_kg=500): if sex not in ("male", "female"): raise ValueError("sex must be one of: male, female") bw = _dots_score_num("bodyweight_kg", bodyweight_kg, 30, 250) total = _dots_score_num("total_kg", total_kg, 0.1, 2000) # DOTS: a, b, c, d, e of a·x^4 + b·x^3 + c·x^2 + d·x + e; bodyweight clamped to the fit if sex == "male": k, lo, hi = (-0.000001093, 0.0007391293, -0.1918759221, 24.0900756, -307.75076), 40, 210 else: k, lo, hi = (-0.0000010706, 0.0005158568, -0.1126655495, 13.6175032, -57.96288), 40, 150 x = min(hi, max(lo, bw)) dots = total * 500 / (k[0] * x ** 4 + k[1] * x ** 3 + k[2] * x ** 2 + k[3] * x + k[4]) # Wilks2 (2020): a + b·x + c·x^2 + d·x^3 + e·x^4 + f·x^5, numerator 600 if sex == "male": w, lo, hi = (47.4617885411949, 8.47206137941125, 0.073694103462609, -0.00139583381094385, 7.07665973070743e-6, -1.20804336482315e-8), 40, 200.95 else: w, lo, hi = (-125.425539779509, 13.7121941940668, -0.0330725063103405, -0.0010504000506583, 9.38773881462799e-6, -2.3334613884954e-8), 40, 150.95 x = min(hi, max(lo, bw)) wilks = total * 600 / sum(c * x ** i for i, c in enumerate(w)) return {"dotsScore": dots, "wilksScore": wilks} DOTS_SCORE_CASES = [ ({"sex": "female", "bodyweight_kg": 63, "total_kg": 380}, {"dotsScore": 408.696, "wilksScore": 485.876}), ({"sex": "male", "bodyweight_kg": 80, "total_kg": 1000}, {"wilksScore": 819.1}), ({"sex": "female", "bodyweight_kg": 60, "total_kg": 1000}, {"wilksScore": 1319.0}), ] def dots_score_check(tolerance=1e-3): for given, want in DOTS_SCORE_CASES: got = dots_score(**given) for name, value in want.items(): close = abs(got[name] - value) <= tolerance * max(1, abs(value)) assert close, (name, got[name], value) return "ok" if __name__ == "__main__": import json, sys dots_score_check() given = dict(a.split("=", 1) for a in sys.argv[1:] if "=" in a) js = lambda v: v.lstrip("-")[:1].isdigit() or v[:1] in '[{".' or v in ("true", "false", "null") given = {k: json.loads(v) if js(v) else v for k, v in given.items()} if given: print(json.dumps(dots_score(**given)))