Public
Edited
Dec 16, 2022
Insert cell
Insert cell
labels@3.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell

a={
const pagesGrouped=d3.group(labels,d=>d.name)
// iterate
const allLabels=[]
const allLabelsPages=[]
const newArray= []
for (let [key, value] of pagesGrouped) {
const newLabels=[]
for(const image of value){
for( let i=1; i<7; i++){
// check if current label is not already on the page, and if current label is not empty
if(image['label_'+i]!=null && !newLabels.some(d=>d.l===image['label_'+i])) {
newLabels.push({'l':image['label_'+i], c:image['confidence'+i]})
allLabels.push(image['label_'+i])
allLabelsPages.push({label:image['label_'+i], page:key})
}
}
}
if(newLabels.length>0) {
newArray.push({
page: key,
labels:newLabels
})
}
}
const pagesByLabel=d3.rollup(allLabelsPages,v=>v.map(item=>item.page), d=>d.label)
return {labelsByPage:newArray,allLabels, pagesByLabel}
}
Insert cell
Insert cell
d3.rollups(a.pagesByLabel.get('Person'),v=>v.length,d=>d).sort((a,b)=> d3.descending(a[1],b[1])) //no hace falta esto porqeu ya sale siempre 1 en pagesByLabel
Insert cell
o=Object.fromEntries(a.pagesByLabel);
Insert cell
allowed = ["Person","chart","car","Man","Art","Painting","Factory","Vehicle","Transportation","Building","Person","Architecture","Nature","Book","Airplane","Furniture","Ship","Plant","Diagram","Drawing","Military","Indoors","City"];
Insert cell
{
return Object.keys(o)
.filter(key => allowed.includes(key))
.reduce((obj, key) => {
obj[key] = o[key];
return obj;
}, {});
}
Insert cell
Insert cell
labelsCounting = d3.rollups(a.allLabels, v=>v.length, d=>d).sort((a,b)=> d3.descending(a[1],b[1]))
Insert cell
labelsCounting
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
labelsCounting.filter(d=> allowed.includes(d[0]))
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