mergedIncidents = {
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;
}