Public
Edited
Nov 29, 2022
Insert cell
Insert cell
Insert cell
test = []
Insert cell
test.push(rawdata[0], rawdata[1], rawdata[2])
Insert cell
raw = getOutcomes(rawdata)
Insert cell
test_2 = getPaths_all(raw)
Insert cell
function getPaths_all (array) {
let pathsAll = {}

pathsAll.path_AR = getPath_AR(array)
pathsAll.path_EO = getPath_EO(array)
pathsAll.path_IN = getPath_IN(array)

return pathsAll
}
Insert cell
path_AR = getPath_AR(raw)
Insert cell
function getPath_AR (array) {
let outcomes = {}
let totalOutcomesByStage = d3.rollup(array, v=> d3.sum(v, d => d.value), d => d.stage, d => d.outcome)

let outcomes_rec = {}

outcomes_rec.stage_AR = totalOutcomesByStage.get("AR").get("recognized")
outcomes_rec.stage_EO = +0
outcomes_rec.stage_IN = +0

let outcomes_pro = {}

outcomes_pro.stage_AR = totalOutcomesByStage.get("AR").get("protected")
outcomes_pro.stage_EO = +0
outcomes_pro.stage_IN = +0

let outcomes_rej = {}

outcomes_rej.stage_AR = totalOutcomesByStage.get("AR").get("rejected")
outcomes_rej.stage_EO = +0
outcomes_rej.stage_IN = +0

let outcomes_clo = {}

outcomes_clo.stage_AR = totalOutcomesByStage.get("AR").get("closed")
outcomes_clo.stage_EO = +0
outcomes_clo.stage_IN = +0

// add to object path_AR
outcomes.outcomes_pro = outcomes_pro
outcomes.outcomes_rec = outcomes_rec
outcomes.outcomes_rej = outcomes_rej
outcomes.outcomes_clo = outcomes_clo

return outcomes
}
Insert cell
path_EO = getPath_EO(raw)
Insert cell
function getPath_EO (array) {
let outcomes = {}
let totalOutcomesByStage = d3.rollup(array, v=> d3.sum(v, d => d.value), d => d.stage, d => d.outcome)

let outcomes_rec = {}

outcomes_rec.stage_AR = +0
outcomes_rec.stage_EO = totalOutcomesByStage.get("EO").get("recognized")
outcomes_rec.stage_IN = +0

let outcomes_pro = {}

outcomes_pro.stage_AR = +0
outcomes_pro.stage_EO = totalOutcomesByStage.get("EO").get("protected")
outcomes_pro.stage_IN = +0

let outcomes_rej = {}

outcomes_rej.stage_AR = +0
outcomes_rej.stage_EO = totalOutcomesByStage.get("EO").get("rejected")
outcomes_rej.stage_IN = +0

let outcomes_clo = {}

outcomes_clo.stage_AR = +0
outcomes_clo.stage_EO = totalOutcomesByStage.get("EO").get("closed")
outcomes_clo.stage_IN = +0

// add to object path_AR
outcomes.outcomes_pro = outcomes_pro
outcomes.outcomes_rec = outcomes_rec
outcomes.outcomes_rej = outcomes_rej
outcomes.outcomes_clo = outcomes_clo

return outcomes
}
Insert cell
path_IN = getPath_IN(raw)
Insert cell
function getPath_IN (array) {
let outcomes = {}
let totalOutcomesByStage = d3.rollup(array, v=> d3.sum(v, d => d.value), d => d.stage, d => d.outcome)

let outcomes_rec = {}

outcomes_rec.stage_AR = +0
outcomes_rec.stage_EO = +0
outcomes_rec.stage_IN = totalOutcomesByStage.get("IN").get("recognized")

let outcomes_pro = {}

outcomes_pro.stage_AR = +0
outcomes_pro.stage_EO = +0
outcomes_pro.stage_IN = totalOutcomesByStage.get("IN").get("protected")

let outcomes_rej = {}

outcomes_rej.stage_AR = +0
outcomes_rej.stage_EO = +0
outcomes_rej.stage_IN = totalOutcomesByStage.get("IN").get("rejected")

let outcomes_clo = {}

outcomes_clo.stage_AR = +0
outcomes_clo.stage_EO = +0
outcomes_clo.stage_IN = totalOutcomesByStage.get("IN").get("closed")

// add to object path_AR
outcomes.outcomes_pro = outcomes_pro
outcomes.outcomes_rec = outcomes_rec
outcomes.outcomes_rej = outcomes_rej
outcomes.outcomes_clo = outcomes_clo

return outcomes
}
Insert cell
asylumByOutcome = d3.group(raw, d => d.outcome)
Insert cell
asylumByCountryOutcome = d3.group(raw, d => d.originCountry, d=> d.stage, d => d.outcome)
Insert cell
asylumByCountryOutcome.get("Argentina").get("AR").get("closed")
Insert cell
totalOutcomes = d3.rollup(raw, v=> d3.sum(v, d => d.value))
Insert cell
totalOutcomesByType = d3.rollup(raw, v=> d3.sum(v, d => d.value), d => d.outcome)
Insert cell
totalOutcomesByType.get("rejected")
Insert cell
totalOutcomesByStage = d3.rollup(raw, v=> d3.sum(v, d => d.value), d => d.stage, d => d.outcome)
Insert cell
totalOutcomesByStage.get("AR").get("recognized")
Insert cell
d3.groups(raw, d => d.originCountry, d => d.stage, d => d.outcome)
Insert cell
leastOutcomeCountry = d3.least(d3.rollup(raw, v=> d3.sum(v, d => d.value), d=> d.originCountry), ([, sum]) => sum)
Insert cell
highestOutcomeCountry = d3.least(d3.rollup(raw, v=> d3.sum(v, d => d.value), d=> d.originCountry), ([, sum]) => -sum)
Insert cell
highestOutcomeStage = d3.least(d3.rollup(raw, v=> d3.sum(v, d => d.value), d=> d.stage), ([, sum]) => -sum)
Insert cell
lowestOutcomeStage = d3.least(d3.rollup(raw, v=> d3.sum(v, d => d.value), d=> d.stage), ([, sum]) => sum)
Insert cell
function getOutcomes (array) {
let outcomes = getOutcomes_Rec(array).concat(getOutcomes_Pro(array), getOutcomes_Rej(array), getOutcomes_Clo(array))

return outcomes
}
Insert cell
getOutcomes_Rec(test)
Insert cell
function getOutcomes_Rec (array){
let outcomes = []
for(let i=0; i<array.length; i++){
let newOutcome = {}

newOutcome.year = array[i]['Year']
newOutcome.originCountry = array[i]['Country of origin']
newOutcome.asylumCountry = array[i]['Country of asylum']
newOutcome.stage = array[i]['Stage of procedure']
newOutcome.outcome = "recognized"
newOutcome.value = +array[i]['Recognized decisions'] || 0

outcomes.push(newOutcome)
}
return outcomes
}
Insert cell
getOutcomes_Pro(test)
Insert cell
function getOutcomes_Pro (array){
let outcomes = []
for(let i=0; i<array.length; i++){
let newOutcome = {}

newOutcome.year = array[i]['Year']
newOutcome.originCountry = array[i]['Country of origin']
newOutcome.asylumCountry = array[i]['Country of asylum']
newOutcome.stage = array[i]['Stage of procedure']
newOutcome.outcome = "protected"
newOutcome.value = +array[i]['Complimentary protection'] || 0
outcomes.push(newOutcome)
}
return outcomes
}
Insert cell
getOutcomes_Rej(test)
Insert cell
function getOutcomes_Rej (array){
let outcomes = []
for(let i=0; i<array.length; i++){
let newOutcome = {}

newOutcome.year = array[i]['Year']
newOutcome.originCountry = array[i]['Country of origin']
newOutcome.asylumCountry = array[i]['Country of asylum']
newOutcome.stage = array[i]['Stage of procedure']
newOutcome.outcome = "rejected"
newOutcome.value = +array[i]['Rejected decisions'] || 0

outcomes.push(newOutcome)
}
return outcomes
}
Insert cell
getOutcomes_Clo(test)
Insert cell
function getOutcomes_Clo (array){
let outcomes = []
for(let i=0; i<array.length; i++){
let newOutcome = {}

newOutcome.year = array[i]['Year']
newOutcome.originCountry = array[i]['Country of origin']
newOutcome.asylumCountry = array[i]['Country of asylum']
newOutcome.stage = array[i]['Stage of procedure']
newOutcome.outcome = "closed"
newOutcome.value = +array[i]['Otherwise closed'] || 0
outcomes.push(newOutcome)
}
return outcomes
}
Insert cell
rawdata = d3.json('https://raw.githubusercontent.com/tkalainoff/major-studio/main/int/data/us-asylum-decision-2019.json').then(data => _.values(data));
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