extract_nist.py

back to table · edit · history · where entries came from · files · download

1604 bytes, as of the version from 2026-10-16 06:19 (current). Recorded here, not run.

"""Extract NIST's rendered critical-value table, excluding HTML comments.

    python3 extract_nist.py

Reads nist-source.html beside this file and writes nist-critical-values.json.
Source: https://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm
The HTML includes an obsolete table inside a comment. It is not evidence
for the currently displayed values; in particular it has 318.313 in place
of the corrected 318.309 for nu=1, p=999/1000.
"""
import hashlib
import json
import re
from html.parser import HTMLParser
from pathlib import Path

class VisibleText(HTMLParser):
    def __init__(self):
        super().__init__()
        self.chunks=[]
    def handle_data(self, data):
        self.chunks.append(data)

root=Path(__file__).parent
raw=(root/'nist-source.html').read_bytes()
parser=VisibleText(); parser.feed(raw.decode())
visible=''.join(parser.chunks).split('Normal Values')[0]
rows=re.findall(r'^\s*(\d+)\.\s+((?:\d+\.\d+\s+){5}\d+\.\d+)',visible,re.M)
ps=['9/10','19/20','39/40','99/100','199/200','999/1000']
assert len(rows)==100 and len({n for n,r in rows})==100
values={n:dict(zip(ps,row.split())) for n,row in rows}
assert values['1']['999/1000']=='318.309'
(root/'nist-critical-values.json').write_text(json.dumps({
    'source':'https://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm',
    'retrieved':'2026-10-16','source_sha256':hashlib.sha256(raw).hexdigest(),
    'extraction':'Rendered text; HTML comments excluded; normal-limit row excluded.',
    'values':values},indent=2))
print('Extracted 100 displayed degree rows; obsolete commented table excluded.')