Public
Edited
May 6, 2024
Importers
Insert cell
Insert cell
Insert cell
viewof table1 = Inputs.select(Object.keys(incidents),{label: "Table"})
Insert cell
navio(incidents, {height: 500, attribWidth: 16})
Insert cell
Insert cell
vl
.markCircle()
.encode(
vl.x().fieldQ("tsne.x"),
vl.y().fieldQ("tsne.y"),
vl.tooltip().fieldN("title")
)
.data(aaiprod.incidents)
.render()
Insert cell
vl
.markLine()
.encode(
vl.x().fieldT("date").timeUnit("year"),
vl.y().count(),
)
.data(aaiprod.incidents)
.render()
Insert cell
Insert cell
Insert cell
aaiprod.classifications
Insert cell
Insert cell
aaiprod.taxa
Insert cell
Insert cell
aaiprod.incidents
Insert cell
// Reading in AIID Data from MongoDB
aaiprod = {
const zFile = await FileAttachment("aiiprod.zip").zip();

return Object.fromEntries(
await Promise.all(
zFile.filenames.map(async (f) => [f.split(".")[1], await zFile.file(f).json()])
)
);
}
Insert cell
Insert cell
reports = {
const indexFile = await FileAttachment("index.json").json();

return indexFile
}
Insert cell
Insert cell
Insert cell
incident_id
Insert cell
{
//Checking if the reports of the same incident IDs have the same classification fields
const reportList = reports.filter(r => r["incident_id"] === +incident_id)
let x = {}
let dateSet = new Set();
let publishSet = new Set();
let locationSet = new Set();
let applicationSet = new Set();
let CSETv1Set = new Set();
let CSETv0Set = new Set();
reportList.forEach(r =>
{
publishSet.add(r["epoch_date_published"]);
dateSet.add(r["incident_date"]);
if (r["CSETv0"] !== undefined)locationSet.add(r["CSETv0"]["Location"]);
if (r["CSETv0"] !== undefined){
applicationSet.add(r["CSETv0"]["AI Applications"]);
CSETv0Set.add(r["CSETv0"])
};
if(r["CSETv1"] !== undefined) CSETv1Set.add(r["CSETv1"])
x.dateSet = [...dateSet]
x.publishSet = [...publishSet]
x.locationSet = [...locationSet]
x.applicationSet = [...applicationSet]
x.CSETv1Set = [...CSETv1Set]
x.CSETv0Set = [...CSETv0Set]
}
)
return x

}
Insert cell
Insert cell
mergedIncidents = {
// if there are multiple reports for one incident, we will pick the report with the earliestion date as the "date publicly known"
const getEarliestDate = (date1,date2) => {
if(!date1) return date2;
if(!date2) return date1;
return date1 < date2 ? date1: date2;
}

const getLocation = (CSETv0,CSETv1) => {
let location = {};
if(CSETv1 !== undefined){
location.country = CSETv1["Location Country (two letters)"] || CSETv1["Location Region"];
location.continent = CSETv1["Location Region"];
}
else if(CSETv0 !== undefined){
location.country = CSETv0["Location"];
location.continent = CSETv0["Location"];
}
return location
}

const getSector = (CSETv0,CSETv1) => {
if(CSETv1 !== undefined){
return CSETv1["Sector of Deployment"]
}
if(CSETv0 !== undefined){
return CSETv0["Sector of Deployment"]
}
}

const getAiGoal = (GMF,CSETv0) => {
let tech = {}
if(GMF !== undefined){
const goal = GMF["Known AI Goal"]
const technology = GMF["Known AI Technology"]
const potentialTechnology = GMF["Potential AI Technology"]
const failure = GMF["Known AI Technical Failure"]
tech.aiApplications = Array.isArray(goal)? goal.join(): goal;
tech.technology = Array.isArray(technology)? technology.join():technology;
tech.potentialTechnology = Array.isArray(potentialTechnology)? potentialTechnology.join():potentialTechnology;
tech.failure = Array.isArray(failure)?failure.join():failure;
}
// if the incident does not have GMF, check if it has CSETv0 which also has an AI Applications field
if(CSETv0 !== undefined){
const aiApplications = CSETv0["AI Applications"]
if (!("goal" in tech)){
tech.aiApplications = Array.isArray(aiApplications)?aiApplications.join():aiApplications
}
}
return tech;
}

const getInjuries = (CSETv1) => {
if(CSETv1!== undefined){
return CSETv1["Lives Lost"]+CSETv1["Injuries"]
}
}

const getHarmType = (CSETv0,CSETv1) => {
let harm = {}
if(CSETv0 !== undefined){
const harmType = CSETv0["Harm Type"]
harm.harmType = Array.isArray(harmType)? harmType.join():harmType
harm.severity = CSETv0["Severity"]
}
if(CSETv1!== undefined){
harm.livesLost = CSETv1["Lives Lost"]
harm.injuries = CSETv1["Injuries"]
}
return harm
}
let reportMap = new Map();
reports.forEach(report => {
const { incident_id,
epoch_date_published,
classifications,
CSETv0,
GMF,
CSETv1,
incident_date,
incident_title,
incident_description } = report;
const currentData = reportMap.get(incident_id);
const publicationDate = getEarliestDate(currentData?.datePublished, epoch_date_published);

reportMap.set(incident_id, {
"incident id": incident_id,
// classification: classifications,
// CSETv0: CSETv0,
// GMF: GMF,
// CSETv1: CSETv1,
"date": incident_date,
"country": getLocation(CSETv0,CSETv1).country,
"continent": getLocation(CSETv0,CSETv1).continent,
"area of application": getSector(CSETv0,CSETv1),
"date published": publicationDate,
"title": incident_title,
"description": incident_description,
"ai applications": getAiGoal(GMF,CSETv0).aiApplications,
"ai technology": getAiGoal(GMF,CSETv0).technology,
"potential ai technology": getAiGoal(GMF,CSETv0).potentialTechnology,
"ai failure": getAiGoal(GMF,CSETv0).failure,
"injuries": getInjuries(CSETv1),
});
});
return reportMap;
}
Insert cell
Insert cell
ids_2023 = {
const incidents_ = Array.from((mergedIncidents.values()))
const incidents_2023 = incidents_.filter(incident => {if(incident["date"]) return incident["date"].slice(0,4) === "2023" })
const ids_2023 = incidents_2023.map(i=>i["incident id"])
return ids_2023
}

Insert cell
Insert cell
Insert cell
incidents.filter(i=> +i["incident id"] === 452)
Insert cell
Insert cell
aggregatedIncidentsUrls = {
let aggregate = {};
reports.forEach(report => {
const id = report.incident_id;
if(!aggregate[id]){
aggregate[id] = [];
}
aggregate[id].push(report.url);
})

return aggregate
}
Insert cell
Insert cell
{
const newsURLJson = ()=>{
const jsonString = JSON.stringify(aggregatedIncidentsUrls);
const blob = new Blob([jsonString], { type: 'application/json' });

const link = document.createElement('a');
//create downloadable link
link.href = URL.createObjectURL(blob);
link.download = 'newsUrls.json';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}

document.getElementById('downloadButton').addEventListener('click', newsURLJson);

}
Insert cell
Insert cell
Insert cell
import {navio} from "@john-guerra/navio"
Insert cell
import {vl} from "@vega/vega-lite-api-v5"
Insert cell
import {Inputs} from '@observablehq/inputs'

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