// Builds the FactHub dataset release for Washington's share of U.S. apple production: // CSV tables, documentation, quality report, source manifest, and the create_dataset_draft request. // Usage: node build_release.js // Node.js 20 or later, no packages. Run after fetch_sources.js and analyze.js. const fs = require('fs'); const path = require('path'); const crypto = require('crypto'); const [rawDir, resDir, buildDir, rel] = process.argv.slice(2); if (!rel) { console.error('usage: node build_release.js '); process.exit(1); } fs.mkdirSync(rel, { recursive: true }); const KEY = 'wa-apple-production-share'; const RETRIEVED = '2026-10-09'; const EXECUTED = '2026-10-09T17:00:00Z'; const sha = (buf) => 'sha256:' + crypto.createHash('sha256').update(buf).digest('hex'); const R = JSON.parse(fs.readFileSync(path.join(resDir, 'apples.json'), 'utf8')); const A = R.analyses; const manifest = JSON.parse(fs.readFileSync(path.join(rawDir, 'fetch-manifest.json'), 'utf8')); const archives = JSON.parse(fs.readFileSync(path.join(buildDir, 'archives.json'), 'utf8')); const ST = { AL: 'Alabama', AZ: 'Arizona', AR: 'Arkansas', CA: 'California', CO: 'Colorado', CT: 'Connecticut', DE: 'Delaware', GA: 'Georgia', ID: 'Idaho', IL: 'Illinois', IN: 'Indiana', IA: 'Iowa', KS: 'Kansas', KY: 'Kentucky', ME: 'Maine', MD: 'Maryland', MA: 'Massachusetts', MI: 'Michigan', MN: 'Minnesota', MO: 'Missouri', MT: 'Montana', NE: 'Nebraska', NV: 'Nevada', NH: 'New Hampshire', NJ: 'New Jersey', NM: 'New Mexico', NY: 'New York', NC: 'North Carolina', ND: 'North Dakota', OH: 'Ohio', OK: 'Oklahoma', OR: 'Oregon', PA: 'Pennsylvania', RI: 'Rhode Island', SC: 'South Carolina', SD: 'South Dakota', TN: 'Tennessee', TX: 'Texas', UT: 'Utah', VT: 'Vermont', VA: 'Virginia', WA: 'Washington', WV: 'West Virginia', WI: 'Wisconsin', WY: 'Wyoming', US: 'United States', OT: 'Other states (combined by NASS)' }; const stateName = (c) => ST[c] || c; const csv = (rows) => { const cols = Object.keys(rows[0]); return cols.join(',') + '\n' + rows.map((r) => cols.map((c) => (r[c] == null ? '' : /[",]/.test(String(r[c])) ? `"${String(r[c]).replace(/"/g, '""')}"` : r[c])).join(',')).join('\n') + '\n'; }; const fmt = (x, d = 1) => Number(x).toFixed(d); // ---------- Source ids ---------- const SRC_OF_FILE = { 'quickstats_apples_state_national.csv': 'nass-quickstats-survey', 'NoncFruiNu-07-08-2003_Annual_Summary.txt': 'nass-noncitrus-2002-summary', 'NoncFruiNu-07-06-2006_final.txt': 'nass-noncitrus-2005-summary', 'NoncFruiNu-07-08-2008_revision.txt': 'nass-noncitrus-2007-summary', }; const LOCATOR = { 'quickstats_apples_state_national.csv': 'Quick Stats, program SURVEY, commodity APPLES, statistic categories PRODUCTION and AREA BEARING, state and national, annual', 'NoncFruiNu-07-08-2003_Annual_Summary.txt': 'Apples, Commercial: Bearing Acreage and Yield; Total and Utilized Production; Price and Value by State, 2000-2002', 'NoncFruiNu-07-06-2006_final.txt': 'Apples, Commercial: Bearing Acreage and Yield; Total and Utilized Production; Price and Value by State, 2003-2005 (2003 and 2004 columns used)', 'NoncFruiNu-07-08-2008_revision.txt': 'Apples, Commercial: Bearing Acreage and Yield; Total and Utilized Production; Price and Value by State, 2005-2007 (2005 and 2006 columns used)', }; // ---------- Tables ---------- const T = {}; T['state-year-production'] = R.stateYear.map((r) => ({ year: r.year, state_code: r.code, state: stateName(r.code), bearing_acres: r.bearingAcres, total_production_mlb: r.totalMlb, utilized_production_mlb: r.utilizedMlb, fresh_market_mlb: r.freshMlb, utilized_value_kusd: r.valueKusd, source_id: SRC_OF_FILE[r.sourceFile], source_locator: LOCATOR[r.sourceFile] })); T['annual-wa-share'] = R.annual.map((a) => ({ year: a.year, states_estimated: a.statesEstimated, us_utilized_mlb: a.usUtilizedMlb, wa_utilized_mlb: a.waUtilizedMlb, wa_share_utilized_pct: a.waShareUtilizedPct, wa_share_total_production_pct: a.waShareTotalPct, wa_share_value_pct: a.waShareValuePct, wa_share_bearing_acres_pct: a.waShareBearingAcresPct, wa_share_fresh_market_pct: a.waShareFreshPct, second_state: stateName(a.secondState), second_state_utilized_mlb: a.secondUtilizedMlb, wa_to_second_ratio: a.waToSecondRatio, seven_state_utilized_mlb: a.sevenStateUtilizedMlb, wa_share_of_seven_states_pct: a.waShareOfSevenStatesPct, other_states_utilized_mlb: a.otherStatesUtilizedMlb, us_minus_sum_of_states_mlb: a.usMinusSumOfStatesMlb })); T['census-acreage'] = A.census.map((c) => ({ census_year: c.year, us_bearing_acres: c.usBearingAcres, wa_bearing_acres: c.waBearingAcres, wa_bearing_acres_cv_pct: c.waBearingCvPct, wa_share_bearing_acres_pct: c.waShareBearingPct, us_total_acres: c.usTotalAcres, wa_total_acres: c.waTotalAcres, wa_share_total_acres_pct: c.waShareTotalAcresPct, second_state: c.secondState.replace(/\b(\w)(\w*)/g, (m, a, b) => a + b.toLowerCase()), second_state_bearing_acres: c.secondBearingAcres, states_with_bearing_acres: c.statesWithBearingAcres })); const files = {}; for (const [id, rows] of Object.entries(T)) files[id] = { fileName: id + '.csv', bytes: Buffer.from(csv(rows)) }; // ---------- Documentation ---------- const s = A.summary; const readme = `# Washington's share of U.S. commercial apple production, 2000-2025 FactHub-curated dataset. Not an official USDA publication. All production, value and acreage figures are USDA National Agricultural Statistics Service (NASS) estimates; FactHub computed the shares and comparisons. ## What this is State and U.S. commercial apple production (total and utilized), value of utilized production, bearing acreage and fresh-market production for 2000-2025, plus Census of Agriculture apple acreage for 2002-2022, with saved analyses of Washington's share. ## Sources and year coverage - 2000-2002: NASS Noncitrus Fruits and Nuts 2002 Summary (July 2003), apple tables. - 2003-2004: NASS Noncitrus Fruits and Nuts 2005 Summary (July 2006). - 2005-2006: NASS Noncitrus Fruits and Nuts 2007 Summary (July 2008, revised). - 2007-2025: NASS Quick Stats survey estimates (latest revisions). - Census of Agriculture apple acreage (2002, 2007, 2012, 2017, 2022): NASS Quick Stats, program CENSUS. - 2026 forecast (total production): NASS Quick Stats (August 2026 Crop Production forecast). Each year comes from one source. Overlapping years in other NASS files are compared in quality-report.md. ## How the Quick Stats files were obtained The Quick Stats API needs a key, so fetch_sources.js uses the public Quick Stats web interface: it POSTs the query form to https://quickstats.nass.usda.gov/uuid/encode and downloads the CSV export from /data/spreadsheet/.csv. The queries are listed in source-manifest.json. ## Method 1. Parse the fixed-width state tables in the three older NASS summaries (columns are matched by position; blank cells stay empty). 2. Read the Quick Stats CSV, keep annual state and national rows with domain TOTAL, and convert pounds to million pounds and dollars to thousand dollars. 3. Washington share = Washington utilized production / U.S. utilized production. The same ratio is computed for total production, value, bearing acres and fresh-market production. 4. Second-largest state and Washington-to-second ratio use utilized production among individually published states. 5. Sensitivity: since 2018 NASS publishes seven states (CA, MI, NY, OR, PA, VA, WA) and its U.S. total is their sum. The adjusted share adds back ${fmt(A.adjusted.otherStatesMeanMlb2015to2017)} million pounds, the 2015-2017 average utilized production of all other states. ## Definitions (NASS) - Commercial apple estimates cover orchards of 100 or more bearing-age trees. - Total production includes unharvested fruit and fruit harvested but not sold; utilized production excludes both. - Value of utilized production is NASS's price per pound times utilized production. ## Reproduce node fetch_sources.js raw; node analyze.js raw results; node build_release.js raw results release Node.js 20 or later, no packages. Quick Stats returns current data, so later NASS revisions may change 2007-2025 values slightly. `; const cc = R.crossChecks; const quality = `# Quality report ## Internal consistency - In every year, the U.S. utilized production equals the sum of the published states plus NASS's "Other states" aggregate (maximum difference ${Math.max(...R.annual.map((a) => Math.abs(a.usMinusSumOfStatesMlb)))} million pounds). - Quick Stats marks ${R.suppressed.length} state values as withheld or not applicable (for example "(D)" or "(X)"). They are blank in the tables; NASS includes withheld values in "Other states". ## Cross-checks against a second NASS file | Year | Area | Check | Other file (million lb) | Adopted (million lb) | Difference | |---|---|---|---|---|---| ${cc.map((c) => `| ${c.year} | ${c.code} | ${c.check} | ${c.reportUtilizedMlb} | ${c.adoptedUtilizedMlb} | ${c.differenceMlb} |`).join('\n')} Differences come from NASS revisions published in later reports; the adopted value is always the later one. ## Coverage changes - States estimated: ${R.annual[0].statesEstimated} in 2000, ${R.annual.find((a) => a.year === 2017).statesEstimated} in 2017, 7 from 2018. Washington's share of the published U.S. total therefore rises slightly in 2018 for a definitional reason (see the seven-state sensitivity analysis). - Fresh-market production by state is included only from 2007 (Quick Stats). `; files['documentation'] = { fileName: 'README.md', bytes: Buffer.from(readme) }; files['quality-report'] = { fileName: 'quality-report.md', bytes: Buffer.from(quality) }; const srcManifest = { retrievedAt: manifest.retrievedAt, note: 'Raw inputs as downloaded by fetch_sources.js. Source documents are not redistributed here; download them from the URLs.', files: manifest.files }; files['source-manifest'] = { fileName: 'source-manifest.json', bytes: Buffer.from(JSON.stringify(srcManifest, null, 2) + '\n') }; for (const [id, f] of [['script-fetch', 'fetch_sources.js'], ['script-analyze', 'analyze.js'], ['script-build', 'build_release.js']]) files[id] = { fileName: f, bytes: fs.readFileSync(path.join(__dirname, f)) }; for (const f of Object.values(files)) fs.writeFileSync(path.join(rel, f.fileName), f.bytes); const MEDIA = { csv: 'text/csv', md: 'text/markdown', json: 'application/json', js: 'text/javascript' }; const ROLE = { 'state-year-production': 'curatedTable', 'annual-wa-share': 'derivedTable', 'census-acreage': 'curatedTable', documentation: 'documentation', 'quality-report': 'qualityReport', 'source-manifest': 'sourceManifest', 'script-fetch': 'transformationManifest', 'script-analyze': 'transformationManifest', 'script-build': 'transformationManifest' }; const DESC = { 'state-year-production': 'NASS commercial apple estimates by state and year, 2000-2025: bearing acres, total and utilized production, fresh-market production and value.', 'annual-wa-share': "Washington's share of U.S. utilized production, total production, value, bearing acres and fresh-market production by year, with the second-largest state and seven-state comparisons.", 'census-acreage': 'Census of Agriculture apple acreage (all farms) for the United States and Washington, 2002-2022.', documentation: 'What the dataset contains, sources by year, method, definitions and how to reproduce it.', 'quality-report': 'Internal consistency checks, cross-checks between NASS files, and coverage changes.', 'source-manifest': 'Every raw input with its URL, Quick Stats query, byte length and SHA-256 at download.', 'script-fetch': 'Downloads the raw NASS and ERS files (Quick Stats web export and ESMIS reports).', 'script-analyze': 'Parses the raw files and computes every share and comparison.', 'script-build': 'Writes the CSV tables, documentation and this dataset payload.', }; const artifacts = Object.entries(files).map(([id, f]) => ({ id, role: ROLE[id], fileName: f.fileName, mediaType: MEDIA[f.fileName.split('.').pop()], byteLength: f.bytes.length, contentDigest: sha(f.bytes), description: DESC[id], access: 'public' })); // ---------- Sources ---------- const mf = (file) => manifest.files.find((f) => f.file === file); const arch = (url) => { const a = archives[url]; if (!a) return {}; const o = {}; if (a.archiveUrl) o.archiveUrl = a.archiveUrl; if (a.archivedAt) o.archivedAt = a.archivedAt; if (a.contentDigest) o.contentDigest = a.contentDigest; return o; }; const usda = { licenseName: 'Public domain (U.S. government work)', licenseUrl: 'https://www.usa.gov/government-copyright', redistribution: 'Unrestricted; U.S. federal government data are not subject to copyright.' }; const src = (id, name, url, role) => ({ id, name, url, retrievedAt: RETRIEVED, role, ...usda, ...arch(url) }); const sources = [ src('nass-quickstats-survey', `USDA NASS Quick Stats: apples, survey program, state and national, annual (query ${mf('quickstats_apples_state_national.csv').query})`, mf('quickstats_apples_state_national.csv').download, 'Primary data, 2007-2025 estimates and 2026 forecast'), src('nass-quickstats-census', `USDA NASS Quick Stats: apples, Census of Agriculture, state and national (query ${mf('quickstats_census_apples.csv').query})`, mf('quickstats_census_apples.csv').download, 'Primary data, all-farm apple acreage 2002-2022'), src('nass-noncitrus-2002-summary', 'USDA NASS, Noncitrus Fruits and Nuts 2002 Summary (Fr Nt 3-1 (03)), July 8, 2003', mf('NoncFruiNu-07-08-2003_Annual_Summary.txt').url, 'Primary data, 2000-2002 estimates'), src('nass-noncitrus-2005-summary', 'USDA NASS, Noncitrus Fruits and Nuts 2005 Summary, July 6, 2006', mf('NoncFruiNu-07-06-2006_final.txt').url, 'Primary data, 2003-2004 estimates'), src('nass-noncitrus-2007-summary', 'USDA NASS, Noncitrus Fruits and Nuts 2007 Summary (revised), July 8, 2008', mf('NoncFruiNu-07-08-2008_revision.txt').url, 'Primary data, 2005-2006 estimates; cross-check for 2007'), src('nass-noncitrus-2025-summary', 'USDA NASS, Noncitrus Fruits and Nuts 2025 Summary, May 2026', mf('ncit0526.txt').url, 'Cross-check for 2023-2025 and definition of commercial orchards'), src('ers-fts-386', 'USDA ERS, Fruit and Tree Nuts Outlook: September 2026 (FTS-386), September 24, 2026', mf('fts-386.pdf').url, 'External comparison: Washington share of fresh-market apples; 2026 forecast context'), ]; // ---------- Fields ---------- const F = (name, type, description, units, nullable, valueType, sourceIds, derivation = null) => ({ name, type, description, units, nullable, valueType, derivation, sourceIds }); const SURVEY = ['nass-quickstats-survey', 'nass-noncitrus-2002-summary', 'nass-noncitrus-2005-summary', 'nass-noncitrus-2007-summary']; const tables = [ { id: 'state-year-production', title: 'Commercial apple estimates by state and year', description: 'NASS commercial apple estimates for each published state, the NASS "Other states" aggregate where present, and the United States, 2000-2025. One row per state per year.', artifactId: 'state-year-production', unitOfObservation: 'State-year (crop year)', fields: [ F('year', 'integer', 'Crop year.', null, false, 'observed', SURVEY), F('state_code', 'string', 'Two-letter postal code; US for the national total; OT for the NASS "Other states" aggregate of withheld states.', null, false, 'observed', SURVEY), F('state', 'string', 'State name.', null, false, 'observed', SURVEY), F('bearing_acres', 'number', 'Bearing acreage of commercial orchards. Blank when NASS withheld or did not publish it.', 'acres', true, 'observed', SURVEY), F('total_production_mlb', 'number', 'Total production, including unharvested fruit and fruit harvested but not sold.', 'million pounds', true, 'observed', SURVEY, 'Quick Stats pounds divided by 1,000,000; reports already in million pounds.'), F('utilized_production_mlb', 'number', 'Utilized production (fresh market plus processing).', 'million pounds', true, 'observed', SURVEY, 'Quick Stats pounds divided by 1,000,000; reports already in million pounds.'), F('fresh_market_mlb', 'number', 'Utilized production sold for fresh market. Only 2007-2025 (Quick Stats).', 'million pounds', true, 'observed', ['nass-quickstats-survey'], 'Quick Stats pounds divided by 1,000,000.'), F('utilized_value_kusd', 'number', 'Value of utilized production, nominal dollars.', 'thousand U.S. dollars', true, 'observed', SURVEY, 'Quick Stats dollars divided by 1,000; reports already in thousand dollars.'), F('source_id', 'string', 'Id of the dataset source this row was taken from.', null, false, 'observed', []), F('source_locator', 'string', 'Table or query within that source.', null, false, 'observed', []), ] }, { id: 'annual-wa-share', title: "Washington's share of U.S. commercial apples by year", description: "Washington's share of U.S. utilized production, total production, value, bearing acres and fresh-market production, with the second-largest state and seven-state comparisons, 2000-2025.", artifactId: 'annual-wa-share', unitOfObservation: 'Crop year', fields: [ F('year', 'integer', 'Crop year.', null, false, 'observed', SURVEY), F('states_estimated', 'integer', 'Number of individually published states with utilized production that year.', 'states', false, 'derived', SURVEY, 'Count of state rows (excluding US and Other states).'), F('us_utilized_mlb', 'number', 'U.S. utilized production as published by NASS (sum of estimated states).', 'million pounds', false, 'observed', SURVEY), F('wa_utilized_mlb', 'number', 'Washington utilized production.', 'million pounds', false, 'observed', SURVEY), F('wa_share_utilized_pct', 'number', "Washington's share of U.S. utilized production.", 'percent', false, 'derived', SURVEY, '100 x wa_utilized_mlb / us_utilized_mlb'), F('wa_share_total_production_pct', 'number', "Washington's share of U.S. total production.", 'percent', true, 'derived', SURVEY, '100 x WA total / US total'), F('wa_share_value_pct', 'number', "Washington's share of U.S. value of utilized production.", 'percent', true, 'derived', SURVEY, '100 x WA value / US value'), F('wa_share_bearing_acres_pct', 'number', "Washington's share of U.S. commercial bearing acres. Rises in 2018 partly because the U.S. total then covers seven states.", 'percent', true, 'derived', SURVEY, '100 x WA bearing acres / US bearing acres'), F('wa_share_fresh_market_pct', 'number', "Washington's share of U.S. fresh-market production, 2007-2025.", 'percent', true, 'derived', ['nass-quickstats-survey'], '100 x WA fresh / US fresh'), F('second_state', 'string', 'State with the second-largest utilized production.', null, false, 'derived', SURVEY, 'Rank of individually published states by utilized production.'), F('second_state_utilized_mlb', 'number', 'Utilized production of the second-largest state.', 'million pounds', false, 'observed', SURVEY), F('wa_to_second_ratio', 'number', "Washington's utilized production divided by the second-largest state's.", 'ratio', false, 'derived', SURVEY, 'wa_utilized_mlb / second_state_utilized_mlb'), F('seven_state_utilized_mlb', 'number', 'Sum of CA, MI, NY, OR, PA, VA and WA utilized production.', 'million pounds', false, 'derived', SURVEY, 'Sum over the seven states NASS still estimates.'), F('wa_share_of_seven_states_pct', 'number', "Washington's share of the seven-state sum (a consistent denominator across all years).", 'percent', false, 'derived', SURVEY, '100 x wa_utilized_mlb / seven_state_utilized_mlb'), F('other_states_utilized_mlb', 'number', 'Utilized production of all states outside the seven, including the NASS "Other states" aggregate. Zero from 2018 because NASS no longer estimates them, not because they grow no apples.', 'million pounds', false, 'derived', SURVEY, 'Sum of published states plus Other states, minus the seven-state sum.'), F('us_minus_sum_of_states_mlb', 'number', 'Consistency check: U.S. total minus the sum of published states and the Other states aggregate.', 'million pounds', false, 'derived', SURVEY, 'us_utilized_mlb - sum of state rows'), ] }, { id: 'census-acreage', title: 'Census of Agriculture apple acreage, United States and Washington', description: 'Apple acreage on all farms (not only commercial orchards of 100 or more trees) in every state, from the Census of Agriculture, 2002-2022.', artifactId: 'census-acreage', unitOfObservation: 'Census year', fields: [ F('census_year', 'integer', 'Census of Agriculture year.', null, false, 'observed', ['nass-quickstats-census']), F('us_bearing_acres', 'number', 'U.S. bearing apple acres, all farms.', 'acres', false, 'observed', ['nass-quickstats-census']), F('wa_bearing_acres', 'number', 'Washington bearing apple acres, all farms.', 'acres', false, 'observed', ['nass-quickstats-census']), F('wa_bearing_acres_cv_pct', 'number', 'NASS coefficient of variation for the Washington estimate (published from 2012).', 'percent', true, 'observed', ['nass-quickstats-census']), F('wa_share_bearing_acres_pct', 'number', "Washington's share of U.S. bearing apple acres.", 'percent', false, 'derived', ['nass-quickstats-census'], '100 x wa_bearing_acres / us_bearing_acres'), F('us_total_acres', 'number', 'U.S. bearing and non-bearing apple acres.', 'acres', false, 'observed', ['nass-quickstats-census']), F('wa_total_acres', 'number', 'Washington bearing and non-bearing apple acres.', 'acres', false, 'observed', ['nass-quickstats-census']), F('wa_share_total_acres_pct', 'number', "Washington's share of all U.S. apple acres.", 'percent', false, 'derived', ['nass-quickstats-census'], '100 x wa_total_acres / us_total_acres'), F('second_state', 'string', 'State with the second-most bearing acres.', null, false, 'derived', ['nass-quickstats-census'], 'Rank of states by bearing acres.'), F('second_state_bearing_acres', 'number', 'Bearing acres of that state.', 'acres', false, 'observed', ['nass-quickstats-census']), F('states_with_bearing_acres', 'integer', 'Number of states with a published bearing-acre value.', 'states', false, 'derived', ['nass-quickstats-census']), ] }, ]; // ---------- Saved analyses ---------- const adj = A.adjusted; const lat = R.annual.find((a) => a.year === 2025); const analyses = [ { id: 'wa-share-series', title: "Washington's share of U.S. apple production and crop value, 2000-2025", question: "What share of U.S. commercial apple production (utilized pounds) and of its value did Washington account for each year?", operation: 'ratio-by-year', parameters: { tableId: 'annual-wa-share', numerator: 'Washington', denominator: 'U.S. total as published by NASS', fields: ['wa_share_utilized_pct', 'wa_share_value_pct'] }, scope: '2000-2025, one row per year per series (utilized production; value of utilized production).', resultShape: 'timeSeries', structuredResult: A.shareSeries, displayResult: `Washington's share of U.S. utilized apple production ranged from ${fmt(s.minSharePct)}% (${s.minYear}) to ${fmt(s.maxSharePct)}% (${s.maxYear}) and was ${fmt(s.latestSharePct)}% in 2025. Its share of crop value ranged from ${fmt(Math.min(...R.annual.map((a) => a.waShareValuePct)))}% to ${fmt(Math.max(...R.annual.map((a) => a.waShareValuePct)))}%.`, methodologicalNotes: ['Shares use NASS utilized production (fresh plus processing), which excludes unharvested fruit and fruit harvested but not sold.', 'Value is nominal and uses NASS price per pound; Washington earns more per pound than the national average in most years, so its value share is usually above its volume share.'], limitations: ['From 2018 the published U.S. total covers only seven states, which raises the share by roughly 3 to 4 points compared with a full national total (see seven-state-sensitivity).', 'NASS estimates cover commercial orchards of 100 or more bearing trees, not backyard or very small orchards.', 'Year-to-year swings are driven by crop failures and alternate bearing in individual states, not only by long-term trends: the 2012 peak reflects the Michigan crop falling to 115 million pounds (975 million in 2011) and the New York crop to 710 million (1,210 million in 2011).'], executedAt: EXECUTED, robustnessChecks: [ { analysisId: 'seven-state-sensitivity', checkType: 'sensitivity', summary: `Adding back the 2015-2017 average output of the states NASS stopped estimating lowers Washington's 2018-2025 share to ${fmt(adj.minAdjustedPct)}-${fmt(adj.maxAdjustedPct)}% (2025: ${fmt(adj.rows.find((r) => r.year === 2025).adjustedSharePct)}%). Washington stays above half in every year.` }, { analysisId: 'census-acreage-share', checkType: 'alternativeComparison', summary: `On acreage from the Census of Agriculture, which covers all farms in every state, Washington had ${fmt(A.census[4].waShareBearingPct)}% of U.S. bearing apple acres in 2022 and ${fmt(A.census[0].waShareBearingPct)}% in 2002. Its share of production is higher because its yields per acre are higher.` }, { analysisId: 'second-largest-state', checkType: 'other', summary: `Washington ranked first in every year; its utilized production was at least ${fmt(s.minWaToSecondRatio, 2)} times the second-largest state's (${s.minRatioYear}).` }, ] }, { id: 'share-summary', title: "Summary of Washington's share, 2000-2025", question: 'Across 2000-2025, in how many years did Washington produce more than half of U.S. utilized apples, and what were the lowest, highest and average shares?', operation: 'summary-statistics', parameters: { tableId: 'annual-wa-share', field: 'wa_share_utilized_pct', years: '2000-2025' }, scope: '26 crop years, 2000-2025.', resultShape: 'scalar', structuredResult: s, displayResult: `Washington produced more than half of U.S. utilized apples in ${s.yearsAbove50Pct} of ${s.nYears} years. Lowest ${fmt(s.minSharePct)}% (${s.minYear}), highest ${fmt(s.maxSharePct)}% (${s.maxYear}), mean ${fmt(s.meanSharePct)}%; 2000-2004 average ${fmt(s.mean2000to2004Pct)}%, 2021-2025 average ${fmt(s.mean2021to2025Pct)}%.`, methodologicalNotes: ['Mean is the simple average of annual shares, not a production-weighted share.'], limitations: ['The 2021-2025 average uses the seven-state U.S. total; see seven-state-sensitivity for the adjusted range.'], executedAt: EXECUTED }, { id: 'state-ranking-2025', title: 'Apple production by state, 2025', question: 'How did the seven states NASS estimates rank in 2025 utilized production?', operation: 'rank', parameters: { tableId: 'state-year-production', year: 2025, field: 'utilized_production_mlb' }, scope: '2025 crop year, seven NASS program states.', resultShape: 'table', structuredResult: A.ranking2025, displayResult: A.ranking2025.slice(0, 4).map((r) => `${r.state} ${fmt(r.utilizedMlb)} million lb (${fmt(r.sharePct)}%)`).join('; ') + '.', limitations: ['Shares are of the seven-state total that NASS publishes as the U.S. total.', 'States outside the seven are not estimated.'], executedAt: EXECUTED }, { id: 'second-largest-state', title: 'Second-largest apple state and Washington-to-second ratio, 2000-2025', question: 'Which state ranked second each year, and how many times larger was Washington?', operation: 'rank-and-ratio', parameters: { tableId: 'annual-wa-share', fields: ['second_state', 'second_state_utilized_mlb', 'wa_to_second_ratio'] }, scope: '2000-2025.', resultShape: 'table', structuredResult: A.secondState, displayResult: `New York was second in ${A.secondState.filter((r) => r.secondState === 'New York').length} of 26 years and Michigan in ${A.secondState.filter((r) => r.secondState === 'Michigan').length}. Washington produced ${fmt(s.minWaToSecondRatio, 2)} to ${fmt(Math.max(...A.secondState.map((r) => r.waToSecondRatio)), 2)} times as much as the second state.`, limitations: ['Ranks use utilized production; total-production ranks can differ slightly in years with large unharvested losses.'], executedAt: EXECUTED }, { id: 'seven-state-sensitivity', title: 'Sensitivity: U.S. total including states NASS stopped estimating in 2018', question: "How much does Washington's share change if the published 2018-2025 U.S. total is adjusted for the states NASS no longer estimates?", operation: 'adjusted-ratio', parameters: { tableId: 'annual-wa-share', otherStatesMeanMlb2015to2017: adj.otherStatesMeanMlb2015to2017, method: 'adjusted share = WA / (published US + mean 2015-2017 utilized production of all states outside CA, MI, NY, OR, PA, VA, WA)' }, scope: '2018-2025.', resultShape: 'table', structuredResult: adj.rows, displayResult: `Adjusted shares are ${fmt(adj.minAdjustedPct)}-${fmt(adj.maxAdjustedPct)}% (published: ${fmt(Math.min(...adj.rows.map((r) => r.waShareUtilizedPct)))}-${fmt(Math.max(...adj.rows.map((r) => r.waShareUtilizedPct)))}%).`, methodologicalNotes: [`States outside the seven produced ${R.annual.filter((a) => a.year >= 2015 && a.year <= 2017).map((a) => fmt(a.otherStatesUtilizedMlb)).join(', ')} million pounds in 2015-2017 (${R.annual.filter((a) => a.year >= 2015 && a.year <= 2017).map((a) => fmt(100 * a.otherStatesUtilizedMlb / a.usUtilizedMlb)).join(', ')}% of the U.S. total).`], limitations: ['The add-back is an estimate: it assumes other states kept producing at their 2015-2017 average. Fewer states were estimated in 2016-2017 than earlier, so the add-back may be low.'], executedAt: EXECUTED }, { id: 'census-acreage-share', title: "Washington's share of U.S. apple acreage, Census of Agriculture 2002-2022", question: "What share of all U.S. apple acreage, counted on every farm in every state, is in Washington?", operation: 'ratio-by-census-year', parameters: { tableId: 'census-acreage', fields: ['wa_share_bearing_acres_pct', 'wa_share_total_acres_pct'] }, scope: 'Census years 2002, 2007, 2012, 2017 and 2022.', resultShape: 'table', structuredResult: A.census.map((c) => ({ year: c.year, waShareBearingPct: c.waShareBearingPct, waShareTotalAcresPct: c.waShareTotalAcresPct, waBearingAcres: c.waBearingAcres, usBearingAcres: c.usBearingAcres, waBearingCvPct: c.waBearingCvPct })), displayResult: `Washington had ${A.census.map((c) => fmt(c.waShareBearingPct)).join('%, ')}% of U.S. bearing apple acres in ${A.census.map((c) => c.year).join(', ')}.`, methodologicalNotes: ['The Census of Agriculture counts every farm with apple trees, so it includes the small and non-commercial orchards that the annual survey leaves out.'], limitations: ['Acreage is not production; Washington yields per acre are well above the national average, so its share of acres understates its share of pounds.', 'Census estimates carry sampling and non-response error (Washington CV 3.5-9.2% where published).'], executedAt: EXECUTED }, { id: 'fresh-market-share', title: "Washington's share of U.S. fresh-market apples, 2007-2025", question: 'What share of apples sold for fresh eating came from Washington?', operation: 'ratio-by-year', parameters: { tableId: 'annual-wa-share', field: 'wa_share_fresh_market_pct' }, scope: '2007-2025.', resultShape: 'timeSeries', structuredResult: A.fresh.map((f) => ({ year: f.year, sharePct: f.waShareFreshPct, waFreshMlb: f.waFreshMlb, usFreshMlb: f.usFreshMlb })), displayResult: `Washington supplied ${fmt(Math.min(...A.fresh.map((f) => f.waShareFreshPct)))}-${fmt(Math.max(...A.fresh.map((f) => f.waShareFreshPct)))}% of U.S. fresh-market apples in 2007-2025 and ${fmt(A.fresh2021to2025.minPct)}-${fmt(A.fresh2021to2025.maxPct)}% in 2021-2025.`, limitations: ['From 2018 the U.S. fresh total covers seven states.', 'Crop-year basis; ERS may use marketing years or a different set of years.'], executedAt: EXECUTED }, { id: 'forecast-2026', title: '2026 forecast share (total production)', question: "What share of the forecast 2026 U.S. apple crop is Washington's?", operation: 'ratio', parameters: { source: 'NASS Quick Stats 2026 annual production (August 2026 Crop Production forecast)', measure: 'total production' }, scope: '2026 crop, seven states.', resultShape: 'scalar', structuredResult: A.forecast2026, displayResult: `Forecast: Washington ${fmt(A.forecast2026.waTotalMlb)} of ${fmt(A.forecast2026.usTotalMlb)} million pounds (${fmt(A.forecast2026.waShareTotalPct)}%).`, limitations: ['A forecast of total production, not final utilized production; NASS revises it in later reports.', 'Total production includes fruit that may go unharvested or unsold, so the utilized share can differ.'], executedAt: EXECUTED }, ]; const replications = [ { id: 'ers-fresh-share-low', analysisId: 'fresh-market-share', externalSourceId: 'ers-fts-386', externalLocator: 'Page 3: "Over the previous 5 seasons, Washington\'s share of U.S. fresh-market apple production ranged from 71 to 80 percent" (lower bound)', externalValue: 71, facthubValue: A.fresh2021to2025.minPct, unit: 'percent', note: 'FactHub lower bound over crop years 2021-2025 from NASS fresh-market production. Close agreement.' }, { id: 'ers-fresh-share-high', analysisId: 'fresh-market-share', externalSourceId: 'ers-fts-386', externalLocator: 'Page 3, same sentence (upper bound)', externalValue: 80, facthubValue: A.fresh2021to2025.maxPct, unit: 'percent', note: `FactHub's highest crop-year share for 2021-2025 is ${fmt(A.fresh2021to2025.maxPct)}% (and ${fmt(Math.max(...A.fresh.map((f) => f.waShareFreshPct)))}% for 2007-2025). ERS does not say which years or which measure gives 80 percent; it may use marketing-year shipments or another fresh-use measure. FactHub did not reproduce the 80 percent figure.` }, ]; const content = { key: KEY, status: 'Final', title: "Washington's Share of U.S. Commercial Apple Production, 2000-2025", description: "USDA NASS commercial apple production, value and acreage by state, 2000-2025, with Census of Agriculture acreage and saved analyses of Washington's share of the U.S. crop.", selectionRationale: "Tests the common claim that Washington grows most of America's apples using NASS, the official U.S. source for crop estimates, over a long enough period (26 years) to show year-to-year swings and the effect of NASS's 2018 reduction to seven estimated states.", topics: ['Agriculture', 'Apples', 'Washington'], geography: ['Washington', 'United States'], temporalCoverage: '2000-2025 crop years (Census of Agriculture 2002-2022; 2026 forecast)', unitOfObservation: 'State-year', updateCadence: 'Annual, after the NASS Noncitrus Fruits and Nuts summary (May)', curator: 'FactHub Research Team', reproducibilityStatus: 'Fully reproducible', reproducibilityExplanation: 'fetch_sources.js downloads every raw file from NASS Quick Stats (web export) and USDA ESMIS; analyze.js and build_release.js rebuild every table and saved analysis with Node.js 20 and no packages. Quick Stats returns current values, so later NASS revisions can change 2007-2025 figures slightly.', limitations: [ 'Since 2018 NASS estimates apples in only seven states (CA, MI, NY, OR, PA, VA, WA) and its published U.S. total is their sum, so shares from 2018 are of a seven-state total. A sensitivity analysis estimates the effect at about 3 to 4 percentage points.', 'NASS estimates cover commercial orchards with 100 or more bearing trees; the Census of Agriculture table covers all farms.', 'Values for 2000-2006 come from the NASS annual summaries as revised in July 2003, 2006 and 2008; NASS may have revised them later, but Quick Stats does not carry state survey estimates before 2007.', 'Value of production is nominal and depends on NASS price estimates, which mix fresh and processing prices.', "Shares describe Washington's production relative to other states; they say nothing about consumption or exports.", 'The Wayback Machine could not capture the two Quick Stats CSV exports (repeated HTTP 520/523 errors on 2026-10-09). Their SHA-256 digests are recorded on the sources and in source-manifest.json, and fetch_sources.js re-creates the same exports; a re-download on 2026-10-09 returned identical bytes.', ], sources, artifacts, tables, events: [{ id: 'nass-seven-states', eventType: 'methodology', date: '2018-01-01', label: 'NASS estimates seven states', description: 'Quick Stats has utilized-production estimates for 20 states in 2017 and for 7 states from 2018; the published U.S. total from 2018 is the sum of those seven.', sourceIds: ['nass-quickstats-survey'] }], analyses, replications, changelog: [{ date: RETRIEVED, summary: 'Initial release: 2000-2025 state estimates, Census of Agriculture acreage 2002-2022, and saved analyses of Washington\'s share.' }], }; const request = { key: KEY, title: content.title, description: content.description, content, references: [] }; // Compact request: tables, sources, saved analyses and replications travel by reference to the public // dataset-metadata.json artifact, which create_dataset_draft expands inline (the stored draft is identical to // dataset-request-full.json). The same file lets readers download every saved-analysis result as JSON. fs.writeFileSync(path.join(rel, 'dataset-request-full.json'), JSON.stringify(request)); const metaBytes = Buffer.from(JSON.stringify({ sources, tables, analyses, replications }, null, 1) + '\n'); fs.writeFileSync(path.join(rel, 'dataset-metadata.json'), metaBytes); const metaArtifact = { id: 'dataset-metadata', role: 'dataDictionary', fileName: 'dataset-metadata.json', mediaType: 'application/json', byteLength: metaBytes.length, contentDigest: sha(metaBytes), description: 'Machine-readable sources, table and field definitions, saved analyses with their structured results, and replications for this release.', access: 'public' }; const compact = { ...request, content: { ...content, artifacts: [...content.artifacts, metaArtifact] } }; for (const k of ['sources', 'tables', 'analyses', 'replications']) compact.content[k] = { $artifact: 'dataset-metadata', pointer: '/' + k }; fs.writeFileSync(path.join(rel, 'dataset-request.json'), JSON.stringify(compact)); console.log('dataset-metadata', metaBytes.length, metaArtifact.contentDigest); console.log('artifacts', artifacts.map((a) => `${a.id} ${a.byteLength} ${a.contentDigest}`).join('\n')); console.log('request bytes', JSON.stringify(compact).length, 'archived sources', sources.filter((x) => x.archiveUrl).length, '/', sources.length);