data-analyst-mcp 0.0.0-stage → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +261 -2
- package/dist/adapters/_acf_tidy.d.ts +18 -0
- package/dist/adapters/_acf_tidy.js +432 -0
- package/dist/adapters/_acf_tidy.js.map +1 -0
- package/dist/adapters/_actuaries_read.d.ts +38 -0
- package/dist/adapters/_actuaries_read.js +728 -0
- package/dist/adapters/_actuaries_read.js.map +1 -0
- package/dist/adapters/_census_micro.d.ts +70 -0
- package/dist/adapters/_census_micro.js +622 -0
- package/dist/adapters/_census_micro.js.map +1 -0
- package/dist/adapters/_census_util.d.ts +40 -0
- package/dist/adapters/_census_util.js +275 -0
- package/dist/adapters/_census_util.js.map +1 -0
- package/dist/adapters/_dol_states.d.ts +6 -0
- package/dist/adapters/_dol_states.js +58 -0
- package/dist/adapters/_dol_states.js.map +1 -0
- package/dist/adapters/_govinfo_entities.d.ts +4 -0
- package/dist/adapters/_govinfo_entities.js +6 -0
- package/dist/adapters/_govinfo_entities.js.map +1 -0
- package/dist/adapters/_govinfo_json.d.ts +13 -0
- package/dist/adapters/_govinfo_json.js +107 -0
- package/dist/adapters/_govinfo_json.js.map +1 -0
- package/dist/adapters/_govinfo_py.d.ts +22 -0
- package/dist/adapters/_govinfo_py.js +272 -0
- package/dist/adapters/_govinfo_py.js.map +1 -0
- package/dist/adapters/_govinfo_xml.d.ts +22 -0
- package/dist/adapters/_govinfo_xml.js +233 -0
- package/dist/adapters/_govinfo_xml.js.map +1 -0
- package/dist/adapters/_hud_excel.d.ts +2 -0
- package/dist/adapters/_hud_excel.js +166 -0
- package/dist/adapters/_hud_excel.js.map +1 -0
- package/dist/adapters/_omb_grid.d.ts +17 -0
- package/dist/adapters/_omb_grid.js +132 -0
- package/dist/adapters/_omb_grid.js.map +1 -0
- package/dist/adapters/_omb_util.d.ts +40 -0
- package/dist/adapters/_omb_util.js +192 -0
- package/dist/adapters/_omb_util.js.map +1 -0
- package/dist/adapters/_usaspending_state.d.ts +6 -0
- package/dist/adapters/_usaspending_state.js +54 -0
- package/dist/adapters/_usaspending_state.js.map +1 -0
- package/dist/adapters/_usda-fna_book.d.ts +59 -0
- package/dist/adapters/_usda-fna_book.js +869 -0
- package/dist/adapters/_usda-fna_book.js.map +1 -0
- package/dist/adapters/_usda-fna_pdf.d.ts +20 -0
- package/dist/adapters/_usda-fna_pdf.js +361 -0
- package/dist/adapters/_usda-fna_pdf.js.map +1 -0
- package/dist/adapters/_usda-outlook_read.d.ts +70 -0
- package/dist/adapters/_usda-outlook_read.js +362 -0
- package/dist/adapters/_usda-outlook_read.js.map +1 -0
- package/dist/adapters/acf.d.ts +3 -0
- package/dist/adapters/acf.js +187 -0
- package/dist/adapters/acf.js.map +1 -0
- package/dist/adapters/actuaries.d.ts +3 -0
- package/dist/adapters/actuaries.js +293 -0
- package/dist/adapters/actuaries.js.map +1 -0
- package/dist/adapters/bts.d.ts +3 -0
- package/dist/adapters/bts.js +26 -0
- package/dist/adapters/bts.js.map +1 -0
- package/dist/adapters/census-geocoder.d.ts +10 -0
- package/dist/adapters/census-geocoder.js +47 -0
- package/dist/adapters/census-geocoder.js.map +1 -0
- package/dist/adapters/census.d.ts +17 -0
- package/dist/adapters/census.js +983 -0
- package/dist/adapters/census.js.map +1 -0
- package/dist/adapters/cfpb.d.ts +7 -0
- package/dist/adapters/cfpb.js +348 -0
- package/dist/adapters/cfpb.js.map +1 -0
- package/dist/adapters/clinical-trials.d.ts +3 -0
- package/dist/adapters/clinical-trials.js +135 -0
- package/dist/adapters/clinical-trials.js.map +1 -0
- package/dist/adapters/cms.d.ts +3 -0
- package/dist/adapters/cms.js +292 -0
- package/dist/adapters/cms.js.map +1 -0
- package/dist/adapters/college-scorecard.d.ts +3 -0
- package/dist/adapters/college-scorecard.js +122 -0
- package/dist/adapters/college-scorecard.js.map +1 -0
- package/dist/adapters/congress.d.ts +33 -0
- package/dist/adapters/congress.js +589 -0
- package/dist/adapters/congress.js.map +1 -0
- package/dist/adapters/dhs-ohss.d.ts +13 -0
- package/dist/adapters/dhs-ohss.js +598 -0
- package/dist/adapters/dhs-ohss.js.map +1 -0
- package/dist/adapters/doj-news.d.ts +7 -0
- package/dist/adapters/doj-news.js +286 -0
- package/dist/adapters/doj-news.js.map +1 -0
- package/dist/adapters/dol.d.ts +4 -0
- package/dist/adapters/dol.js +634 -0
- package/dist/adapters/dol.js.map +1 -0
- package/dist/adapters/eia.d.ts +15 -0
- package/dist/adapters/eia.js +456 -0
- package/dist/adapters/eia.js.map +1 -0
- package/dist/adapters/epa-aqs.d.ts +3 -0
- package/dist/adapters/epa-aqs.js +357 -0
- package/dist/adapters/epa-aqs.js.map +1 -0
- package/dist/adapters/epa.d.ts +3 -0
- package/dist/adapters/epa.js +298 -0
- package/dist/adapters/epa.js.map +1 -0
- package/dist/adapters/fbi.d.ts +3 -0
- package/dist/adapters/fbi.js +192 -0
- package/dist/adapters/fbi.js.map +1 -0
- package/dist/adapters/fda.d.ts +5 -0
- package/dist/adapters/fda.js +184 -0
- package/dist/adapters/fda.js.map +1 -0
- package/dist/adapters/fdic.d.ts +4 -0
- package/dist/adapters/fdic.js +95 -0
- package/dist/adapters/fdic.js.map +1 -0
- package/dist/adapters/fec.d.ts +3 -0
- package/dist/adapters/fec.js +142 -0
- package/dist/adapters/fec.js.map +1 -0
- package/dist/adapters/fed-board.d.ts +12 -0
- package/dist/adapters/fed-board.js +581 -0
- package/dist/adapters/fed-board.js.map +1 -0
- package/dist/adapters/federal-register.d.ts +11 -0
- package/dist/adapters/federal-register.js +43 -0
- package/dist/adapters/federal-register.js.map +1 -0
- package/dist/adapters/fhfa.d.ts +3 -0
- package/dist/adapters/fhfa.js +253 -0
- package/dist/adapters/fhfa.js.map +1 -0
- package/dist/adapters/fsa.d.ts +9 -0
- package/dist/adapters/fsa.js +335 -0
- package/dist/adapters/fsa.js.map +1 -0
- package/dist/adapters/govinfo.d.ts +30 -0
- package/dist/adapters/govinfo.js +636 -0
- package/dist/adapters/govinfo.js.map +1 -0
- package/dist/adapters/gsa-calc.d.ts +10 -0
- package/dist/adapters/gsa-calc.js +318 -0
- package/dist/adapters/gsa-calc.js.map +1 -0
- package/dist/adapters/hud.d.ts +3 -0
- package/dist/adapters/hud.js +200 -0
- package/dist/adapters/hud.js.map +1 -0
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/index.js +25 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/irs-soi.d.ts +6 -0
- package/dist/adapters/irs-soi.js +576 -0
- package/dist/adapters/irs-soi.js.map +1 -0
- package/dist/adapters/naep.d.ts +15 -0
- package/dist/adapters/naep.js +341 -0
- package/dist/adapters/naep.js.map +1 -0
- package/dist/adapters/nhtsa.d.ts +10 -0
- package/dist/adapters/nhtsa.js +239 -0
- package/dist/adapters/nhtsa.js.map +1 -0
- package/dist/adapters/nih.d.ts +5 -0
- package/dist/adapters/nih.js +196 -0
- package/dist/adapters/nih.js.map +1 -0
- package/dist/adapters/noaa.d.ts +3 -0
- package/dist/adapters/noaa.js +148 -0
- package/dist/adapters/noaa.js.map +1 -0
- package/dist/adapters/nrel.d.ts +3 -0
- package/dist/adapters/nrel.js +186 -0
- package/dist/adapters/nrel.js.map +1 -0
- package/dist/adapters/nws.d.ts +3 -0
- package/dist/adapters/nws.js +119 -0
- package/dist/adapters/nws.js.map +1 -0
- package/dist/adapters/omb.d.ts +15 -0
- package/dist/adapters/omb.js +517 -0
- package/dist/adapters/omb.js.map +1 -0
- package/dist/adapters/open-payments.d.ts +5 -0
- package/dist/adapters/open-payments.js +149 -0
- package/dist/adapters/open-payments.js.map +1 -0
- package/dist/adapters/pbgc.d.ts +13 -0
- package/dist/adapters/pbgc.js +283 -0
- package/dist/adapters/pbgc.js.map +1 -0
- package/dist/adapters/philfed.d.ts +12 -0
- package/dist/adapters/philfed.js +59 -0
- package/dist/adapters/philfed.js.map +1 -0
- package/dist/adapters/regulations.d.ts +6 -0
- package/dist/adapters/regulations.js +58 -0
- package/dist/adapters/regulations.js.map +1 -0
- package/dist/adapters/sec.d.ts +13 -0
- package/dist/adapters/sec.js +504 -0
- package/dist/adapters/sec.js.map +1 -0
- package/dist/adapters/senate-lobbying.d.ts +3 -0
- package/dist/adapters/senate-lobbying.js +181 -0
- package/dist/adapters/senate-lobbying.js.map +1 -0
- package/dist/adapters/snapqc.d.ts +32 -0
- package/dist/adapters/snapqc.js +701 -0
- package/dist/adapters/snapqc.js.map +1 -0
- package/dist/adapters/treasury-yields.d.ts +3 -0
- package/dist/adapters/treasury-yields.js +170 -0
- package/dist/adapters/treasury-yields.js.map +1 -0
- package/dist/adapters/usaspending.d.ts +3 -0
- package/dist/adapters/usaspending.js +340 -0
- package/dist/adapters/usaspending.js.map +1 -0
- package/dist/adapters/usda-fna.d.ts +7 -0
- package/dist/adapters/usda-fna.js +707 -0
- package/dist/adapters/usda-fna.js.map +1 -0
- package/dist/adapters/usda-fooddata.d.ts +3 -0
- package/dist/adapters/usda-fooddata.js +101 -0
- package/dist/adapters/usda-fooddata.js.map +1 -0
- package/dist/adapters/usda-nass.d.ts +3 -0
- package/dist/adapters/usda-nass.js +108 -0
- package/dist/adapters/usda-nass.js.map +1 -0
- package/dist/adapters/usda-outlook.d.ts +12 -0
- package/dist/adapters/usda-outlook.js +696 -0
- package/dist/adapters/usda-outlook.js.map +1 -0
- package/dist/adapters/usgs.d.ts +9 -0
- package/dist/adapters/usgs.js +265 -0
- package/dist/adapters/usgs.js.map +1 -0
- package/dist/adapters/usitc.d.ts +18 -0
- package/dist/adapters/usitc.js +170 -0
- package/dist/adapters/usitc.js.map +1 -0
- package/dist/adapters/uspto.d.ts +3 -0
- package/dist/adapters/uspto.js +47 -0
- package/dist/adapters/uspto.js.map +1 -0
- package/dist/adapters/world-bank.d.ts +3 -0
- package/dist/adapters/world-bank.js +163 -0
- package/dist/adapters/world-bank.js.map +1 -0
- package/dist/analysis/cite.d.ts +31 -0
- package/dist/analysis/cite.js +229 -0
- package/dist/analysis/cite.js.map +1 -0
- package/dist/analysis/combine.d.ts +27 -0
- package/dist/analysis/combine.js +198 -0
- package/dist/analysis/combine.js.map +1 -0
- package/dist/analysis/compute.d.ts +62 -0
- package/dist/analysis/compute.js +583 -0
- package/dist/analysis/compute.js.map +1 -0
- package/dist/analysis/expr.d.ts +69 -0
- package/dist/analysis/expr.js +780 -0
- package/dist/analysis/expr.js.map +1 -0
- package/dist/analysis/factfmt.d.ts +16 -0
- package/dist/analysis/factfmt.js +187 -0
- package/dist/analysis/factfmt.js.map +1 -0
- package/dist/analysis/facts.d.ts +63 -0
- package/dist/analysis/facts.js +355 -0
- package/dist/analysis/facts.js.map +1 -0
- package/dist/analysis/handoff.d.ts +58 -0
- package/dist/analysis/handoff.js +208 -0
- package/dist/analysis/handoff.js.map +1 -0
- package/dist/analysis/pyfmt.d.ts +16 -0
- package/dist/analysis/pyfmt.js +156 -0
- package/dist/analysis/pyfmt.js.map +1 -0
- package/dist/analysis/rerun.d.ts +13 -0
- package/dist/analysis/rerun.js +125 -0
- package/dist/analysis/rerun.js.map +1 -0
- package/dist/analysis/table.d.ts +18 -0
- package/dist/analysis/table.js +109 -0
- package/dist/analysis/table.js.map +1 -0
- package/dist/analysis/tools.d.ts +67 -0
- package/dist/analysis/tools.js +217 -0
- package/dist/analysis/tools.js.map +1 -0
- package/dist/analysis/write_table.d.ts +13 -0
- package/dist/analysis/write_table.js +59 -0
- package/dist/analysis/write_table.js.map +1 -0
- package/dist/bin/cli.d.ts +10 -0
- package/dist/bin/cli.js +177 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/core/cache.d.ts +14 -0
- package/dist/core/cache.js +90 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/context.d.ts +12 -0
- package/dist/core/context.js +15 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/env.d.ts +14 -0
- package/dist/core/env.js +52 -0
- package/dist/core/env.js.map +1 -0
- package/dist/core/generic-rest.d.ts +61 -0
- package/dist/core/generic-rest.js +639 -0
- package/dist/core/generic-rest.js.map +1 -0
- package/dist/core/http.d.ts +120 -0
- package/dist/core/http.js +514 -0
- package/dist/core/http.js.map +1 -0
- package/dist/core/keys.d.ts +43 -0
- package/dist/core/keys.js +174 -0
- package/dist/core/keys.js.map +1 -0
- package/dist/core/manual.d.ts +41 -0
- package/dist/core/manual.js +218 -0
- package/dist/core/manual.js.map +1 -0
- package/dist/core/package.d.ts +58 -0
- package/dist/core/package.js +228 -0
- package/dist/core/package.js.map +1 -0
- package/dist/core/packs.d.ts +139 -0
- package/dist/core/packs.js +173 -0
- package/dist/core/packs.js.map +1 -0
- package/dist/core/policy.d.ts +69 -0
- package/dist/core/policy.js +189 -0
- package/dist/core/policy.js.map +1 -0
- package/dist/core/py.d.ts +40 -0
- package/dist/core/py.js +171 -0
- package/dist/core/py.js.map +1 -0
- package/dist/core/routing.d.ts +10 -0
- package/dist/core/routing.js +39 -0
- package/dist/core/routing.js.map +1 -0
- package/dist/core/tabular.d.ts +21 -0
- package/dist/core/tabular.js +229 -0
- package/dist/core/tabular.js.map +1 -0
- package/dist/deep/_bea_api.d.ts +102 -0
- package/dist/deep/_bea_api.js +457 -0
- package/dist/deep/_bea_api.js.map +1 -0
- package/dist/deep/_bea_fetch.d.ts +151 -0
- package/dist/deep/_bea_fetch.js +1274 -0
- package/dist/deep/_bea_fetch.js.map +1 -0
- package/dist/deep/_bea_util.d.ts +14 -0
- package/dist/deep/_bea_util.js +156 -0
- package/dist/deep/_bea_util.js.map +1 -0
- package/dist/deep/_bls_api.d.ts +84 -0
- package/dist/deep/_bls_api.js +231 -0
- package/dist/deep/_bls_api.js.map +1 -0
- package/dist/deep/_bls_ids.d.ts +43 -0
- package/dist/deep/_bls_ids.js +188 -0
- package/dist/deep/_bls_ids.js.map +1 -0
- package/dist/deep/_bls_lib.d.ts +61 -0
- package/dist/deep/_bls_lib.js +442 -0
- package/dist/deep/_bls_lib.js.map +1 -0
- package/dist/deep/_fred_api.d.ts +148 -0
- package/dist/deep/_fred_api.js +545 -0
- package/dist/deep/_fred_api.js.map +1 -0
- package/dist/deep/_fred_pack.d.ts +162 -0
- package/dist/deep/_fred_pack.js +1027 -0
- package/dist/deep/_fred_pack.js.map +1 -0
- package/dist/deep/_fred_py.d.ts +40 -0
- package/dist/deep/_fred_py.js +199 -0
- package/dist/deep/_fred_py.js.map +1 -0
- package/dist/deep/_ipums_bundle.d.ts +29 -0
- package/dist/deep/_ipums_bundle.js +194 -0
- package/dist/deep/_ipums_bundle.js.map +1 -0
- package/dist/deep/_ipums_ddi.d.ts +23 -0
- package/dist/deep/_ipums_ddi.js +162 -0
- package/dist/deep/_ipums_ddi.js.map +1 -0
- package/dist/deep/_opm_io.d.ts +26 -0
- package/dist/deep/_opm_io.js +383 -0
- package/dist/deep/_opm_io.js.map +1 -0
- package/dist/deep/_opm_parquet.d.ts +31 -0
- package/dist/deep/_opm_parquet.js +744 -0
- package/dist/deep/_opm_parquet.js.map +1 -0
- package/dist/deep/_opm_py.d.ts +6 -0
- package/dist/deep/_opm_py.js +74 -0
- package/dist/deep/_opm_py.js.map +1 -0
- package/dist/deep/_treasury_api.d.ts +48 -0
- package/dist/deep/_treasury_api.js +221 -0
- package/dist/deep/_treasury_api.js.map +1 -0
- package/dist/deep/_treasury_context.d.ts +34 -0
- package/dist/deep/_treasury_context.js +142 -0
- package/dist/deep/_treasury_context.js.map +1 -0
- package/dist/deep/_treasury_lib.d.ts +109 -0
- package/dist/deep/_treasury_lib.js +686 -0
- package/dist/deep/_treasury_lib.js.map +1 -0
- package/dist/deep/bea.d.ts +3 -0
- package/dist/deep/bea.js +248 -0
- package/dist/deep/bea.js.map +1 -0
- package/dist/deep/bls.d.ts +3 -0
- package/dist/deep/bls.js +220 -0
- package/dist/deep/bls.js.map +1 -0
- package/dist/deep/fred.d.ts +3 -0
- package/dist/deep/fred.js +325 -0
- package/dist/deep/fred.js.map +1 -0
- package/dist/deep/ipums.d.ts +59 -0
- package/dist/deep/ipums.js +744 -0
- package/dist/deep/ipums.js.map +1 -0
- package/dist/deep/opm.d.ts +56 -0
- package/dist/deep/opm.js +1033 -0
- package/dist/deep/opm.js.map +1 -0
- package/dist/deep/treasury.d.ts +3 -0
- package/dist/deep/treasury.js +218 -0
- package/dist/deep/treasury.js.map +1 -0
- package/dist/envelope.d.ts +47 -0
- package/dist/envelope.js +88 -0
- package/dist/envelope.js.map +1 -0
- package/dist/index.d.ts +277 -0
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -0
- package/dist/remote/app.d.ts +21 -0
- package/dist/remote/app.js +218 -0
- package/dist/remote/app.js.map +1 -0
- package/dist/remote/oauth.d.ts +14 -0
- package/dist/remote/oauth.js +90 -0
- package/dist/remote/oauth.js.map +1 -0
- package/dist/remote/pages.d.ts +8 -0
- package/dist/remote/pages.js +56 -0
- package/dist/remote/pages.js.map +1 -0
- package/dist/remote/sign.d.ts +4 -0
- package/dist/remote/sign.js +40 -0
- package/dist/remote/sign.js.map +1 -0
- package/dist/remote/store.d.ts +31 -0
- package/dist/remote/store.js +129 -0
- package/dist/remote/store.js.map +1 -0
- package/dist/report/audit_answer.d.ts +94 -0
- package/dist/report/audit_answer.js +1349 -0
- package/dist/report/audit_answer.js.map +1 -0
- package/dist/report/audit_report.d.ts +23 -0
- package/dist/report/audit_report.js +637 -0
- package/dist/report/audit_report.js.map +1 -0
- package/dist/report/build_report.d.ts +27 -0
- package/dist/report/build_report.js +1168 -0
- package/dist/report/build_report.js.map +1 -0
- package/dist/report/method_audit.d.ts +47 -0
- package/dist/report/method_audit.js +716 -0
- package/dist/report/method_audit.js.map +1 -0
- package/dist/report/policyset.d.ts +50 -0
- package/dist/report/policyset.js +421 -0
- package/dist/report/policyset.js.map +1 -0
- package/dist/report/py.d.ts +58 -0
- package/dist/report/py.js +311 -0
- package/dist/report/py.js.map +1 -0
- package/dist/report/scan_secrets.d.ts +24 -0
- package/dist/report/scan_secrets.js +265 -0
- package/dist/report/scan_secrets.js.map +1 -0
- package/dist/report/style_check.d.ts +29 -0
- package/dist/report/style_check.js +173 -0
- package/dist/report/style_check.js.map +1 -0
- package/dist/report/tools.d.ts +87 -0
- package/dist/report/tools.js +167 -0
- package/dist/report/tools.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.js +247 -0
- package/dist/server.js.map +1 -0
- package/dist/session.d.ts +47 -0
- package/dist/session.js +107 -0
- package/dist/session.js.map +1 -0
- package/dist/toolkit.d.ts +21 -0
- package/dist/toolkit.js +2 -0
- package/dist/toolkit.js.map +1 -0
- package/dist/tools.d.ts +299 -0
- package/dist/tools.js +491 -0
- package/dist/tools.js.map +1 -0
- package/guide/WORKFLOW.md +134 -0
- package/guide/assets/disclaimer.txt +1 -0
- package/guide/assets/download_data.ps1 +162 -0
- package/guide/assets/download_data.sh +143 -0
- package/guide/assets/report_template.html +597 -0
- package/guide/references/report_patterns.md +199 -0
- package/guide/references/routing.md +171 -0
- package/guide/references/style_guide.md +398 -0
- package/package.json +54 -4
- package/packs/acf/endpoints.json +114 -0
- package/packs/acf/policy.json +104 -0
- package/packs/acf/source.md +138 -0
- package/packs/actuaries/endpoints.json +82 -0
- package/packs/actuaries/policy.json +109 -0
- package/packs/actuaries/source.md +137 -0
- package/packs/bea/assets/download_bea.ps1 +182 -0
- package/packs/bea/assets/download_bea.sh +144 -0
- package/packs/bea/docs/bea_api.md +461 -0
- package/packs/bea/docs/datasets.md +157 -0
- package/packs/bea/docs/report_patterns.md +112 -0
- package/packs/bea/policy.json +170 -0
- package/packs/bea/source.md +152 -0
- package/packs/bls/assets/download_bls.ps1 +152 -0
- package/packs/bls/assets/download_bls.sh +167 -0
- package/packs/bls/docs/analysis_patterns.md +108 -0
- package/packs/bls/docs/bls_api.md +73 -0
- package/packs/bls/docs/series_ids.md +149 -0
- package/packs/bls/policy.json +238 -0
- package/packs/bls/series_ids.json +1375 -0
- package/packs/bls/source.md +156 -0
- package/packs/bts/endpoints.json +347 -0
- package/packs/bts/policy.json +94 -0
- package/packs/bts/source.md +97 -0
- package/packs/cdc/endpoints.json +197 -0
- package/packs/cdc/policy.json +83 -0
- package/packs/cdc/source.md +74 -0
- package/packs/census/endpoints.json +99 -0
- package/packs/census/policy.json +238 -0
- package/packs/census/source.md +304 -0
- package/packs/census-geocoder/endpoints.json +70 -0
- package/packs/census-geocoder/policy.json +80 -0
- package/packs/census-geocoder/source.md +53 -0
- package/packs/cfpb/endpoints.json +327 -0
- package/packs/cfpb/policy.json +119 -0
- package/packs/cfpb/source.md +96 -0
- package/packs/clinical-trials/endpoints.json +167 -0
- package/packs/clinical-trials/policy.json +84 -0
- package/packs/clinical-trials/source.md +82 -0
- package/packs/cms/endpoints.json +69 -0
- package/packs/cms/policy.json +96 -0
- package/packs/cms/source.md +112 -0
- package/packs/college-scorecard/endpoints.json +253 -0
- package/packs/college-scorecard/policy.json +106 -0
- package/packs/college-scorecard/source.md +92 -0
- package/packs/congress/endpoints.json +1701 -0
- package/packs/congress/policy.json +117 -0
- package/packs/congress/source.md +190 -0
- package/packs/dhs-ohss/endpoints.json +66 -0
- package/packs/dhs-ohss/policy.json +107 -0
- package/packs/dhs-ohss/source.md +120 -0
- package/packs/doj-news/endpoints.json +59 -0
- package/packs/doj-news/policy.json +96 -0
- package/packs/doj-news/source.md +99 -0
- package/packs/dol/endpoints.json +818 -0
- package/packs/dol/policy.json +135 -0
- package/packs/dol/source.md +181 -0
- package/packs/eia/endpoints.json +718 -0
- package/packs/eia/policy.json +112 -0
- package/packs/eia/source.md +112 -0
- package/packs/epa/endpoints.json +292 -0
- package/packs/epa/policy.json +99 -0
- package/packs/epa/source.md +99 -0
- package/packs/epa-aqs/endpoints.json +174 -0
- package/packs/epa-aqs/policy.json +96 -0
- package/packs/epa-aqs/source.md +97 -0
- package/packs/fbi/endpoints.json +1842 -0
- package/packs/fbi/policy.json +118 -0
- package/packs/fbi/source.md +108 -0
- package/packs/fda/endpoints.json +238 -0
- package/packs/fda/policy.json +121 -0
- package/packs/fda/source.md +117 -0
- package/packs/fdic/endpoints.json +417 -0
- package/packs/fdic/policy.json +83 -0
- package/packs/fdic/source.md +92 -0
- package/packs/fec/endpoints.json +708 -0
- package/packs/fec/policy.json +93 -0
- package/packs/fec/source.md +90 -0
- package/packs/fed-board/endpoints.json +89 -0
- package/packs/fed-board/policy.json +136 -0
- package/packs/fed-board/source.md +118 -0
- package/packs/federal-register/endpoints.json +143 -0
- package/packs/federal-register/policy.json +86 -0
- package/packs/federal-register/source.md +98 -0
- package/packs/fema/endpoints.json +646 -0
- package/packs/fema/policy.json +103 -0
- package/packs/fema/source.md +103 -0
- package/packs/fhfa/endpoints.json +105 -0
- package/packs/fhfa/policy.json +109 -0
- package/packs/fhfa/source.md +108 -0
- package/packs/fred/assets/download_fred.ps1 +122 -0
- package/packs/fred/assets/download_fred.sh +123 -0
- package/packs/fred/docs/analysis_patterns.md +124 -0
- package/packs/fred/docs/fred_api.md +94 -0
- package/packs/fred/docs/series.md +188 -0
- package/packs/fred/policy.json +253 -0
- package/packs/fred/source.md +142 -0
- package/packs/fsa/endpoints.json +150 -0
- package/packs/fsa/policy.json +99 -0
- package/packs/fsa/source.md +102 -0
- package/packs/govinfo/endpoints.json +520 -0
- package/packs/govinfo/policy.json +116 -0
- package/packs/govinfo/source.md +241 -0
- package/packs/gsa-calc/endpoints.json +93 -0
- package/packs/gsa-calc/policy.json +97 -0
- package/packs/gsa-calc/source.md +108 -0
- package/packs/hud/endpoints.json +147 -0
- package/packs/hud/policy.json +84 -0
- package/packs/hud/source.md +97 -0
- package/packs/ipums/assets/download_ipums.ps1 +215 -0
- package/packs/ipums/assets/download_ipums.sh +192 -0
- package/packs/ipums/docs/ipums_api.md +67 -0
- package/packs/ipums/docs/report_patterns.md +117 -0
- package/packs/ipums/docs/variables.md +284 -0
- package/packs/ipums/lib/fetch_text.json +112 -0
- package/packs/ipums/policy.json +215 -0
- package/packs/ipums/source.md +169 -0
- package/packs/irs-soi/endpoints.json +114 -0
- package/packs/irs-soi/policy.json +107 -0
- package/packs/irs-soi/source.md +124 -0
- package/packs/medicaid/endpoints.json +412 -0
- package/packs/medicaid/policy.json +108 -0
- package/packs/medicaid/source.md +136 -0
- package/packs/naep/endpoints.json +217 -0
- package/packs/naep/policy.json +100 -0
- package/packs/naep/source.md +120 -0
- package/packs/nhtsa/endpoints.json +132 -0
- package/packs/nhtsa/policy.json +93 -0
- package/packs/nhtsa/source.md +109 -0
- package/packs/nih/endpoints.json +453 -0
- package/packs/nih/policy.json +86 -0
- package/packs/nih/source.md +108 -0
- package/packs/noaa/endpoints.json +432 -0
- package/packs/noaa/policy.json +95 -0
- package/packs/noaa/source.md +88 -0
- package/packs/nrel/endpoints.json +328 -0
- package/packs/nrel/policy.json +96 -0
- package/packs/nrel/source.md +91 -0
- package/packs/nws/endpoints.json +272 -0
- package/packs/nws/policy.json +82 -0
- package/packs/nws/source.md +81 -0
- package/packs/nyfed/endpoints.json +80 -0
- package/packs/nyfed/policy.json +92 -0
- package/packs/nyfed/source.md +89 -0
- package/packs/omb/endpoints.json +460 -0
- package/packs/omb/policy.json +106 -0
- package/packs/omb/source.md +130 -0
- package/packs/open-payments/endpoints.json +298 -0
- package/packs/open-payments/policy.json +101 -0
- package/packs/open-payments/source.md +99 -0
- package/packs/opm/assets/download_opm.ps1 +125 -0
- package/packs/opm/assets/download_opm.sh +85 -0
- package/packs/opm/docs/fields.md +184 -0
- package/packs/opm/docs/opm_api.md +71 -0
- package/packs/opm/docs/report_patterns.md +83 -0
- package/packs/opm/lib/data_dictionary.csv +73 -0
- package/packs/opm/policy.json +142 -0
- package/packs/opm/source.md +137 -0
- package/packs/pbgc/endpoints.json +483 -0
- package/packs/pbgc/policy.json +94 -0
- package/packs/pbgc/source.md +95 -0
- package/packs/philfed/endpoints.json +85 -0
- package/packs/philfed/policy.json +94 -0
- package/packs/philfed/source.md +125 -0
- package/packs/port.json +287 -0
- package/packs/regulations/endpoints.json +288 -0
- package/packs/regulations/policy.json +86 -0
- package/packs/regulations/source.md +84 -0
- package/packs/sec/endpoints.json +237 -0
- package/packs/sec/policy.json +86 -0
- package/packs/sec/source.md +101 -0
- package/packs/senate-lobbying/endpoints.json +554 -0
- package/packs/senate-lobbying/policy.json +99 -0
- package/packs/senate-lobbying/source.md +100 -0
- package/packs/snapqc/endpoints.json +1426 -0
- package/packs/snapqc/policy.json +92 -0
- package/packs/snapqc/source.md +96 -0
- package/packs/treasury/catalog.json +2267 -0
- package/packs/treasury/docs/api_guide.md +245 -0
- package/packs/treasury/docs/datasets.md +56 -0
- package/packs/treasury/docs/report_patterns.md +126 -0
- package/packs/treasury/policy.json +159 -0
- package/packs/treasury/source.md +170 -0
- package/packs/treasury-yields/endpoints.json +226 -0
- package/packs/treasury-yields/policy.json +86 -0
- package/packs/treasury-yields/source.md +80 -0
- package/packs/usaspending/endpoints.json +1316 -0
- package/packs/usaspending/policy.json +109 -0
- package/packs/usaspending/source.md +103 -0
- package/packs/usda-fna/endpoints.json +427 -0
- package/packs/usda-fna/policy.json +133 -0
- package/packs/usda-fna/source.md +217 -0
- package/packs/usda-fooddata/endpoints.json +181 -0
- package/packs/usda-fooddata/policy.json +94 -0
- package/packs/usda-fooddata/source.md +105 -0
- package/packs/usda-nass/endpoints.json +324 -0
- package/packs/usda-nass/policy.json +95 -0
- package/packs/usda-nass/source.md +85 -0
- package/packs/usda-outlook/endpoints.json +86 -0
- package/packs/usda-outlook/policy.json +109 -0
- package/packs/usda-outlook/source.md +144 -0
- package/packs/usgs/endpoints.json +313 -0
- package/packs/usgs/policy.json +95 -0
- package/packs/usgs/source.md +96 -0
- package/packs/usitc/endpoints.json +74 -0
- package/packs/usitc/policy.json +111 -0
- package/packs/usitc/source.md +90 -0
- package/packs/uspto/endpoints.json +141 -0
- package/packs/uspto/policy.json +95 -0
- package/packs/uspto/source.md +101 -0
- package/packs/va/endpoints.json +414 -0
- package/packs/va/policy.json +101 -0
- package/packs/va/source.md +129 -0
- package/packs/world-bank/endpoints.json +122 -0
- package/packs/world-bank/policy.json +101 -0
- package/packs/world-bank/source.md +93 -0
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Release gate for a report or paper (a port of report/audit_report.py). Run before handing anything to the user.
|
|
3
|
+
* One gate for every source pack: the shared checks, plus each used source's policy (report.json "sources",
|
|
4
|
+
* else the data/<id>/ folders). FAIL-level checks:
|
|
5
|
+
* facts every fact traced to a CSV cell matches that cell exactly; derived facts state a derivation;
|
|
6
|
+
* a fact's source pack ("pack") is one of the sources used
|
|
7
|
+
* numbers no number is typed into the prose by hand: each must be a {{fact}}, a year, or listed in
|
|
8
|
+
* report.json "audit_allow" with a reason
|
|
9
|
+
* exhibits every exhibit CSV exists and has the columns its chart uses; every exhibit has a source line
|
|
10
|
+
* that names one of the sources used
|
|
11
|
+
* links every relative link resolves and none points at data a source's terms keep local; with online
|
|
12
|
+
* every external link answers HTTP < 400
|
|
13
|
+
* html report.html exists, is newer than its inputs, loads nothing external, starts with the AI
|
|
14
|
+
* disclaimer, and has no unresolved {{placeholders}} or raw [@cite] / [^n] markup
|
|
15
|
+
* vintage provenance per source; the Data Vintage block; the methods state the vintage; preliminary,
|
|
16
|
+
* projected and past-vintage facts say so where they are cited
|
|
17
|
+
* policy every notice of every used source is on the page; each source's audit hooks pass; a withheld
|
|
18
|
+
* key has a report.json "clearance" entry with its basis
|
|
19
|
+
* secrets no API key or key-shaped value in any workspace file, including the members of the ZIP
|
|
20
|
+
* style prose meets the style guide target (>= 90%)
|
|
21
|
+
* structure report mode: the exhibit-chartbook parts are present
|
|
22
|
+
* questions ... benchmark the method record (method_audit.ts)
|
|
23
|
+
* replication replication_package.zip holds REPLICATION.md, facts.json, the exhibit data and their recipes
|
|
24
|
+
* (exhibits/lineage.json), per source its allowed data with provenance or (definition_only) its
|
|
25
|
+
* reproduce/<id>/ bundle, and nothing a source's terms forbid; with rerun, every exhibit recipe
|
|
26
|
+
* and table fact is replayed and must come out the same
|
|
27
|
+
*/
|
|
28
|
+
import fs from "node:fs";
|
|
29
|
+
import path from "node:path";
|
|
30
|
+
import { unzipSync } from "fflate";
|
|
31
|
+
import { checkPublicHost } from "../analysis/cite.js";
|
|
32
|
+
import { lineagePacks } from "../analysis/compute.js";
|
|
33
|
+
import { mode as serverMode } from "../core/env.js";
|
|
34
|
+
import * as pol from "../core/policy.js";
|
|
35
|
+
import * as MA from "./method_audit.js";
|
|
36
|
+
import * as PS from "./policyset.js";
|
|
37
|
+
import { echoSources, knownKeys, relHits, scanTree } from "./scan_secrets.js";
|
|
38
|
+
import * as SC from "./style_check.js";
|
|
39
|
+
import { csvGrid, fixed, fullmatch, readDict, readText, repr, rx, sorted, str, sub, toFloat, unescapeHtml } from "./py.js";
|
|
40
|
+
const FACT_RE = /\{\{[^}]*\}\}/g;
|
|
41
|
+
const NUM_RE = /(?<![\w.])[-−]?\$?\d[\d,]*(?:\.\d+)?%?/g;
|
|
42
|
+
const PROSE_KEYS = ["subtitle", "summary", "sections", "methods", "footnotes", "about", "highlights", "exhibits",
|
|
43
|
+
"at_a_glance", "notes_page", "introduction", "appendixes", "cover", "assumptions"];
|
|
44
|
+
const MONTHS = String.raw `(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t(?:ember)?)?|` +
|
|
45
|
+
String.raw `Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)`;
|
|
46
|
+
const UA = "data-analyst-audit/1.0";
|
|
47
|
+
const BROWSER_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) data-analyst-audit";
|
|
48
|
+
export const CHECKS = ["facts", "numbers", "exhibits", "links", "html", "vintage", "policy", "secrets", "style", "structure",
|
|
49
|
+
"questions", "literature", "disclosures", "references", "assumptions", "sensitivity", "data_needs", "benchmark", "replication"];
|
|
50
|
+
/** [where, text] for every human-readable string in the report (not data paths or charts). */
|
|
51
|
+
export function proseStrings(R) {
|
|
52
|
+
const out = [];
|
|
53
|
+
const walk = (where, x) => {
|
|
54
|
+
if (typeof x === "string")
|
|
55
|
+
out.push([where, x]);
|
|
56
|
+
else if (Array.isArray(x))
|
|
57
|
+
x.forEach((v, i) => walk(`${where}[${i}]`, v));
|
|
58
|
+
else if (x && typeof x === "object") {
|
|
59
|
+
for (const [k, v] of Object.entries(x)) {
|
|
60
|
+
if (["data", "chart", "path", "exhibits"].includes(k) && where.startsWith("sections"))
|
|
61
|
+
continue;
|
|
62
|
+
if (k === "exhibit" && where.startsWith("cover"))
|
|
63
|
+
continue;
|
|
64
|
+
if (["data", "chart", "path", "source", "rows"].includes(k))
|
|
65
|
+
continue;
|
|
66
|
+
walk(`${where}.${k}`, v);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
for (const k of PROSE_KEYS)
|
|
71
|
+
if (k in R)
|
|
72
|
+
walk(k, R[k]);
|
|
73
|
+
if ("title" in R)
|
|
74
|
+
out.push(["title", R.title]);
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
/** URLs in text; balanced parentheses stay in ("...RA%20(GW).aspx"), a closing one after the URL does not. */
|
|
78
|
+
export function findUrls(s) {
|
|
79
|
+
return s.match(/https?:\/\/(?:[^\s"'<>()[\]\\]|\([^\s"'<>()]*\))+/g) || [];
|
|
80
|
+
}
|
|
81
|
+
// ---------------------------------------------------------------------- what is not a statistic
|
|
82
|
+
const ref = String.raw `\d+(?:\.\d+)*[A-Z]?`;
|
|
83
|
+
const R_ = (src, repl = " ") => [rx(src), repl];
|
|
84
|
+
const EXEMPT = [
|
|
85
|
+
R_(String.raw `\[\^\d+\]`), // footnote markers
|
|
86
|
+
R_(String.raw `\]\([^)]*\)|https?://\S+`), // link targets
|
|
87
|
+
// "Tables 1.1.1, 1.1.2 and 2.6" / "Exhibits 2, 3, and 4" are lists; "Exhibit 2, 45 percent" is a reference
|
|
88
|
+
R_(String.raw `\b(?:Exhibits|Figures|Tables|Appendixes|Boxes|Chapters|Lines|Sections)\s+${ref}` +
|
|
89
|
+
String.raw `(?:\s*(?:,?\s*(?:and|to)|[–,/-])\s*${ref})*\b`),
|
|
90
|
+
R_(String.raw `\bTables?\s+\d+(?:\.\d+)+[A-Z]?\b`), // NIPA tables such as Table 1.1.6
|
|
91
|
+
R_(String.raw `(?i)\b\d{1,2}\s?(?:Yr|Mo|Wk)s?\b`), // maturity labels: 10 Yr, 3 Mo
|
|
92
|
+
R_(String.raw `(?i)\b(?:Exhibit|Figure|Table|Appendix|Box|Chapter|Part|Title|Volume|Vol\.|Note|FAQ)\s+\d+[a-z]?` +
|
|
93
|
+
String.raw `(?:\s*(?:[–-]|to)\s*\d+[a-z]?)?\b`),
|
|
94
|
+
R_(String.raw `\b(?:Executive [Oo]rders?|EOs?|E\.\s?O\.|Proclamations?|Public Land Orders?)\s+(?:No\.\s*)?` +
|
|
95
|
+
String.raw `\d{3,6}(?:\s*(?:[–-]|to|through|,?\s*and|,?\s*or|,)\s*\d{3,6})*\b`), // EO 14296
|
|
96
|
+
// survey variable codes: RELATE 1, OWNERSHP in (1, 2), GQ = 2 (two-letter names need the operator); REPWT1-80
|
|
97
|
+
R_(String.raw `\b[A-Z]{2,}\d+\s*[-–]\s*\d+\b`),
|
|
98
|
+
R_(String.raw `\b(?:(?!(?:USA|GDP|GNP|CPI|PCE|PPI|ECI|EITC|ACS|CPS|BLS|BEA|OPM|FRED)\b)[A-Z][A-Z0-9_]{2,15}` +
|
|
99
|
+
String.raw `(?:\s*==?\s*|\s+(?:in|is)\s+|\s+)|[A-Z]{2}(?:\s*==?\s*|\s+in\s+))\(?\d{1,3}(?:\s*(?:,|,?\s+(?:or|and))\s+\d{1,3})*\)?` +
|
|
100
|
+
String.raw `(?![\d%/]|\.\d|[,–-]\d|\s*(?:%|percent|points?|million|billion|thousand))`),
|
|
101
|
+
R_(String.raw `(?i)\b(?:versions?|vintages?|editions?|waves?|releases?)\s+\d+(?:\s*(?:,|,?\s*(?:and|or))\s*\d+)*\b` +
|
|
102
|
+
String.raw `(?!\s*(?:%|percent))`), // version 1; file versions 4, 4 and 3
|
|
103
|
+
R_(String.raw `(?i)\bcongress(?:es)?\s*(?:=\s*)?\d{2,3}\b(?!\s*(?:%|percent))`), // congress 118
|
|
104
|
+
R_(String.raw `(?i)\b(?:foot)?notes?\s+\d+[a-z]?(?:\s*(?:,|and|to|–|-)\s*\d+[a-z]?)*\b`), // footnote 5
|
|
105
|
+
R_(String.raw `(?i)(?:=|equals?)\s*100\b(?!\s*(?:%|percent))`), // an index base: (U.S. = 100), 2017=100
|
|
106
|
+
// a confidence level is a convention, not a statistic: "90 percent margin of error", "significant at 90%"
|
|
107
|
+
R_(String.raw `(?i)\b(?:90|95|99)\s*(?:%|percent)(?=\s+(?:confidence|margins?|level|MOE|CI)\b)|` +
|
|
108
|
+
String.raw `\b(?:significant|confidence)\s+(?:at|level\s+of)\s+(?:the\s+)?(?:90|95|99)\s*(?:%|percent)`),
|
|
109
|
+
R_(String.raw `(?i)\bin\s+sample\s+\d+(?:\s*(?:,|and|or)\s*\d+)*`), // CPS months in sample 4 and 8
|
|
110
|
+
R_(String.raw `(?i)\b(?:IPUMS\s+\w+\s+)?extract\s+(?:no\.\s*|number\s+|#)?\d+\b`), // IPUMS extract 30
|
|
111
|
+
// ages define a universe: "aged 16", "ages 25 to 64", "65 and older", "children under 15 who"
|
|
112
|
+
R_(String.raw `(?i)\b(?:aged?|ages)\s+\d{1,3}(?:\s*(?:to|through|[–-]|and)\s*\d{1,3})?\b(?!\s*(?:%|percent|\.\d))`),
|
|
113
|
+
R_(String.raw `(?i)\b\d{1,3}\s+(?:years?\s+)?(?:(?:and|or)\s+(?:over|older|up|above)|or\s+more\b(?=\s*(?:years|[,.;)]|$)))`),
|
|
114
|
+
R_(String.raw `(?i)\b(?:age[sd]?\s+|adults\s+|people\s+|workers\s+)\d{1,3}\+`), // "adults 25+"
|
|
115
|
+
R_(String.raw `(?i)\b(?:ch|chap|sec|art|para|pt|vol|no|pp?)\.\s*\d+(?:\.\d+)*(?:\s*[–-]\s*\d+)?\b`),
|
|
116
|
+
R_(String.raw `(?i)\bpages?\s+\d+(?:\s*(?:[–-]|to|and)\s*\d+)?(?!\s*(?:%|percent))\b`), // page 9
|
|
117
|
+
R_(String.raw `\b[A-Z]{2,6}-\d{2}-[0-9A-Z]{1,8}\b`), // GAO-26-900644, USDL-26-0229
|
|
118
|
+
R_(String.raw `(?<![\d.])(?:1\.645|1\.96|2\.576)(?![\d])`), // z critical values
|
|
119
|
+
R_(String.raw `(?i)\b(?:under|younger than|older than)\s+(?:age\s+)?\d{1,2}(?=\s+(?:years?\b|year-olds?\b|who\b|in\b|and\b|or\b)|\s*[(),;:]` +
|
|
120
|
+
String.raw `|\s*\.(?!\d)|\s*$)`),
|
|
121
|
+
R_(String.raw `(?i)\b(?:at|those|workers|people|persons|adults|men|women|group)\s+\d{1,2}\s*(?:to|through|[–-])\s*\d{2}\b` +
|
|
122
|
+
String.raw `(?!\s*(?:%|percent|\.\d))|\b\d{2}-to-\d{2}\b`), // "5.7 percent at 25 to 64"
|
|
123
|
+
// "youngest child is 6 to 17", "a child under 18", "children aged 6-17": the group's ages
|
|
124
|
+
R_(String.raw `(?i)\b(?:child|children|kids?|son|daughter)\s+(?:is\s+|are\s+|was\s+|aged?\s+)?` +
|
|
125
|
+
String.raw `(?:(?:under|over|younger than|older than)\s+)?\d{1,2}(?:\s*(?:to|through|[–-])\s*\d{1,2})?\b` +
|
|
126
|
+
String.raw `(?!\s*(?:%|percent|\.\d))`),
|
|
127
|
+
R_(String.raw `(?i)\b(?:employees|workers|people|persons|adults|children|staff|residents|individuals|those)\s+` +
|
|
128
|
+
String.raw `(?:under|over|younger than|older than)\s+(?:age\s+)?\d{1,2}\b(?!\s*(?:%|percent|\.\d))`),
|
|
129
|
+
R_(String.raw `(?i)\b(?:Parts|Titles|Volumes|Vols\.)\s+\d+(?:\s*(?:[–-]|to|through|,?\s*and|,?\s*or|,)\s*\d+)*\b`),
|
|
130
|
+
// statute and regulation citations: 2 U.S.C. 653, 42 USC § 1983, 40 CFR 60.5, 138 Stat. 2687, 89 FR 12345
|
|
131
|
+
R_(String.raw `\b\d+\s+(?:U\.?\s?S\.?\s?C\.?(?:A\.?)?|C\.?\s?F\.?\s?R\.?|Stat\.|F\.?\s?R\.?|Fed\.\s?Reg\.)\s*` +
|
|
132
|
+
String.raw `(?:§+\s*|part\s+|pt\.\s*)?\d[\w.\-()]*(?:\s*(?:,|,?\s*(?:and|or|through|to))\s*\d[\w.\-()]*(?!\w)` +
|
|
133
|
+
String.raw `(?!\s*(?:U\.?\s?S\.?\s?C|C\.?\s?F\.?\s?R|Stat\.|F\.?\s?R\b|Fed\.|%|percent|points?|million|billion|` +
|
|
134
|
+
String.raw `thousand|(?!(?:and|or|through|to)\b)[a-z]{3,})))*`),
|
|
135
|
+
R_(String.raw `\b\d{1,4}(?:\([a-zA-Z0-9]{1,4}\))+`), // provisions: INA 236(c), 241(a)(2)
|
|
136
|
+
R_(String.raw `(?i)\b(?:status\s+|error\s+)?codes?\s+\d[\d\-.]*(?:\s*\([^)\n]{0,60}\))?` +
|
|
137
|
+
String.raw `(?:\s*(?:,|and|or)\s*\d[\d\-.]*(?:\s*\([^)\n]{0,60}\))?)*`), // code 2 (...), 4 (...) or 5
|
|
138
|
+
R_(String.raw `(?i)\b(?:issues?|volume)\s+(?:no\.\s*)?\d+(?:\s*(?:[–-]|to|through|and)\s*\d+)?\b` +
|
|
139
|
+
String.raw `(?!\s*(?:%|percent))`), // volume 171, issues 204 to 206
|
|
140
|
+
R_(String.raw `(?i)\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\.?\s+\d{1,2}\s*(?:[–-]|to|through|` +
|
|
141
|
+
String.raw `and)\s*\d{1,2}(?=,?\s+\d{4}\b)`), // February 12 to 13, 2024
|
|
142
|
+
R_(String.raw `(?i)\b(?:returns?|returned|gives?|gave|got|answers?|answered)\s+(?:an?\s+)?(?:http\s+)?(?:status\s+)?` +
|
|
143
|
+
String.raw `(?:200|301|302|400|401|403|404|406|410|429|500|502|503|504)\b(?!\s*(?:%|percent|rows?|records?))`),
|
|
144
|
+
R_(String.raw `(?i)\b(?:roll(?:\s+calls?)?(?:\s+votes?)?|votes?)\s+(?:nos?\.?\s*)?\d+(?:\s*(?:,|and|or|&)\s*\d+)+\b`),
|
|
145
|
+
R_(String.raw `(?i)\b(?:line|section|sec\.|§|session|roll(?: call)?(?: vote)?|vote|no\.|http(?: error)?|error code|` +
|
|
146
|
+
String.raw `status code|function)\s*\d[\d.\-/]*`), // line 32, roll 404, HTTP 403, session 2
|
|
147
|
+
R_(String.raw `(?i)\b(?:roll(?:\s+calls?)?(?:\s+votes?)?|votes?|lines|sections)\s+(?:nos?\.?\s*)?\d+\s*(?:to|through|[–-])\s*` +
|
|
148
|
+
String.raw `\d+\b(?!\s*(?:%|percent))`), // "votes 1 to 659"
|
|
149
|
+
// bill and law numbers, ranges too (H.R. 1-10,564); a lone "S" needs its period and no letter or dot before it
|
|
150
|
+
R_(String.raw `(?<![\w.'’])(?:H\.\s?R\.?|HR|S\.|H\.\s?J\.\s?Res\.?|S\.\s?J\.\s?Res\.?|H\.\s?Con\.\s?Res\.?|` +
|
|
151
|
+
String.raw `S\.\s?Con\.\s?Res\.?|H\.\s?Res\.?|S\.\s?Res\.?|P\.\s?L\.?|PL|Pub\.\s?L\.?|Public Law|Private Law|S\.\s?Amdt\.?|H\.\s?Amdt\.?|S\.\s?Up\.\s?Amdt\.?|SA|` +
|
|
152
|
+
String.raw `H\.\s?Rept\.?|S\.\s?Rept\.?)\s*\d[\d,]*(?:\s*[–-]\s*\d[\d,]*)?` +
|
|
153
|
+
String.raw `(?:(?:,\s*|,?\s+(?:and|or)\s+|(?<=,)\s+)\d[\d,]*(?:[–-]\d+)?(?![\d.])` +
|
|
154
|
+
String.raw `(?!\s*(?:%|percent|other|more|bills?|laws?|votes?|members?|senators?|times)\b))*`),
|
|
155
|
+
R_(String.raw `(?i)\bFIPS\s*\d+|\(\d{5}\)`), // geography codes: FIPS 24031, (24510)
|
|
156
|
+
R_(String.raw `\b[A-Z]{1,2}\s?\d+\.[A-Z][A-Za-z]{0,4}\s?\d+(?:/\d+)?(?::[\w./-]*)?`), // SuDoc: Y 4.J 89/2:
|
|
157
|
+
R_(String.raw `(?i)\b9/11\b|\bpost-9/11\b`),
|
|
158
|
+
R_(String.raw `\b\d{4}(?:[-–]\d{2,4})?\s*=\s*100\b`), // index bases: 1982-84=100, 2017=100
|
|
159
|
+
R_(String.raw `\b\d{4}-\d{2}(?:-\d{2})?\b|\b\d{1,2}/\d{1,2}/\d{2,4}\b`), // ISO and m/d/y dates
|
|
160
|
+
R_(String.raw `(?i)(?<!from )(?<!rose )(?<!fell )\b(?:about|roughly|approximately|between|some|around)?\s*` +
|
|
161
|
+
String.raw `\d+(?:\.\d+)?\s+to\s+\d+(?:\.\d+)?(?=\s*(?:%|percent)\s+(?:range|of\s+(?:the|all|total)|target|` +
|
|
162
|
+
String.raw `guidance|recommended|band))`), // a guideline range: 15 to 20 percent range
|
|
163
|
+
R_(String.raw `(?i)\b(?:about|roughly|approximately|between)\s+\d+(?:\.\d+)?\s+(?:to|and)\s+\d+(?:\.\d+)?` +
|
|
164
|
+
String.raw `(?=\s*(?:%|percent)?)`), // an approximate range: about 45 to 48
|
|
165
|
+
R_(String.raw `\b(?:17|18|19|20)\d\d\s*–\s*\d{2,4}\b`), // year ranges with a dash: 1982–84
|
|
166
|
+
R_(String.raw `(?i)(\d\.\d+)-(day|week|month|quarter|year)s?\b`, (m) => `${m[1]} ${m[2]}`), // a 1.6-year rise
|
|
167
|
+
R_(String.raw `(?i)(?<![\d.])\b(?:1|2|3|4|5|6|7|8|9|10|12|13|14|15|17|18|20|21|24|25|26|28|30|31|36|40|45|` +
|
|
168
|
+
String.raw `50|52|60|75|90|100|120|180|270|360|365)-(?:day|week|month|quarter|year)s?\b`),
|
|
169
|
+
// standard terms and windows (4-week bill, 10-year note, 30-day average); "43-day shutdown" is a statistic
|
|
170
|
+
R_(String.raw `(?i)\b(?:1|3|6|12|24|36)[ -]months?\b(?!\s+(?:earlier|later|before|after|ahead|ago|lag|` +
|
|
171
|
+
String.raw `lead|behind)\b)`),
|
|
172
|
+
R_(String.raw `\bU-[1-6]\b|\b\d{4}(?:-\d{2,4})?\s*=\s*100\b|\b[MQS]\d{2}\b|\bQ[1-4]\b`),
|
|
173
|
+
R_(String.raw `\b(?:19|20)\d\d\s?[QM]\d{1,2}\b`), // periods such as 2026Q2 or 2026M09
|
|
174
|
+
R_(String.raw `\b[A-Za-z]+-\d+\b`), // names with a number: COVID-19, H-1
|
|
175
|
+
R_(String.raw `\b\d{1,2}\s+` + MONTHS + String.raw `\b`), // "30 September 2026"
|
|
176
|
+
// "March 31, 2026", "October 1-3", "January 17 and 21, 2025"; a comma list of days is dates only when it closes
|
|
177
|
+
// with "and 20" or a year ("On March 3, 12 states" is not)
|
|
178
|
+
R_(MONTHS + String.raw `\.?\s+\d{1,2}(?:\s*,\s*\d{1,2}\b)+(?:\s*,?\s*(?:and|or|&)\s*\d{1,2}\b(?:,?\s+\d{4}\b)?|` +
|
|
179
|
+
String.raw `,?\s+\d{4}\b)`),
|
|
180
|
+
R_(MONTHS + String.raw `\.?\s+\d{1,2}(?:\s*(?:[–-]|and|&|or)\s*\d{1,2}\b(?!\.\d))*\b,?`),
|
|
181
|
+
// FY2024-25, FY2020 to FY2026, fiscal years 2024 and 2025; "FY2024 and 146,482" keeps its number
|
|
182
|
+
R_(String.raw `(?i)\b(?:fiscal years?|FY)\s*\d{2,4}(?:\s*[–-]\s*(?:FY\s?)?(?:(?:19|20)\d\d|\d\d)\b(?![,.]\d)` +
|
|
183
|
+
String.raw `|\s*(?:to|and|through)\s*(?:FY\s?)?(?:19|20)\d\d\b(?![,.]\d))?`),
|
|
184
|
+
R_(String.raw `\b(?:FY|Q)\s?\d{1,4}\b`), // FY2025, FY 2025, Q4
|
|
185
|
+
R_(String.raw `(?m)^\s*\d{1,2}[.)]\s`), // list markers "1. " "2) "
|
|
186
|
+
R_(String.raw `(?im)^(\s*\|\s*(?:\*\*)?(?:total|all)\b.*)$`, // a share table's total row: 100 percent
|
|
187
|
+
(m) => sub(/\b100(?:\.0+)?\s*(?:%|percent)/, " ", m[1])),
|
|
188
|
+
// a table's first column is its labels ("35 to 44", "Under 35", "2019 Q1"), when the row has more cells
|
|
189
|
+
R_(String.raw `(?m)^(\s*\|)([^|\n]*)(?=\|[^\n]*\|)`, (m) => m[1] + m[2].replace(/\d/g, " ")),
|
|
190
|
+
R_(String.raw `(?m)^\s*\|\s*\d+\s*(?:\(tie\)|=)?\s*\|`, "| |"), // a rank or code in the first column
|
|
191
|
+
R_(String.raw `(?<![\d.,])0\d+\b(?![.,]\d)`), // zero-padded codes: 0301, 06037
|
|
192
|
+
R_(String.raw `(?i)\b(?:series|codes?|occupation|naics|soc|cip|sic|psc|nigp)\s+\(?\d{3,}[\d\-.]*\)?(?!\s*(?:%|percent))` +
|
|
193
|
+
String.raw `|\b(?:series|codes?|occupation|naics|soc|cip|sic|psc|nigp)\s+\d[\d\-.]*` +
|
|
194
|
+
String.raw `(?:\s*\([^)\n]{0,60}\))?(?:\s*(?:,|and|or)\s*\d[\d\-.]*(?:\s*\([^)\n]{0,60}\))?)*`),
|
|
195
|
+
R_(String.raw `(?i)\b(?:90|95|99)\s*(?:%|percent)(?=[\s-]*(?:confidence|margin|moe|ci\b|interval|level|signific))`),
|
|
196
|
+
R_(String.raw `\b\d+(?:st|nd|rd|th)\b`), // ordinals: 118th Congress
|
|
197
|
+
];
|
|
198
|
+
const CODE_STAT = rx(String.raw `\s*[-−]?\$?[\d,.]+\s*(?:%|percent|percentage points?|pp|million|billion|trillion)?\s*`);
|
|
199
|
+
/** The text with what is not a statistic blanked out: {{facts}}, code, links, footnote marks, table and exhibit
|
|
200
|
+
* references, bill and law numbers, roll calls and line numbers, dates in any common form, periods and terms such
|
|
201
|
+
* as 10-year note or U-6. Shared by the report audit and the quick-answer audit. */
|
|
202
|
+
export function exempt(text) {
|
|
203
|
+
let t = text.replace(FACT_RE, " ");
|
|
204
|
+
// a bare integer in backticks is a code (`0301`, `25`); a number with a unit, decimals or commas is checked
|
|
205
|
+
t = sub(/`([^`]*)`/, (m) => (fullmatch(CODE_STAT, m[1]) && !/^\s*\d+\s*$/.test(m[1]) ? m[0].replace(/^`+|`+$/g, "") : " "), t);
|
|
206
|
+
for (const [re, repl] of EXEMPT)
|
|
207
|
+
t = sub(re, repl, t);
|
|
208
|
+
return t;
|
|
209
|
+
}
|
|
210
|
+
/** Numbers typed by hand (exempted: years, references, dates, periods). */
|
|
211
|
+
export function hardNumbers(text, allow) {
|
|
212
|
+
const t = exempt(text);
|
|
213
|
+
const bad = [];
|
|
214
|
+
for (const m of t.matchAll(NUM_RE)) {
|
|
215
|
+
const tok = m[0];
|
|
216
|
+
const core = tok.replace(/\$/g, "").replace(/%/g, "").replace(/,/g, "").replace(/−/g, "-").replace(/^-+/, "");
|
|
217
|
+
const v = toFloat(core);
|
|
218
|
+
if (v === null)
|
|
219
|
+
continue;
|
|
220
|
+
if (tok.replace(/,+$/, "") === core && /^\d+$/.test(core) && core.length === 4 && v >= 1900 && v <= 2100)
|
|
221
|
+
continue;
|
|
222
|
+
if (allow.has(tok) || allow.has(core))
|
|
223
|
+
continue;
|
|
224
|
+
bad.push(tok);
|
|
225
|
+
}
|
|
226
|
+
return bad;
|
|
227
|
+
}
|
|
228
|
+
export const notes = MA.NOTES;
|
|
229
|
+
/** Missing or malformed parts of the exhibit-chartbook layout (report mode). */
|
|
230
|
+
export function structureProblems(R) {
|
|
231
|
+
const out = [];
|
|
232
|
+
const g = R.at_a_glance || {};
|
|
233
|
+
const findings = (g.findings && g.findings.length ? g.findings : R.summary) || [];
|
|
234
|
+
if (!g.text)
|
|
235
|
+
out.push("at_a_glance.text: add the framing paragraph (what was examined, population or measures, period)");
|
|
236
|
+
if (!(findings.length >= 3 && findings.length <= 5))
|
|
237
|
+
out.push(`At a Glance has ${findings.length} findings; a chartbook uses 3 to 5`);
|
|
238
|
+
if (findings.some((f) => !(f && typeof f === "object" && f.lead))) {
|
|
239
|
+
out.push("each At a Glance finding needs a bold 'lead' naming its section, e.g. 'Unemployment.'");
|
|
240
|
+
}
|
|
241
|
+
if (!R.notes_page || (Array.isArray(R.notes_page) && !R.notes_page.length)) {
|
|
242
|
+
out.push("notes_page missing: calendar or fiscal years, rounding, seasonal adjustment, dollar year and deflator, data " +
|
|
243
|
+
"sources, retrieval dates and vintages, definitions");
|
|
244
|
+
}
|
|
245
|
+
const intro = R.introduction || {};
|
|
246
|
+
if (!intro.text)
|
|
247
|
+
out.push("introduction.text missing: a lead paragraph with the headline numbers");
|
|
248
|
+
if (!intro.subsections || !intro.subsections.length) {
|
|
249
|
+
out.push("introduction.subsections missing: one question-style heading per section, plus the data used");
|
|
250
|
+
}
|
|
251
|
+
const secs = R.sections || [];
|
|
252
|
+
if (secs.length < 2)
|
|
253
|
+
out.push(`${secs.length} section(s); a chartbook has 2 to 5 thematic sections`);
|
|
254
|
+
secs.forEach((s, k) => {
|
|
255
|
+
if (!s.exhibits || !s.exhibits.length)
|
|
256
|
+
out.push(`section ${k + 1} (${repr(s.heading ?? null)}) shows no exhibit`);
|
|
257
|
+
});
|
|
258
|
+
(R.exhibits || []).forEach((e, i) => {
|
|
259
|
+
if (!String(e.text ?? "").trim())
|
|
260
|
+
out.push(`exhibit ${i + 1}: add 'text', the 2 to 4 paragraphs shown beside the chart`);
|
|
261
|
+
if (!/(?:19|20)\d\d(?:\s*Q[1-4])?\s*$/.test(String(e.title ?? ""))) {
|
|
262
|
+
MA.note(`exhibit ${i + 1} title should end with its period, e.g. ', 2013 to 2023' or ', 2019 Q1 to 2026 Q2'`);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
if (!R.about)
|
|
266
|
+
out.push("about missing: About This Document (who asked, who prepared it, with what data and tools, date)");
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
export function* allStrings(x) {
|
|
270
|
+
if (typeof x === "string")
|
|
271
|
+
yield x;
|
|
272
|
+
else if (Array.isArray(x))
|
|
273
|
+
for (const v of x)
|
|
274
|
+
yield* allStrings(v);
|
|
275
|
+
else if (x && typeof x === "object")
|
|
276
|
+
for (const v of Object.values(x))
|
|
277
|
+
yield* allStrings(v);
|
|
278
|
+
}
|
|
279
|
+
/** [ok, message] for one external link (HTTP < 400; 403 and time-outs to scripts are accepted with a note). */
|
|
280
|
+
export async function checkUrl(u) {
|
|
281
|
+
if (serverMode() === "remote") {
|
|
282
|
+
try {
|
|
283
|
+
await checkPublicHost(u);
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
return [false, `${u}: ${e.message}`];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
let status = null, err = null;
|
|
290
|
+
const codes = [];
|
|
291
|
+
for (const ua of [UA, BROWSER_UA]) { // some hosts refuse a browser-like agent, others anything else
|
|
292
|
+
status = null;
|
|
293
|
+
try {
|
|
294
|
+
const r = await fetch(u, { method: "GET", headers: { "User-Agent": ua }, signal: AbortSignal.timeout(20000), redirect: "follow" });
|
|
295
|
+
status = r.status;
|
|
296
|
+
try {
|
|
297
|
+
await r.body?.cancel();
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
// ignore
|
|
301
|
+
}
|
|
302
|
+
if (status < 400)
|
|
303
|
+
return [true, `${u}: HTTP ${status}`];
|
|
304
|
+
}
|
|
305
|
+
catch (e) {
|
|
306
|
+
err = e;
|
|
307
|
+
}
|
|
308
|
+
if (status !== null)
|
|
309
|
+
codes.push(status);
|
|
310
|
+
}
|
|
311
|
+
const real = codes.find((c) => ![401, 403, 429].includes(c) && c >= 400); // a real answer beats a timeout
|
|
312
|
+
if (real !== undefined)
|
|
313
|
+
return [false, `${u}: HTTP ${real}`];
|
|
314
|
+
const text = err ? `${err.name || ""} ${err.message || ""} ${err.cause?.code || ""} ${err.cause?.message || ""}` : "";
|
|
315
|
+
const timedOut = status === null && /timed? ?out|timeout|aborted/i.test(text);
|
|
316
|
+
const dropped = status === null && /reset|10054|remote end closed|remotedisconnected|eof occurred|socket hang up|other side closed/i.test(text);
|
|
317
|
+
const n = status === 403 ? "HTTP 403 to scripts" : timedOut ? "timed out for scripts"
|
|
318
|
+
: dropped ? "connection dropped for scripts (throttling)" : null;
|
|
319
|
+
return [!!n, `${u}: ${n ? n + "; open it in a browser to confirm" : err ? (err.cause?.message || err.message || String(err)) : status}`];
|
|
320
|
+
}
|
|
321
|
+
export function namesSource(text, policies) {
|
|
322
|
+
const t = text.toLowerCase();
|
|
323
|
+
for (const [sid, P] of Object.entries(policies)) {
|
|
324
|
+
const cands = [P.agency || "", P.title || "", ...(P.aliases || [])];
|
|
325
|
+
if (cands.some((c) => c && t.includes(c.toLowerCase())))
|
|
326
|
+
return true;
|
|
327
|
+
if (new RegExp(`(?<![a-z0-9])${sid.toLowerCase().replace(/[.*+?^${}()|[\]\\-]/g, "\\$&")}(?![a-z0-9])`).test(t))
|
|
328
|
+
return true;
|
|
329
|
+
const short = (P.title || "").replace(/\s*\(.*?\)/g, "").trim().toLowerCase();
|
|
330
|
+
if (short && t.includes(short))
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
/** Python's text-mode read: universal newlines. */
|
|
336
|
+
export function readTextFile(p) {
|
|
337
|
+
return readText(p).replace(/\r\n?/g, "\n");
|
|
338
|
+
}
|
|
339
|
+
function readJson(p) {
|
|
340
|
+
return JSON.parse(readText(p));
|
|
341
|
+
}
|
|
342
|
+
const mtime = (p) => fs.statSync(p).mtimeMs;
|
|
343
|
+
export async function audit(reportPath, htmlPath, online = false, rerunIt = false) {
|
|
344
|
+
const base = path.dirname(path.resolve(reportPath));
|
|
345
|
+
const R = MA.merged(base, readJson(reportPath));
|
|
346
|
+
const mode = R.mode || "report";
|
|
347
|
+
htmlPath = htmlPath || path.join(base, "report.html");
|
|
348
|
+
const results = [];
|
|
349
|
+
const res = (check, ok, msg) => void results.push([check, !!ok, msg]);
|
|
350
|
+
// ---- sources and their policies
|
|
351
|
+
const ids = PS.usedSources(base, R);
|
|
352
|
+
let policies = {};
|
|
353
|
+
try {
|
|
354
|
+
policies = PS.loadPolicies(ids);
|
|
355
|
+
}
|
|
356
|
+
catch (e) {
|
|
357
|
+
if (!(e instanceof PS.SourceError))
|
|
358
|
+
throw e;
|
|
359
|
+
res("policy", false, e.message);
|
|
360
|
+
}
|
|
361
|
+
if (!ids.length)
|
|
362
|
+
res("policy", false, 'no source used: list report.json "sources" or fetch into data/<id>/');
|
|
363
|
+
const page = fs.existsSync(htmlPath) ? readTextFile(htmlPath) : "";
|
|
364
|
+
const pageText = unescapeHtml(page.replace(/<[^>]+>/g, " ")).replace(/\s+/g, " ");
|
|
365
|
+
// ---- facts
|
|
366
|
+
const fpath = path.join(base, R.facts || "facts.json");
|
|
367
|
+
const facts = fs.existsSync(fpath) ? readJson(fpath) : {};
|
|
368
|
+
const cited = new Set([...JSON.stringify(R).matchAll(/\{\{\s*([A-Za-z_]\w*)/g)].map((m) => m[1]));
|
|
369
|
+
if (cited.size && !Object.keys(facts).length)
|
|
370
|
+
res("facts", false, `report cites ${cited.size} facts but ${path.relative(base, fpath)} is missing`);
|
|
371
|
+
for (const name of sorted(cited)) {
|
|
372
|
+
const f = facts[name];
|
|
373
|
+
if (f === undefined || f === null) {
|
|
374
|
+
res("facts", false, `{{${name}}} is cited but not registered in facts.json`);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
const pk = f.pack;
|
|
378
|
+
const pks = typeof pk === "string" ? [pk] : Array.isArray(pk) ? pk : [];
|
|
379
|
+
const unknown = pks.filter((p) => !(p in policies));
|
|
380
|
+
if (unknown.length && Object.keys(policies).length) {
|
|
381
|
+
res("facts", false, `${name}: source pack ${repr(unknown)} is not one of the sources used (${repr(ids)})`);
|
|
382
|
+
}
|
|
383
|
+
res("facts", ...MA.checkFact(name, f, base));
|
|
384
|
+
}
|
|
385
|
+
if (!cited.size)
|
|
386
|
+
res("facts", false, "the prose cites no {{facts}}; every number in the text must come from facts.json");
|
|
387
|
+
// ---- hand-typed numbers
|
|
388
|
+
const allow = new Set((R.audit_allow || []).map((x) => (x && typeof x === "object" ? str(x.value) : str(x))));
|
|
389
|
+
const found = new Map();
|
|
390
|
+
for (const [where, text] of proseStrings(R)) {
|
|
391
|
+
for (const tok of hardNumbers(text, allow))
|
|
392
|
+
found.set(tok, [...(found.get(tok) || []), where]);
|
|
393
|
+
}
|
|
394
|
+
for (const tok of sorted(found.keys())) {
|
|
395
|
+
res("numbers", false, `hand-typed number '${tok}' in ${sorted(new Set(found.get(tok))).join(", ").slice(0, 120)} ` +
|
|
396
|
+
"-> make it a {{fact}} or add it to audit_allow with a reason");
|
|
397
|
+
}
|
|
398
|
+
if (!found.size)
|
|
399
|
+
res("numbers", true, "every number in the prose is a registered fact, a year, or allowed");
|
|
400
|
+
// ---- exhibits
|
|
401
|
+
(R.exhibits || []).forEach((e, j) => {
|
|
402
|
+
const i = j + 1;
|
|
403
|
+
if (!e.source)
|
|
404
|
+
res("exhibits", false, `exhibit ${i}: no source line`);
|
|
405
|
+
else if (Object.keys(policies).length && !namesSource(e.source, policies)) {
|
|
406
|
+
res("exhibits", false, `exhibit ${i}: the source line names none of the sources used ` +
|
|
407
|
+
`(${Object.values(policies).map((P) => P.agency).join(", ")})`);
|
|
408
|
+
}
|
|
409
|
+
if (!("data" in e))
|
|
410
|
+
return;
|
|
411
|
+
const p = path.join(base, e.data);
|
|
412
|
+
if (!fs.existsSync(p)) {
|
|
413
|
+
res("exhibits", false, `exhibit ${i}: ${e.data} missing`);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const cols = new Set(csvGrid(readText(p))[0] || []);
|
|
417
|
+
const c = e.chart || {};
|
|
418
|
+
const need = [c.x, c.series, ...(Array.isArray(c.y) ? c.y : [c.y]), ...Object.keys(c.filter || {}), ...(c.columns || [])];
|
|
419
|
+
const miss = need.filter((n) => n && !cols.has(n));
|
|
420
|
+
res("exhibits", !miss.length, miss.length ? `exhibit ${i}: missing columns ${repr(miss)}` : `exhibit ${i}: ok`);
|
|
421
|
+
});
|
|
422
|
+
const linPath = path.join(base, "exhibits", "lineage.json");
|
|
423
|
+
if (fs.existsSync(linPath) && Object.keys(policies).length) {
|
|
424
|
+
const lin = readJson(linPath);
|
|
425
|
+
for (const [ex, v] of Object.entries(lin && typeof lin === "object" ? lin : {})) {
|
|
426
|
+
const pks = lineagePacks(v);
|
|
427
|
+
const bad = pks.filter((p) => !(String(p) in policies));
|
|
428
|
+
if (bad.length)
|
|
429
|
+
res("exhibits", false, `${ex}: lineage names ${repr(bad)}, which are not sources of this report`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
// ---- links
|
|
433
|
+
const withheld = {};
|
|
434
|
+
for (const [sid, P] of Object.entries(policies))
|
|
435
|
+
withheld[sid] = PS.withheldKeys(base, sid, P, R);
|
|
436
|
+
for (const d of R.data_files || []) {
|
|
437
|
+
const ok = fs.existsSync(path.join(base, d.path));
|
|
438
|
+
res("links", ok, `${d.path}: ${ok ? "exists" : "MISSING"}`);
|
|
439
|
+
const dd = PS.decide(d.path, base, policies, R, withheld);
|
|
440
|
+
if (!dd.ok && dd.policy)
|
|
441
|
+
res("links", false, `${d.path}: linked, but ${dd.reason}`);
|
|
442
|
+
}
|
|
443
|
+
if (page) {
|
|
444
|
+
const hrefs = [...page.matchAll(/href=['"]([^'"#]+)['"]/g)].map((m) => m[1]);
|
|
445
|
+
const local = sorted(new Set(hrefs.filter((h) => !/^[a-z]+:/.test(h))));
|
|
446
|
+
const outDir = path.dirname(path.resolve(htmlPath));
|
|
447
|
+
for (const h of local) {
|
|
448
|
+
const relp = path.relative(base, path.join(outDir, h)).replaceAll("\\", "/");
|
|
449
|
+
const dd = PS.decide(relp, base, policies, R, withheld);
|
|
450
|
+
if (!dd.ok && dd.policy)
|
|
451
|
+
res("links", false, `report.html links ${relp}: ${dd.reason}`);
|
|
452
|
+
else if (!fs.existsSync(path.join(outDir, h)))
|
|
453
|
+
res("links", false, `report.html links ${h}, which does not exist`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const urls = sorted(new Set([...allStrings(R)].flatMap(findUrls).map((u) => u.replace(/[.,;:]+$/, ""))));
|
|
457
|
+
for (const u of urls) {
|
|
458
|
+
if (!online)
|
|
459
|
+
res("links", true, `${u}: not requested (use online: true to verify)`);
|
|
460
|
+
else
|
|
461
|
+
res("links", ...(await checkUrl(u)));
|
|
462
|
+
}
|
|
463
|
+
// ---- html
|
|
464
|
+
if (!page)
|
|
465
|
+
res("html", false, `${path.relative(base, htmlPath)} does not exist; call build_report`);
|
|
466
|
+
else {
|
|
467
|
+
const dpath = path.join(base, "decisions.json");
|
|
468
|
+
const newest = Math.max(mtime(reportPath), ...[fpath, dpath].filter((p) => fs.existsSync(p)).map(mtime), ...(R.exhibits || []).filter((e) => e.data && fs.existsSync(path.join(base, e.data))).map((e) => mtime(path.join(base, e.data))));
|
|
469
|
+
const up = mtime(htmlPath) >= newest;
|
|
470
|
+
res("html", up, up ? "report.html is up to date" : "report.html is older than its inputs; rebuild it");
|
|
471
|
+
const ext = page.match(/(?:\bsrc\s*=\s*["']|<link[^>]+href\s*=\s*["']|@import\s+|url\(\s*["']?)(?:https?:)?\/\//gi) || [];
|
|
472
|
+
res("html", !ext.length, !ext.length ? "no external resources" : `${ext.length} external resource loads`);
|
|
473
|
+
const first = page.indexOf('class="disclaimer"');
|
|
474
|
+
res("html", first !== -1 && first < page.indexOf('class="masthead'), "AI disclaimer at top of page");
|
|
475
|
+
const visible = page.replace(/<blockquote>[\s\S]*?<\/blockquote>|<pre\b[\s\S]*?<\/pre>|<script\b[\s\S]*?<\/script>/g, "");
|
|
476
|
+
const k = visible.indexOf("{{");
|
|
477
|
+
res("html", k === -1, k === -1 ? "no unresolved {{placeholders}}"
|
|
478
|
+
: `unresolved placeholder near: ${repr(visible.slice(Math.max(0, k - 60), k + 40))}`);
|
|
479
|
+
const left = visible.match(/\[@[^\]]*\]|\[\^\d+\]/g) || [];
|
|
480
|
+
res("html", !left.length, !left.length ? "no raw citation or footnote markup"
|
|
481
|
+
: `raw markup left in the page: ${repr(sorted(new Set(left)).slice(0, 5))}; use [@id] or [@a; @b] and [^n] with matching entries`);
|
|
482
|
+
}
|
|
483
|
+
// ---- vintage
|
|
484
|
+
let anyVintage = false;
|
|
485
|
+
for (const sid of Object.keys(policies)) {
|
|
486
|
+
const [rel, P] = PS.provenance(base, sid, R);
|
|
487
|
+
res("vintage", !!rel, rel ? `${sid}: provenance ${rel}` : `${sid}: no provenance file in data/${sid}/ (request.json): the ` +
|
|
488
|
+
`retrieval date cannot be stated; fetch with the fetch tool (source ${sid})`);
|
|
489
|
+
anyVintage = anyVintage || Object.keys(PS.vintageFields(P)).length > 0;
|
|
490
|
+
}
|
|
491
|
+
if (page && Object.keys(policies).length) {
|
|
492
|
+
res("vintage", page.includes("Data Vintage"), page.includes("Data Vintage") ? "Data Vintage block present"
|
|
493
|
+
: "report.html lacks the Data Vintage block; rebuild with build_report");
|
|
494
|
+
}
|
|
495
|
+
if (anyVintage) {
|
|
496
|
+
const methods = JSON.stringify(R.methods ?? "") + JSON.stringify(R.notes_page ?? "");
|
|
497
|
+
const ok = /vintage|released|release of|as of|revis/i.test(methods);
|
|
498
|
+
res("vintage", ok, ok ? "methods state the vintage and revisions" : "a source records vintage information: the methods " +
|
|
499
|
+
"or notes page must say which release (vintage) the data come from and that the source revises them");
|
|
500
|
+
}
|
|
501
|
+
const prose = new Map();
|
|
502
|
+
for (const [w, s] of proseStrings(R)) { // a tile, finding or exhibit is one unit: its parts are read together
|
|
503
|
+
const unit = w.replace(/\.(?:label|value|note|lead|text|title|subtitle|notes)$/, "");
|
|
504
|
+
prose.set(unit, ((prose.get(unit) || "") + " " + s).trim());
|
|
505
|
+
}
|
|
506
|
+
const labels = {
|
|
507
|
+
preliminary: [/preliminar|subject to revision|advance estimate|revis/i, 'say so ("preliminary", "advance estimate", "subject to revision")'],
|
|
508
|
+
projection: [/project|forecast|estimate[sd]? for|expect/i, 'say it is a projection ("projected", "the agency projects")'],
|
|
509
|
+
vintage: [/as (?:first )?(?:reported|published|estimated)|first (?:release|estimate|reported)|initial(?:ly)?|vintage|real[- ]time|at the time|originally/i,
|
|
510
|
+
'say which vintage ("as first reported", "as published in July 2020")']
|
|
511
|
+
};
|
|
512
|
+
for (const name of sorted(cited)) {
|
|
513
|
+
const f = facts[name] || {};
|
|
514
|
+
const hits = [...prose.values()].filter((s) => new RegExp(String.raw `\{\{\s*` + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + String.raw `\b`).test(s));
|
|
515
|
+
for (const [flag, [pat, fix]] of Object.entries(labels)) {
|
|
516
|
+
if (f[flag]) {
|
|
517
|
+
const ok = hits.every((s) => pat.test(s));
|
|
518
|
+
res("vintage", ok, ok ? `${name}: ${flag} value is labeled as such` : `${name} is a ${flag} value: ${fix} where it is cited`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
// ---- policy: notices, audit hooks, clearances
|
|
523
|
+
for (const n of pol.notices(Object.values(policies))) {
|
|
524
|
+
const norm = n.replace(/\s+/g, " ").trim();
|
|
525
|
+
const ok = pageText.includes(norm);
|
|
526
|
+
res("policy", ok, ok ? `notice present: ${norm.slice(0, 60)}` : `required notice missing from report.html: ` +
|
|
527
|
+
`${repr(norm.slice(0, 100))}; rebuild with build_report`);
|
|
528
|
+
}
|
|
529
|
+
for (const [sid, P] of Object.entries(policies)) {
|
|
530
|
+
for (const [status, hid, msg] of PS.runAuditHooks(P, base, R, facts, pageText))
|
|
531
|
+
res("policy", status === "PASS", `${sid} hook ${hid}: ${msg}`);
|
|
532
|
+
const [w, rows] = PS.withholdRows(base, sid, P);
|
|
533
|
+
if (w) {
|
|
534
|
+
const clear = PS.clearances(R);
|
|
535
|
+
const byKey = new Map(rows.map((x) => [String(x[w.key || ""] ?? ""), x]));
|
|
536
|
+
for (const r of byKey.values()) {
|
|
537
|
+
const k = String(r[w.key || ""] ?? "");
|
|
538
|
+
const c = PS.clearanceFor(clear, sid, k);
|
|
539
|
+
const ok = !!(c && String(c.basis ?? "").trim());
|
|
540
|
+
res("policy", ok, ok ? `${sid} ${k}: ${str(r[w.column] ?? null)}, cleared (${str(c.basis)})` : `${sid} ${k}: ${w.column} ` +
|
|
541
|
+
`${str(r[w.column] ?? null)}; read the terms for it or ask the user, then add report.json "clearance": {"source", ` +
|
|
542
|
+
'"key", "basis", "redistribute": true|false}');
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
// ---- secrets
|
|
547
|
+
const hits = relHits(scanTree([base], knownKeys(), echoSources(policies).length > 0)[0], base);
|
|
548
|
+
res("secrets", !hits.length, !hits.length ? "no API key or credential in any output file" : hits.slice(0, 10).join("; "));
|
|
549
|
+
// ---- style
|
|
550
|
+
const sc = SC.score(JSON.parse(JSON.stringify(R).replace(FACT_RE, "X")))[0];
|
|
551
|
+
res("style", sc >= SC.TARGET, `style guide ${fixed(sc, 0)}% (target ${SC.TARGET}%); call style_check for details`);
|
|
552
|
+
// ---- structure (report mode: exhibit chartbook)
|
|
553
|
+
if (mode === "report") {
|
|
554
|
+
for (const problem of structureProblems(R))
|
|
555
|
+
res("structure", false, problem);
|
|
556
|
+
res("structure", true, "chartbook parts checked");
|
|
557
|
+
}
|
|
558
|
+
// ---- method record: questions, literature, references, assumptions; benchmarks
|
|
559
|
+
results.push(...MA.checkMethod(R, base, facts), ...MA.checkBenchmark(base, facts));
|
|
560
|
+
const norm = (s) => String(s).replace(/\s+/g, " ").trim().toLowerCase();
|
|
561
|
+
for (const [k] of MA.escapes(R)) { // each unverifiable claim must reach the reader
|
|
562
|
+
const text = (R.disclosures || {})[k];
|
|
563
|
+
if (text) {
|
|
564
|
+
const shown = norm(pageText).includes(norm(text));
|
|
565
|
+
res("disclosures", shown, shown ? `${k}: disclosure shown on the page` : `${k}: the disclosure ${repr(text)} is not on ` +
|
|
566
|
+
"the page: rebuild (the builder prints it in Appendix A)");
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
// ---- replication package
|
|
570
|
+
const zp = path.join(base, "replication_package.zip");
|
|
571
|
+
if (!fs.existsSync(zp))
|
|
572
|
+
res("replication", false, "replication_package.zip missing; call build_report");
|
|
573
|
+
else {
|
|
574
|
+
let z = {};
|
|
575
|
+
try {
|
|
576
|
+
z = unzipSync(fs.readFileSync(zp));
|
|
577
|
+
}
|
|
578
|
+
catch {
|
|
579
|
+
res("replication", false, "replication_package.zip is not a readable ZIP; call build_report");
|
|
580
|
+
}
|
|
581
|
+
const names = new Set(Object.keys(z));
|
|
582
|
+
const need = ["REPLICATION.md", "facts.json"];
|
|
583
|
+
need.push(...["spec.json", "plan.json", "exhibits/lineage.json"].filter((x) => fs.existsSync(path.join(base, x))));
|
|
584
|
+
need.push(...(R.exhibits || []).filter((e) => e.data).map((e) => String(e.data).replaceAll("\\", "/")));
|
|
585
|
+
for (const [sid, P] of Object.entries(policies)) {
|
|
586
|
+
if (P.redistribution.mode === "definition_only") {
|
|
587
|
+
need.push(`reproduce/${sid}/REPRODUCE.md`);
|
|
588
|
+
for (const ext of [".sh", ".ps1"]) { // one-command download scripts with the request built in
|
|
589
|
+
if (![...names].some((n) => n.startsWith(`reproduce/${sid}/`) && n.endsWith(ext)))
|
|
590
|
+
need.push(`reproduce/${sid}/download_*${ext}`);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
const [rel] = PS.provenance(base, sid, R);
|
|
595
|
+
if (rel)
|
|
596
|
+
need.push(rel);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const miss = need.filter((n) => !names.has(n));
|
|
600
|
+
res("replication", !miss.length, !miss.length ? "package complete" : `package lacks ${repr(miss)}`);
|
|
601
|
+
const viol = [];
|
|
602
|
+
for (const n of sorted(names)) {
|
|
603
|
+
if (n === "REPLICATION.md" || n.endsWith("/"))
|
|
604
|
+
continue;
|
|
605
|
+
const d = PS.decide(n, base, policies, R, withheld);
|
|
606
|
+
if (!d.ok && d.policy)
|
|
607
|
+
viol.push(`${n} (${d.reason})`);
|
|
608
|
+
}
|
|
609
|
+
for (const [sid, P] of Object.entries(policies)) { // core's own check, on the source's own files
|
|
610
|
+
const scope = [...names].filter((n) => n.startsWith(`data/${sid}/`) || !["data/", "exhibits/", "lib/"].some((x) => n.startsWith(x)));
|
|
611
|
+
viol.push(...PS.checkPackage(P, scope).map((n) => `${n} (core.policy.check_package: ${sid})`));
|
|
612
|
+
}
|
|
613
|
+
res("replication", !viol.length, !viol.length ? "no file the source terms forbid"
|
|
614
|
+
: "package holds files the source terms forbid: " + sorted(new Set(viol)).slice(0, 6).join("; "));
|
|
615
|
+
for (const [sid, P] of Object.entries(policies)) { // withheld rows must not be in shared CSVs
|
|
616
|
+
const keys = withheld[sid] || new Set();
|
|
617
|
+
const w = P.redistribution.withhold || {};
|
|
618
|
+
if (!keys.size)
|
|
619
|
+
continue;
|
|
620
|
+
for (const n of names) {
|
|
621
|
+
if (n.startsWith(`data/${sid}/`) && n.endsWith(".csv") && n !== `data/${sid}/${w.meta}`) {
|
|
622
|
+
const d = readDict(Buffer.from(z[n]).toString("utf8"));
|
|
623
|
+
if (d.fields.includes(w.key)) {
|
|
624
|
+
const leaked = sorted(new Set(d.rows.map((r) => String(r[w.key] ?? "")).filter((v) => keys.has(v))));
|
|
625
|
+
res("replication", !leaked.length, !leaked.length ? `${n}: no withheld rows` : `${n} holds rows of withheld ${w.key} ${repr(leaked.slice(0, 5))}`);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (rerunIt) {
|
|
632
|
+
const tracked = (R.exhibits || []).filter((e) => e.data).map((e) => path.join(base, e.data));
|
|
633
|
+
results.push(...(await MA.rerun(base, fpath, tracked)));
|
|
634
|
+
}
|
|
635
|
+
return results;
|
|
636
|
+
}
|
|
637
|
+
//# sourceMappingURL=audit_report.js.map
|