Skip to content

Commit

Permalink
travel filter
Browse files Browse the repository at this point in the history
  • Loading branch information
sibeshkar committed Mar 21, 2020
1 parent 92a7b7d commit 39c358b
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 38 deletions.
9 changes: 3 additions & 6 deletions util/filters/state.js
Expand Up @@ -58,7 +58,7 @@ export const removeStates = (graph, patients) => {
image: state_node,
}
let index = _.findIndex(dotProp.get(graph, 'nodes'), function(o) {
return o.id == key
return o.id == node.id
})

if (index !== -1) {
Expand All @@ -80,12 +80,9 @@ export const removeStates = (graph, patients) => {
color: { opacity: '0.3' },
}
let edgeIndex = _.findIndex(graph.edges, function(o) {
return (
o.to == patients[patientId].patientId &&
o.from === hash(patients[patientId].state)
)
return o.to == edge.to && o.from === edge.from
})
console.log('edge', edgeIndex)

graph = dotProp.delete(graph, `edges.${edgeIndex}`)
}

Expand Down
113 changes: 81 additions & 32 deletions util/filters/travel.js
Expand Up @@ -5,58 +5,107 @@ import dotProp from 'dot-prop-immutable'
import { plane_node } from '../../images'

export const addTravel = (graph, patients) => {
let travelHistories = {}
let locations = []
let locations = {}

for (let patientId in patients) {
if (patients[patientId].travel !== null) {
if (patients[patientId].travel.length !== 0) {
travelHistories[hash(patients[patientId].travel)] =
patients[patientId].travel
}
patients[patientId].travel.forEach(loc => {
if (!locations[hash(loc)]) {
locations[hash(loc)] = loc
}
})
}
}

for (let key in travelHistories) {
travelHistories[key].forEach(location => {
if (!locations.includes(location)) {
locations.push(location)
}
})
}
console.log(locations)

locations.forEach(location => {
for (let loc in locations) {
let node = {
id: hash(location),
label: location,
size: 40,
id: loc,
label: locations[loc],
size: 30,
shape: 'image',
image: plane_node,
}
graph = dotProp.set(graph, 'nodes', list => [...list, node])
})
}

// Add edges from patient to location
for (let patientId in patients) {
for (let location in patients[patientId].travel) {
let edge = {
from: hash(location),
to: patientId,
length: 250,
dashes: true,
arrows: {
to: {
enabled: false,
if (patients[patientId].travel !== null && patients[patientId].travel[0]) {
patients[patientId].travel.forEach(loc => {
let edge = {
from: hash(loc),
to: patients[patientId].patientId,
length: 500,
dashes: true,
arrows: {
to: {
enabled: false,
},
},
},
color: { opacity: '0.3' },
}
graph = dotProp.set(graph, 'edges', list => [...list, edge])
color: { opacity: '0.2' },
}

graph = dotProp.set(graph, 'edges', list => [...list, edge])
})
}
}

return graph
}

export const removeTravel = (graph, patients) => {
let travelHistories = {}
let locations = {}

for (let patientId in patients) {
if (patients[patientId].travel !== null) {
patients[patientId].travel.forEach(loc => {
if (!locations[hash(loc)]) {
locations[hash(loc)] = loc
}
})
}
}

for (let loc in locations) {
let node = {
id: loc,
label: locations[loc],
size: 30,
shape: 'image',
image: plane_node,
}
let index = _.findIndex(dotProp.get(graph, 'nodes'), function(o) {
return o.id == node.id
})
if (index !== -1) {
graph = dotProp.delete(graph, `nodes.${index}`)
}
}
for (let patientId in patients) {
if (patients[patientId].travel !== null && patients[patientId].travel[0]) {
patients[patientId].travel.forEach(loc => {
let edge = {
from: hash(loc),
to: patients[patientId].patientId,
length: 500,
dashes: true,
arrows: {
to: {
enabled: false,
},
},
color: { opacity: '0.2' },
}

let edgeIndex = _.findIndex(graph.edges, function(o) {
return o.to == edge.to && o.from === edge.from
})

graph = dotProp.delete(graph, `edges.${edgeIndex}`)
})
}
}
return graph
}

0 comments on commit 39c358b

Please sign in to comment.