Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All cluster together #100

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions components/FilterPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import styled from 'styled-components'
import { connect } from 'react-redux'
import _ from 'lodash'

import { state, city, abroad, p2p } from '../../images/index'
import { state, city, abroad, p2p, all } from '../../images/index'
import {
addStates,
removeStates,
addCities,
removeCities,
addTravel,
removeTravel,
addAll,
removeAll,
} from '../../util/filters'
import { updateGraph, selectFilter } from '../Redux/actions'

Expand All @@ -29,6 +31,7 @@ const filters = [
{ name: 'State', icon: state, add: addStates, remove: removeStates },
{ name: 'City', icon: city, add: addCities, remove: removeCities },
{ name: 'Travel', icon: abroad, add: addTravel, remove: removeTravel },
{ name: 'All', icon: all, add: addAll, remove: removeAll},
]

const HeaderContainer = styled.div`
Expand All @@ -50,7 +53,7 @@ const HeaderContainer = styled.div`

const FilterMenuContainer = styled.div`
display: grid;
grid-template-rows: 10% 10% 10% 10% 60%;
grid-template-rows: 10% 10% 10% 10% 10% 40%;
overflow: auto;
font-family: 'Lato', sans-serif;
color: #7c7a7a;
Expand Down
Binary file added images/filter/all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import abroad from './filter/abroad.png'
import state from './filter/state.png'
import city from './filter/city.png'
import p2p from './filter/p2p.png'
import all from './filter/all.png'

import state_node from './nodes/state.png'
import city_node from './nodes/city.png'
Expand All @@ -28,6 +29,7 @@ export {
p2p,
city_node,
abroad,
all,
plane_abroad_node,
plane_local_node,
}
317 changes: 317 additions & 0 deletions util/filters/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
import hash from 'object-hash'
import { state_node, city_node, plane_abroad_node, plane_local_node } from '../../images'
import _ from 'lodash'
import dotProp from 'dot-prop-immutable'

export const addAll= (graph, patients) => {
let states = {}
let stateCitiesMap = {}
let locations = {}

for (let patientId in patients) {
let city = patients[patientId].city
? patients[patientId].city
: (patients[patientId].district ? patients[patientId].district: patients[patientId].state )
if (!states[hash(patients[patientId].state)]) {
states[hash(patients[patientId].state)] = patients[patientId].state
if (!stateCitiesMap[hash(patients[patientId].state)]) {
stateCitiesMap[hash(patients[patientId].state)] = {}
}
}
if (
!stateCitiesMap[hash(patients[patientId].state)][hash(city)] &&
city !== ''
) {
stateCitiesMap[hash(patients[patientId].state)][hash(city)] = city
}

if (patients[patientId].place_attributes !== null) {
patients[patientId].place_attributes.forEach(loc => {
if (!locations[hash(loc.place)]) {
locations[hash(loc.place)] = loc
}
})
}
}

console.log('State map: ', states, 'State Cities Map:', stateCitiesMap, 'Location :', locations)

for (var key in states) {
let node = {
id: key + 1,
label: states[key],
size: 30,
shape: 'image',
image: state_node,
}
let index = _.findIndex(dotProp.get(graph, 'nodes'), function(o) {
return o.id == node.id
})

if (index === -1) {
graph = dotProp.set(graph, 'nodes', list => [...list, node])
}
}

for (var key in stateCitiesMap) {
for (var cityKey in stateCitiesMap[key]) {
let cityNode = {
id: cityKey,
label: stateCitiesMap[key][cityKey],
size: 20,
shape: 'image',
image: city_node,
}

let index = _.findIndex(dotProp.get(graph, 'nodes'), function(o) {
return o.id == cityNode.id
})

if (index === -1) {
graph = dotProp.set(graph, 'nodes', list => [...list, cityNode])
}
}
}

for (let loc in locations) {
let node = {
id: loc,
label: locations[loc].place,
size: 30,
shape: 'image',
image: locations[loc].is_foreign ? plane_abroad_node : plane_local_node,
}
let index = _.findIndex(dotProp.get(graph, 'nodes'), function(o) {
return o.id == node.id
})

if (index === -1) {
graph = dotProp.set(graph, 'nodes', list => [...list, node])
}
}

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

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

for (var key in stateCitiesMap) {
for (var cityKey in stateCitiesMap[key]) {
let edge = {
from: key + 1,
to: cityKey,
length: 400,
dashes: true,
arrows: {
to: {
enabled: false,
},
},
color: { opacity: '0.3' },
}
graph = dotProp.set(graph, 'edges', list => [...list, edge])
}
}

for (let patientId in patients) {
let city = patients[patientId].city
? patients[patientId].city
: (patients[patientId].district ? patients[patientId].district: patients[patientId].state )
let edge = {
from: hash(city),
to: patients[patientId].patientId,
length: 250,
dashes: true,
arrows: {
to: {
enabled: false,
},
},
color: { opacity: '0.3' },
}
graph = dotProp.set(graph, 'edges', list => [...list, edge])
}

return graph
}

export const removeAll = (graph, patients) => {
let states = {}
let stateCitiesMap = {}
let locations = {}

for (let patientId in patients) {
let city = patients[patientId].city
? patients[patientId].city
: patients[patientId].district
if (!states[hash(patients[patientId].state)]) {
states[hash(patients[patientId].state)] = patients[patientId].state
if (!stateCitiesMap[hash(patients[patientId].state)]) {
stateCitiesMap[hash(patients[patientId].state)] = {}
}
}
if (
!stateCitiesMap[hash(patients[patientId].state)][hash(city)] &&
city !== ''
) {
stateCitiesMap[hash(patients[patientId].state)][hash(city)] = city
}
if (patients[patientId].place_attributes !== null) {
patients[patientId].place_attributes.forEach(loc => {
if (!locations[hash(loc.place)]) {
locations[hash(loc.place)] = loc
}
})
}
}

console.log('State map: ', states, 'State Cities Map:', stateCitiesMap, 'Location :', locations)

for (var key in states) {
let node = {
id: key + 1,
label: states[key],
size: 30,
shape: 'image',
image: state_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 (var key in stateCitiesMap) {
for (var cityKey in stateCitiesMap[key]) {
let cityNode = {
id: cityKey,
label: stateCitiesMap[key][cityKey],
size: 40,
shape: 'image',
image: city_node,
}

let index = _.findIndex(dotProp.get(graph, 'nodes'), function(o) {
return o.id == cityKey
})

if (index !== -1) {
graph = dotProp.delete(graph, `nodes.${index}`)
}
}
}
for (var key in stateCitiesMap) {
for (var cityKey in stateCitiesMap[key]) {
let edge = {
from: key + 1,
to: cityKey,
length: 400,
dashes: true,
arrows: {
to: {
enabled: false,
},
},
color: { opacity: '0.3' },
}
let edgeIndex = _.findIndex(graph.edges, function(o) {
return o.to == edge.to && o.from === edge.from
})
if (edgeIndex !== -1) {
graph = dotProp.delete(graph, `edges.${edgeIndex}`)
}
}
}

for (let patientId in patients) {
let city = patients[patientId].city
? patients[patientId].city
: patients[patientId].district
let edge = {
from: hash(city),
to: patients[patientId].patientId,
length: 250,
dashes: true,
arrows: {
to: {
enabled: false,
},
},
color: { opacity: '0.3' },
}
let edgeIndex = _.findIndex(graph.edges, function(o) {
return o.to == edge.to && o.from === edge.from
})
if (edgeIndex !== -1) {
graph = dotProp.delete(graph, `edges.${edgeIndex}`)
}
}

for (let loc in locations) {
let node = {
id: loc,
label: locations[loc].place,
size: 30,
shape: 'image',
image: locations[loc].is_foreign ? plane_abroad_node : plane_local_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].place_attributes !== null &&
patients[patientId].place_attributes[0]
) {
patients[patientId].place_attributes.forEach(loc => {
let edge = {
from: hash(loc.place),
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
}
3 changes: 3 additions & 0 deletions util/filters/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { addStates, removeStates } from './state'
import { addCities, removeCities } from './city'
import { addTravel, removeTravel } from './travel'
import { addAll, removeAll } from './all'

export {
addStates,
Expand All @@ -9,4 +10,6 @@ export {
removeCities,
addTravel,
removeTravel,
addAll,
removeAll,
}