Public
Edited
Aug 23, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
race_labels = get_labels(
["Q1542952", "Q33881", "Q33861", "Q33937", "Q487654", "Q755125"],
lang
).then((d) => d.objects())
Insert cell
winner_labels = get_labels(
[
"Q20882747",
"Q20882763",
"Q20883140",
"Q21686770",
"Q20883008",
"Q20883213"
],
lang
).then((d) => d.objects())
Insert cell
race_map = new Map(
race_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
winner_map = new Map(
winner_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
query = `SELECT ?tour ?tourLabel ?startdate ?tournumber ?item ?itemLabel ?stagenumber ?winner ?winnerLabel ?country ?countryLabel WHERE {
?tour wdt:P31 wd:${tour};
rdfs:label ?tourLabel.
FILTER((LANG(?tourLabel)) = "en")
?item wdt:P361 ?tour;
rdfs:label ?itemLabel.
FILTER((LANG(?itemLabel)) = "en")
?tour wdt:P580 ?startdate.
?tour wdt:P393 ?tournumber.
?item wdt:P1545 ?stagenumber.
?item p:P1346 ?statement.
?statement ps:P1346 ?winner.
?statement pq:P642 wd:${winner} .
?winner rdfs:label ?winnerLabel.
FILTER((LANG(?winnerLabel)) = "en" )
?winner wdt:P27 ?country.
?country rdfs:label ?countryLabel.
FILTER((LANG(?countryLabel)) = "${lang}" )
}
`
Insert cell
data = fetch(`https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`, {headers: {accept: "application/sparql-results+json"}}).then(response => response.json())
Insert cell
df = aq
.from(
data.results.bindings.map((d) => ({
item: d.item.value,
itemLabel: d.itemLabel.value,
tour: d.tour.value,
tourLabel: d.tourLabel.value,
country: d.country.value,
countryLabel: d.countryLabel.value,
tournumber: parseInt(d.tournumber.value),
stagenumber: parseInt(d.stagenumber.value),
startdate: d.startdate.value,
winnerLabel: d.winnerLabel.value
}))
)
.derive({
year: (d) => op.year(d.startdate)
})
.derive({ decade: (d) => op.floor(d.year / 10) * 10 })
.dedupe([
"itemLabel",
"tourLabel",
"winnerLabel",
"countryLabel",
"tournumber",
"stagenumber"
])
Insert cell
df.array("countryLabel")
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
lang: "en",
race: "Q1542952",
winner: "Q20882747"
};
if (params.has("race")) {
defaults.race = params.get("race");
}
if (params.has("lang")) {
defaults.lang = params.get("lang");
}
if (params.has("winner")) {
defaults.winner = params.get("winner");
}
return defaults;
}
Insert cell
Insert cell
Insert cell
Insert cell
import { get_labels } from "@pac02/what-kind-of-articles-have-you-created"
Insert cell
https://w.wiki/9bXs
Insert cell
races = FileAttachment("query(1).json").json()
Insert cell
r_map = races.map((d) => ({
id: d.item.replace("http://www.wikidata.org/entity/", ""),
race: d.itemLabel
}))
Insert cell
r_map2 = new Map(r_map.map(({ race, id }) => [race + " (" + id + ")", id]))
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more