Talk:2023 Indoor Meeting Karlsruhe

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Script to match names to results[edit]

I used this script to match names to the results using IAAF IDs (note the API key is public info):

data=await (await fetch("https://wpgiegzkbrhj5mlsdxnipboepm.appsync-api.eu-west-1.amazonaws.com/graphql", {
  "headers": {
    "x-api-key": "da2-juounigq4vhkvg5ac47mezxqge"
  },
  "body": JSON.stringify({
  "operationName": "getCalendarCompetitionResults",
  "variables": {
    "competitionId": 7162587,
    "day": null,
    "eventId": null
  },
  "query": `query getCalendarCompetitionResults($competitionId: Int, $day: Int, $eventId: Int) {
  getCalendarCompetitionResults(competitionId: $competitionId, day: $day, eventId: $eventId) {
    competition {
      dateRange
      endDate
      name
      rankingCategory
      startDate
      venue
      __typename
    }
    eventTitles {
      rankingCategory
      eventTitle
      events {
        event
        eventId
        gender
        isRelay
        perResultWind
        withWind
        summary {
          competitor {
            teamMembers {
              id
              name
              iaafId
              urlSlug
              __typename
            }
            id
            name
            iaafId
            urlSlug
            birthDate
            __typename
          }
          mark
          nationality
          placeInRace
          placeInRound
          points
          raceNumber
          records
          wind
          __typename
        }
        races {
          date
          day
          race
          raceId
          raceNumber
          results {
            competitor {
              teamMembers {
                id
                name
                iaafId
                urlSlug
                __typename
              }
              id
              name
              iaafId
              urlSlug
              birthDate
              hasProfile
              __typename
            }
            mark
            nationality
            place
            points
            qualified
            records
            wind
            remark
            details {
              event
              eventId
              raceNumber
              mark
              wind
              placeInRound
              placeInRace
              points
              overallPoints
              placeInRoundByPoints
              overallPlaceByPoints
              __typename
            }
            __typename
          }
          startList {
            competitor {
              birthDate
              country
              id
              name
              urlSlug
              __typename
            }
            order
            pb
            sb
            bib
            __typename
          }
          wind
          __typename
        }
        __typename
      }
      __typename
    }
    options {
      days {
        date
        day
        __typename
      }
      events {
        gender
        id
        name
        combined
        __typename
      }
      __typename
    }
    parameters {
      competitionId
      day
      eventId
      __typename
    }
    __typename
  }
}`
}),
  "method": "POST",
})).json();
pre='';
cache??={};
if (typeof nameFixer === 'undefined') {
  const script = Object.assign(document.createElement('script'), { src: 'https://unpkg.com/name-fixer@1.0.0' });
  document.body.appendChild(script);
  await new Promise(res => script.addEventListener('load', res));
}
titleExists=async (name)=>{
  const enLabelTitleMatch = await (await fetch(pre+'https://www.wikidata.org/w/api.php?' + new URLSearchParams({
    action: 'wbgetentities',
    format: 'json',
    sites: 'enwiki',
    titles: name,
  }))).json();
  return !enLabelTitleMatch.entities[-1];
}
getTitle=async (id,name)=>{
  const [fname, ...lname] = name.split(' ');
  name = fname + ' ' + nameFixer.nameFixer(lname.join(' '));
  if (cache[id]) return cache[id];
  const pages = await (await fetch(pre+'https://www.wikidata.org/w/api.php?' + new URLSearchParams({
    action: 'query',
    format: 'json',
    list: 'search',
    srsearch: `haswbstatement:P1146=${id}`,
  }))).json();
  const qid = pages.query.search[0]?.title;
  if (qid) {
    const entity = await (await fetch(pre+'https://www.wikidata.org/w/api.php?' + new URLSearchParams({
      action: 'wbgetentities',
      format: 'json',
      ids: qid,
    }))).json();
    const sitelinks = entity.entities[qid].sitelinks;
    const enTitle = sitelinks.enwiki?.title;
    if (enTitle) {
      cache[id] = `[[${enTitle}${enTitle.includes('(') ? '|' : ''}]]`;
      return cache[id];
    }
    let enLabel = entity.entities[qid].labels.en?.value ?? name;
    if (await titleExists(enLabel)) enLabel += ' (athlete)'; // todo awb job?
    const otherWiki = Object.keys(sitelinks).find(key => key.endsWith('wiki'));
    if (otherWiki) {
      const otherTitle = sitelinks[otherWiki].title;
      cache[id] = `{{ill|${enLabel}|${otherWiki.replace('wiki', '')}|${otherTitle}}}`;
      return cache[id];
    }
    cache[id] = `[[${enLabel}${enLabel.includes('(') ? '|' : ''}]]`;
    return cache[id];
  }
  if (await titleExists(name)) name += ' (athlete)|';
  cache[id] = `[[${name}]]`;
  return cache[id];
}
mark2secs=mark=>{
  const parts = mark.split(':');
  if (parts.length === 1) return +mark;
  if (parts.length === 2) return +parts[0] * 60 + +parts[1];
  return +parts[0] * 60 * 60 + +parts[1] * 60 + +parts[2];
}
let out = '';
for (const evt of data.data.getCalendarCompetitionResults.eventTitles.find(et => et.eventTitle === 'World Athletics Indoor Tour').events) {
  const finals = evt.races.filter(race => race.race === 'Final');
  const isMulti = finals.length > 1;
  out += `===${evt.event.replace(' indoor', '')}===\n`;
  out += `{| class="wikitable"\n! Place !! Athlete !! Time ${isMulti ? '!! Heat ' : ''}!! Points\n`;
  const results = finals.flatMap(race => race.results.map(res => ({...res, raceNumber: race.raceNumber}))).sort((a, b) => mark2secs(a.mark) - mark2secs(b.mark));
  for (const result of results) {
    const pl = ['DNS', 'DNF'].includes(result.mark) ? '' : results.indexOf(result) + 1;
    const name = result.competitor.name;
    const id = result.competitor.urlSlug.split('-').at(-1).replace(/^0/, '');
    out += `|-\n| ${pl} || ${await getTitle(id, name)} || ${result.mark} ||${isMulti ? ` ${result.raceNumber} ||` : ''} ${{1: 10, 2: 7, 3: 5, 4: 3}[pl] ?? ''}\n`;
  }
  out += '|}\n\n';
}
return out;

Habst (talk) 04:40, 11 November 2023 (UTC)[reply]