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AAMC,EAAe","names":["LENGTH_SD","normalCdf","z","x","erf","lengthPercentile","cm","AVERAGE_SIZE","lengthRankLabel","p","fmtLen","unit","updatedAgo","iso","now","days","CLASH_TIE_CM"],"sources":["../../../../../../src/lib/sculpt/stats.ts"],"sourcesContent":["// Display numbers around a sculpt: where its length sits in the population, and small formatters\n// shared by the profile card, the share page and the OG images. Pure, client + server safe.\nimport { AVERAGE_SIZE } from './params';\n\n/** Erect length SD in cm (Veale et al., BJU International 2015, the same study as AVERAGE_SIZE). */\nexport const LENGTH_SD = 1.66;\n\n/** Standard normal CDF (Abramowitz-Stegun 7.1.26 erf, |error| < 1.5e-7). */\nexport function normalCdf(z: number): number {\n\tconst x = Math.abs(z) / Math.SQRT2;\n\tconst t = 1 / (1 + 0.3275911 * x);\n\tconst erf =\n\t\t1 -\n\t\t((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) *\n\t\t\tt *\n\t\t\tMath.exp(-x * x);\n\treturn z >= 0 ? (1 + erf) / 2 : (1 - erf) / 2;\n}\n\n/** Share of men shorter than `cm` (0..1), normal around AVERAGE_SIZE.length. */\nexport function lengthPercentile(cm: number): number {\n\treturn normalCdf((cm - AVERAGE_SIZE.length) / LENGTH_SD);\n}\n\n/** \"Top 18%\" at or above the mean, \"Bottom 7%\" below it. Never 0%: tails read as 1%. */\nexport function lengthRankLabel(cm: number): string {\n\tconst p = lengthPercentile(cm);\n\tif (p >= 0.5) return `Top ${Math.max(1, Math.round((1 - p) * 100))}%`;\n\treturn `Bottom ${Math.max(1, Math.round(p * 100))}%`;\n}\n\nexport type Units = 'cm' | 'in';\nexport const fmtLen = (cm: number, unit: Units = 'cm') =>\n\tunit === 'cm' ? cm.toFixed(1) + ' cm' : (cm / 2.54).toFixed(2) + ' in';\n\n/** \"today\", \"2d ago\", \"3w ago\", \"5mo ago\" for the card's \"updated\" line. */\nexport function updatedAgo(iso: string, now = Date.now()): string {\n\tconst days = Math.floor((now - new Date(iso).getTime()) / 86_400_000);\n\tif (!Number.isFinite(days) || days < 1) return 'today';\n\tif (days < 7) return `${days}d ago`;\n\tif (days < 30) return `${Math.floor(days / 7)}w ago`;\n\tif (days < 365) return `${Math.floor(days / 30)}mo ago`;\n\treturn `${Math.floor(days / 365)}y ago`;\n}\n\n/** Below this length gap (cm) a clash is a draw (\"Dead even\"), as in the show's verdict. */\nexport const CLASH_TIE_CM = 0.3;\n\n/** RAT-653: a sculpt page's scoreboard. `tried` = others who clashed its owner, `short` = how many of\n *  them lost (the owner longer by CLASH_TIE_CM or more, the show's verdict). */\nexport type ClashScoreboard = { tried: number; short: number };\n\n/** One row per challenger (their latest clash against the owner). A side whose sculpt was deleted\n *  (`gone`) or a length the snapshot lacks leaves the row out. */\nexport function clashScoreboard(\n\trows: readonly { challengerLength: number | null; ownerLength: number | null; gone: boolean }[]\n): ClashScoreboard {\n\tlet tried = 0;\n\tlet short = 0;\n\tfor (const r of rows) {\n\t\tif (r.gone || !Number.isFinite(r.challengerLength) || !Number.isFinite(r.ownerLength)) continue;\n\t\ttried++;\n\t\tif ((r.ownerLength as number) - (r.challengerLength as number) >= CLASH_TIE_CM) short++;\n\t}\n\treturn { tried, short };\n}\n\nexport interface ClashStats {\n\t/** a.length - b.length, cm */\n\tlengthDiff: number;\n\t/** a vs b in percent, e.g. 12 = a is 12% bigger */\n\tlengthPct: number;\n\tgirthPct: number;\n\tvolumePct: number;\n}\n\n/** The clash numbers without three: the formula of render/clash.ts clashResult (volume of a\n *  cylinder), for the server and the feed card. */\nexport function clashStats(\n\ta: { length: number; girth: number },\n\tb: { length: number; girth: number }\n): ClashStats {\n\tconst vol = (p: { length: number; girth: number }) => (p.girth / (2 * Math.PI)) ** 2 * Math.PI * p.length;\n\treturn {\n\t\tlengthDiff: a.length - b.length,\n\t\tlengthPct: (a.length / b.length - 1) * 100,\n\t\tgirthPct: (a.girth / b.girth - 1) * 100,\n\t\tvolumePct: (vol(a) / vol(b) - 1) * 100\n\t};\n}\n"],"version":3}