Public
Edited
May 8, 2024
1 star
Insert cell
Insert cell
astronauts = [
'Neil Armstrong',
'Buzz Aldrin',
'Pete Conrad',
'Alan Bean',
'Alan Shepard',
'Edgar Mitchell',
'David Scott',
'James Irwin',
'John Young (astronaut)',
'Charles Duke',
'Eugene Cernan',
'Harrison Schmitt',
'Frank Borman',
'Jim Lovell',
'Bill Anders',
'Thomas P. Stafford',
'Michael Collins (astronaut)',
'Richard F. Gordon Jr.',
'Jack Swigert',
'Fred Haise',
'Stu Roosa',
'Al Worden',
'Ken Mattingly',
'Ron Evans'
]
Insert cell
Insert cell
groups = chunkBy(astronauts, 20)
Insert cell
Insert cell
docs = {
let opts = {'Api-User-Agent': 'wtf_wikipedia example'}
const doit = function(group){
return wtf.fetch(group, opts) //returns a promise
}
//only allow three requests at a time
return slow.three(groups, doit).then(responses=>{
//flatten the results
return [].concat.apply([], responses);
})
}
Insert cell
Insert cell
birthDays = {
return docs.map(doc => {
let birthday = null
// no infobox for Richard Gordon
if (doc.infobox() && doc.infobox().get('birth_date')) {
birthday = doc
.infobox()
.get('birth_date')
.text()
}
return {
name: doc.title(),
birthday: birthday
}
})
}
Insert cell
html`<table>${birthDays.map((o)=> '<tr><td><a href="https://en.wikipedia.org/wiki/'+o.name+'">'+o.name+'</a></td><td>'+o.birthday+'</td></tr>').join('\n')}
</table>`
Insert cell
Insert cell
cats = {
return docs.map((doc) => {
let categories = null;
if (doc.categories) {
categories = doc.categories();
}
return categories;
});
}
Insert cell
allcats = [].concat.apply([], cats)
Insert cell
aq.from(_.countBy(allcats)).orderby(aq.desc("value")).view()
Insert cell
aq.from(_.countBy(allcats)).orderby(aq.desc("value")).objects()
Insert cell
Insert cell
wtf = require('wtf_wikipedia')
Insert cell
slow = require("slow")
Insert cell
chunkBy = function(arr, chunkSize) {
var groups = [], i;
for (i = 0; i < arr.length; i += chunkSize) {
groups.push(arr.slice(i, i + chunkSize));
}
return groups;
}

Insert cell
wtf.version
Insert cell
import { aq, op } from "@uwdata/arquero"
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