Jump to content

User:Habst/makeUsaNationalsTable.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
dab = {
  'Robert Hayes': 'Bob Hayes',
  'John Gilbert': 'John Glibert (sprinter)|',
  'Paul Drayton': 'Paul Drayton (athlete)|',
  'John Moon': 'John Moon (sprinter)|',
  'Patrick Clohessy': 'Pat Clohessy',
  'Jim Keefe': 'Jim Keefe (runner)|',
  'Julio Martin': 'Julio Martin (runner)|',
  'Peter McArdle': 'Pete McArdle',
  'John Macy': 'John Macy (runner)|',
  "Jim O'Connell": "Jim O'Connell (runner)|",
  'Jim Allen': 'Jim Allen (hurdler)|',
  'Gene Johnson': 'Gene Johnson (high jumper)|',
  'Ron Morris': 'Ron Morris (pole vaulter)|',
  'William Sharpe': 'Bill Sharpe (athlete)|',
  'David Davis': 'Dave Davis (athlete)|',
  'Bob Humphreys': 'Bob Humphreys (athlete)|',
  'Albert Hall': 'Albert Hall (athlete)|',
  'Ed Burke': 'Ed Burke (hammer thrower)|',
  'Larry Stuart': 'Larry Stuart (athlete)|',
  'David Edstrom': 'David Edstrom (decathlete)|',
  'Vivian Brown': 'Vivian Brown (athlete)|',
  'Diana Willson': 'Diana Willson (sprinter)|',
  'Carol Bush': 'Carol Bush (sprinter)|',
  'Chi Cheng': 'Chi Cheng (athlete)|',
  'Barbara Browne': 'Barbara Browne (pentathlete)|',
  'Harold Connolly': 'Hal Connolly',
  'Carol Smith': 'Carol Smith (sprinter)|',
  'Charles Frazier': 'Charley Frazier',
  'Robert Gardner': 'Robert Gardner (high jumper)|',
  'Henry Wadsworth': 'Henry Wadsworth (pole vaulter)|',
  'Paul Herman': 'Paul Herman (decathlete)|',
  'William Alley': 'William Alley (athlete)|',
  'Mary Rose': 'Mary Rose (hurdler)|',
  'William Woodhouse': 'William Woodhouse (sprinter)|',
  'Dave Mills': 'Dave Mills (sprinter)|',
  'Thomas Murphy': 'Tom Murphy (runner)|',
  'John Thomas': 'John Thomas (athlete)|',
  'John Cramer': 'John Cramer (pole vaulter)|',
  'Lucinda Williams': 'Lucinda Williams (athlete)|',
  'James Green': 'James Green (runner)|',
  'Jim Graham': 'Jim Graham (pole vaulter)|',
  'Willie White': 'Willie White (sprinter)|',
  'Charles Jenkins': 'Charles Jenkins Sr.',
  'George Dennis': 'George Dennis (high jumper)|',
  'Bill Jackson': 'Bill Jackson (long jumper)|',
  'Alejandra Herrera': 'Alejandra Herrera (discus thrower)|',
  'Betty Scott': 'Betty Scott (pentathlete)|',
  'Robert Richards': 'Bob Richards',
  'George Brown': 'George Brown (long jumper)|',
  'Ron Drummond': 'Ron Drummond (discus thrower)|',
  'Elaine Ellis': 'Elaine Ellis (sprinter)|',
  'Phyllis Logan': 'Phyllis Logan (long jumper)|',
  'Dean Smith': 'Dean Smith (sprinter)|',
  'Bob Seaman': 'Bob Seaman (runner)|',
  'Bob Hunt': 'Bob Hunt (runner)|',
  'George King': 'George King (runner)|',
  'Charles Pratt': 'Charles Pratt (hurdler)|',
  'James Luttrell': 'James Luttrell (hurdler)|',
  'Robert Smith': 'Bobby Smith (pole vaulter)|',
  'Victor Hernandez': 'Victor Hernandez (triple jumper)|',
  'Robert Lawson': 'Robert Lawson (decathlete)|',
  'Leonard Simpson': 'Leonard Simpson (runner)|',
  'Curtis Stone': 'Curt Stone',
  'Willard Wright': 'Willard Wright (hurdler)|',
  'Roy Thompson': 'Roy Thompson (hurdler)|',
  'Aubrey Lewis': 'Aubrey Lewis (athlete)|',
  'Barbara Lee': 'Barbara Lee (sprinter)|',
  
  'Javier Montes': 'Javier Montes (runner)|',
  'Thomas Jones': 'Thomas Jones (runner)|',
  'Charley Moore': 'Charley Moore (hurdler)|',
  'Robert Allison': 'Robert Allison (javelin thrower)|',
  'Milton Campbell': 'Milt Campbell',
  'Cynthia Robinson': 'Cynthia Robinson (sprinter)|',
  'Jean Simmons': 'Jean Simmons (long jumper)|',
  'Robert Work': 'Robert Work (sprinter)|',
  'James Ford': 'James Ford (sprinter)|',
  'John Lafferty': 'John Lafferty (runner)|',
  'Robert Kelly': 'Robert Kelly (runner)|',
  'Eric Roberts': 'Eric Roberts (high jumper)|',
  'Charles Hanger': 'Charles Hanger (high jumper)|',

  'Elmore Harris': 'Elmore Harris (sprinter)|',
  'Peter Watkins': 'Peter Watkins (high jumper)|',
  'Pat Turner': 'Pat Turner (long jumper)|',
  'James Herbert': 'Jim Herbert (runner)|',
  'David Smith': 'David Smith (runner)|',
  'Thomas Quinn': 'Tom Quinn (runner)|',
  'Jack Morris': 'Jack Morris (hurdler)|',
  'James Wisner': 'James Wisner (runner)|',
  'William Berger': 'William Berger (runner)|',
  'Joshua Williamson': 'Joshua Williamson (high jumper)|',
  'Robert Phelps': 'Robert Phelps (pole vaulter)|',
  'John Schmidt': 'John Schmidt (pole vaulter)|',
  'Charles Barnes': 'Charles Barnes (triple jumper)|',
  'Jack Donaldson': 'John Donaldson (discus thrower)|',
  'Edward Thompson': 'Edward Thompson (javelin thrower)|',
  'Jean Lowe': 'Jean Lowe (sprinter)|',
  'Helen Steward': 'Helen Steward (shot putter)|',
  'Peggy Anderson': 'Peggy Anderson (javelin thrower)|',
  'Claude Young': 'Claude Young (sprinter)|',
  'Charles Parker': 'Charles Parker (sprinter)|',
  'Donald Campbell': 'Donald Campbell (athlete)|',
  'James McGuire': 'James McGuire (sprinter)|',
  'William Marr': 'William Marr (runner)|',
  'Thomas Crane': 'Thomas Crane (runner)|',
  'Owen Cassidy': 'Owen Cassidy (hurdler)|',
  'Willard Smith': 'Willard Smith (high jumper)|',
  'Del Smith': 'Del Smith (pole vaulter)|',
  'Raul Lopez': 'Raul Lopez (triple jumper)|',
  'William Watson': 'William Watson (decathlete)|',
  'David Schrader': 'David Schrader (discus thrower)|',
  'Wilbur Ross': 'Wilbur Ross (decathlete)|',
  'Nathaniel Boyd': 'Nathaniel Boyd (decathlete)|',
  'Cleo Davis': 'Cleo Davis (shot putter)|',
  'Betty Weaver': 'Betty Weaver (discus thrower)|',
  'Francis Cotter': 'Francis Cotter (sprinter)|',
  'Louis Gregory': 'Lou Gregory',
  'John Saunders': 'John Saunders (hurdler)|',
  'Bruce Miller': 'Bruce Miller (hurdler)|',
  'Ray Phillips': 'Ray Phillips (runner)|',
  'Ralph Dewey': 'Ralph Dewey (runner)|',
  'Irving Moore': 'Irving Moore (pole vaulter)|',
  'Billy Christopher': 'William Christopher (long jumper)|',
  'Clarence Lewis': 'Clarence Lewis (triple jumper)|',
  'George Huber': 'George Huber (hammer thrower)|',
  'Seymour Cohen': 'Steve Seymour',
  'Joan Davis': 'Joan Davis (hurdler)|',
  'Bernice Robinson': 'Bernice Robinson (athlete)|',
  'Irving Folsworthy': 'Irving Folwartshny',
  'Charles Shaw': 'Charles Shaw (sprinter)|',
  'Bob Wright': 'Robert Wright (hurdler)|',
  'Walter Smith': 'Walter Smith (hurdler)|',
  'Adam Berry': 'Adam Berry (high jumper)|',
  'Thomas Montgomery': 'Thomas Montgomery (shot putter)|',
  'Boyd Brown': 'Boyd Brown (javelin thrower)|',
  'Herbert Matter': 'Herbert Matter (decathlete)|',
  'Robert Wright': 'Robert Wright (hurdler)|',
  'Mamie Taylor': 'Mamie Taylor (sprinter)|',
  'Clarence Barnes': 'Clarence Barnes (runner)|',
  'Harry March': 'Harry March (hurdler)|',
  'Donald Munson': 'Donald Munson (runner)|',
  'William Daly': 'William Daly (runner)|',
  'Herbert Michael': 'Herbert Michael (shot putter)|',
  'Lucy Newell': 'Lucy Newell (sprinter)|',
  'Esther Brown': 'Esther Brown (sprinter)|',
  'Paul Moore': 'Paul Moore (runner)|',
  'Edward Dugger': 'Edward Dugger (hurdler)|',
  'Stanley Anderson': 'Uell Standley Andersen',
  'Chester Cruickshank': 'Chester Cruikshank',
  'Joe Scott': 'Joe Scott (basketball player)|',
  'Sybil Cooper': 'Sybil Cooper (hurdler)|',
  'Mary Haydon': 'Mary Haydon (high jumper)|',
  'Barbara Howe': 'Barbara Howe (high jumper)|',
  'Gertrude Johnson': 'Gertrude Johnson (sprinter)|',
  'Edward Gordon': 'Ed Gordon (athlete)|',
  'Francis Ryan': 'Francis Ryan (shot putter)|',
  'Walter Stone': 'Walter Stone (runner)|',
  'John Brooks': 'John Brooks (athlete)|',
  'Kenneth Carpenter': 'Ken Carpenter (discus thrower)|',

  'John Wolff': 'John Wolff (runner)|',
  'William Zepp': 'William Zepp (runner)|',
  'Thomas McDonough': 'Thomas McDonough (runner)|',
  'Melvin Porter': 'Melvin Porter (runner)|',
  'William Roy': 'William Roy (pole vaulter)|',
  'Jack Torrance': 'Jack Torrance (athlete)|',
  'George Mackey': 'George Mackey (decathlete)|',
  'Elton Brown': 'Elton Brown (runner)|',
  'Joseph Mangan': 'Joseph Mangan (runner)|',
  'William Steiner': 'William Steiner (runner)|',
  'Phillip Good': 'Philip Good',
  'John Mottram': 'John Mottram (javelin thrower)|',
  'Paul Starr': 'Paul Starr (sprinter)|',
  'John Anderson': 'John Anderson (discus thrower)|',
  'Alice Arden': 'Alice Arden (athlete)|',

  'Cyrus Leland': 'Cyrus Leland (sprinter)|',
  'Victor Williams': 'Victor Williams (sprinter)|',
  'William Agee': 'William Agee (athlete)|',
  'James Hatfield': 'James Hatfield (hurdler)|',
  'Victor Burke': 'Victor Burke (hurdler)|',
  'George Jefferson': 'George Jefferson (athlete)|',
  'Alfred Bates': 'Al Bates',
  'George Martin': 'George Martin (long jumper)|',
  'Ed Moeller': 'Ed Moeller (discus thrower)|',
  'Harry Schneider': 'Harry Schneider (discus thrower)|',
  'Robert Maxwell': 'Robert Maxwell (hurdler)|',
  'Johnny Lewis': 'John Lewis (sprinter)|',
  'Rupert Beetham': 'Rupert Beetham (runner)|',
  "Jack O'Reilly": "Jack O'Reilly (runner)|",
  'Jack Lamb': 'Jack Lamb (runner)|',
  'Henry Coggeshall': 'Henry Coggeshall (high jumper)|',
  'Robert Patton': 'Robert Patton (triple jumper)|',
  'James Stewart': 'James Stewart (decathlete)|',
  'Elizabeth Robinson': 'Betty Robinson',
  'Tom Warne': 'Tom Warne (pole vaulter)|',
  'Tom Sharkey': 'Tom Sharkey (sprinter)|',

  'Charles Werner': 'Charles Werner (hurdler)|',
  'Charles Harlow': 'Charles Harlow (javelin thrower)|',
  'Margaret Jenkins': 'Margaret Jenkins (athlete)|',
  'Albert Michelson': 'Albert Michelson (runner)|',
  'Charles Werner': 'Charles Werner (hurdler)|',
  'George Meyers': 'George Meyers (hurdler)|',
  'Charles Harlow': 'Charles Harlow (athlete)|',
  'Mabel Holmes': 'Mabel Holmes (athlete)|',
  'Cecil Cooke': 'Cecil Cooke (sprinter)|',
  'Ray Robertson': 'Ray Robertson (athlete)|',
  'Joseph Tierney': 'Joe Tierney',
  'Arthur Hoffman': 'Arthur Hoffman (discus thrower)|',
  'John Leyden': 'John Leyden (javelin thrower)|',
  'Harrison Thompson': 'Harrison Thompson (hurdler)|',
  'Richard Oram': 'Richard Oram (hurdler)|',
  'Ray Robertson': 'Ray Robertson (athlete)|',

  'Karl Anderson': 'Karl Anderson (hurdler)|',
  'Charles Eastman': 'Charles Eastman (shot putter)|',
  'James Driscoll': 'Jim Driscoll (sprinter)|',
  'James Connolly': 'James Connolly (disambiguation)|',
  'Frank Titterton': 'Frank Titterton (runner)|',
  'Roy Evans': 'Roy Evans (discus thrower)|',
  'Frank Gillespie': 'Frank Gillespie (runner)|',
  'Carl Rice': 'Carl Rice (high jumper)|',
  'Carl Buck': 'Carl Buck (pole vaulter)|',
  'David Politzer': 'David Politzer (long jumper)|',
  'Clinton Larsen': 'Clinton Larsen (high jumper)|',
  'Joseph Irish': 'Joseph Irish (long jumper)|',
  'Alfred Booth': 'Alfred Booth (sprinter)|',
  'Robert Nourse': 'Robert Nourse (javelin thrower)|',
  'Fred Murray': 'Feg Murray',
};
year = 1915;
evtdab = {
  'Pentathlon': 'Women\'s pentathlon',
  '2 miles sc': '2 miles steeplechase',
  '8lb shot put': '[[Shot put]] (8 lb)',
  '200 m straight track': '200 m straight',
  '220 yards straight track': '220 yards straight',
  '10000 m': '10,000 m',
};
await (async () => {
const trialsMode = false;

window.doc ??= {};
window.doc[year] ??= {};
window.ap ??= {};
window.ap[year] ??= trialsMode ? { data: [[],[],[]] } : await (await fetch(`https://api.athleticspodium.com/1.0/meetings/${(await (await fetch(`https://api.athleticspodium.com/1.0/meetings/${year}-usa-track-and-field-championships`)).json()).data.id}/medals`)).json();

const prefix = trialsMode ? '/OlympicTrials.asp?TourCode=T' : '/USATournaments.asp?TourCode=N';

const evts = { M: [], W: [] };
for (const code of ['MT', 'MF', /*'WT', 'WF'*/]) {
  window.doc[year][code] ??= new DOMParser().parseFromString(await (await fetch(prefix + `&Year=${year}&Gender=${code[0]}&TF=${code[1]}&By=Y&Count=&P=F`)).text(), 'text/html');
for (const tbl of [...doc[year][code].querySelector('table.result').querySelectorAll('table')]) {
  let wt = '';
  const [title, ...trs] = tbl.querySelectorAll('tr');
  let evtName = title.innerText.trim()[0] + title.innerText.trim().replaceAll(' y', ' yards').replaceAll(' ft', ' feet').split(' (')[0].slice(1).toLowerCase();
  evtName = evtdab[evtName] ?? evtName;
  const evtLink = evtName.includes('[[') ? evtName : `[[${evtName}]]`;
  const rowspan = Math.max(...['1', '2', '3'].map(n => trs.filter(tr => tr.querySelector('td').innerText === n).length));
  const finishers = [...Array(3)].fill(`|rowspan=${rowspan} colspan=2| ''none awarded''`);
  const hasTie = rowspan > 1;
  wt += rowspan > 1 ? `|rowspan=${rowspan}| ${evtLink}\n` : `| ${evtLink}\n`;
  const wtSuffixes = [];
  for (const tr of trs) {
    const [pl, brinksterName, ctry, brinkMark, notes] = [...tr.querySelectorAll('td')].map(td => td.innerText.trim());
    if (!['1', '2', '3'].includes(pl)) continue;
    const ties = trs.filter(tr => tr.querySelector('td').innerText === pl);
    const tieIdx = ties.indexOf(tr);
    const isTie = ties.length > 1;
    const isLastInTie = isTie && tieIdx === ties.length - 1;
    const rowSpanForLastTie = `rowspan=${rowspan - ties.length + 1}|`;
    const name = dab[brinksterName] ?? brinksterName;
    const nameLink = ctry === 'USA' ? `[[${name}]]` : `{{flai|[[${name}]]|${ctry}}}`;
    const isBronzeTie = pl === '3' && isTie;
    const goldTies = trs.filter(tr => tr.querySelector('td').innerText === '1');
    if (isTie && tieIdx >= 1) {
      if (isBronzeTie && goldTies.length > 1 && tieIdx < goldTies.length) {
        wtSuffixes[tieIdx - 1] += ` || ${nameLink}`;
      } else wtSuffixes.push(`\n|-\n|${isLastInTie ? rowSpanForLastTie : ''} ${nameLink}`);
      continue;
    }
    let mark = brinkMark.replaceAll(' =', '').replaceAll('w', ' {{AthAbbr|w}}').replaceAll('yd', 'yard').replace(/^1 ft/, '1 foot').replaceAll(' ft', ' feet').replaceAll('bh2', 'behind 2nd').replaceAll('bh', 'behind').replace(/e$/, ' {{AthAbbr|e}}');
    if (code[1] === 'F' && mark.trim()) mark += evtName.includes('athlon') ? ' pts' : ' m';
    while (mark.split('.').length >= 3) mark = mark.replace('.', ':');
    if (mark.includes('behind')) mark = `''${mark}''`;
    finishers[pl - 1] = hasTie ? isTie ? `| ${nameLink} ||rowspan=${rowspan}| ${mark}` : `|rowspan=${rowspan}| ${nameLink} ||rowspan=${rowspan}| ${mark}` : `| ${nameLink} || ${mark}`;
  }
  evts[code[0]].push(wt + finishers.slice(0, 3).join('\n') + wtSuffixes.join(''));
}
}
const walkName = ap[year].data[0].find(e => e.name.endsWith('W'))?.name;
const lowHurdlesName = ap[year].data[0].find(e => ['200H', '220yrd H'].includes(e.name))?.name;
for (const name of [lowHurdlesName, walkName, 'Pentathlon', '56pound weight throw']) {
  const dispName = {Pentathlon: 'Olympic athletics pentathlon|Pentathlon', '56pound weight throw': 'Weight throw for distance', '220yrd H': '220 yards hurdles', '200H': '200 m hurdles', '3000mW': '3000 m walk', '80y h/r': '80 yards hurdles'}[name] ?? name;
  const unit = name?.includes('athlon') ? ' pts' : name?.includes('throw') ? ' m' : '';
  const podium = ap[year].data[0].find(e => e.name === name)?.medals;
  if (!podium) { console.log('no', name); continue; }
  let txt = `| [[${dispName}]]<ref name=ap />`;
  while (podium.length < 3) podium.push({ athlete_name: '', mark_display: '' });
  for (const pod of podium) {
    const apName = pod.athlete_name?.split(' (')[0] || `${pod.athlete?.first_name ?? ''} ${pod.athlete?.last_name ?? ''}`.trim();
    const athName = apName ? `[[${dab[apName] ?? apName}]]` : '';
    txt += `\n| ${athName} || ${pod.mark_display}${athName ? unit : ''}`;
  }
  evts.M.push(txt);
}
evts.M.push(`| [[Pole vault for distance]]<ref name=usatf />\n| [[]] ||  {{tf2|0|0}} \n|  || \n|  || `);
evts.M.push(`| [[All-around decathlon]]<ref name=usatf />\n| [[]] ||  pts\n|  || \n|  || `);
evts.W.push(`| [[Baseball throw]]<ref name=usatf />\n| [[]] || {{tf2|0|0}} \n|  || \n|  || `);
console.log(evts.M.join('\n|-\n'))
console.log(evts.W.join('\n|-\n'))

return [evts.M.join('\n|-\n'), evts.W.join('\n|-\n')];
})();