Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Commit

Permalink
WIP: connect viz to modeled results
Browse files Browse the repository at this point in the history
This commit partially connects the viz prototype
with the IDM API through a proxy GET endpoint that
we host as part of our API. 

The IDM API cannot be fully integrated with this viz
until further design questions are considered. There
is a lot of data standardization that needs to be done
between IDM and ID3C to avoid lots of if/else or
branching logic as part of this app. 

Currently, the prototype is able to get modeled
results for `all` pathogens as well as Flu A H1 & H3. 
We are getting results for Seattle neighborhoods
only. We are not able to query or filter by age, sex, or
vaccination status. The time (Week) filter does not 
currently work in the app, but it should be able to be
integrated with React with the current data. 'Mean' is
not an available result for every pathogen model.

NOTE:
The bar chart and the map are not rendering the
information correctly. This is still a work in
progress that is being put aside until we 
collaborate further on the future of the
modeling results API. 

Please see [this GitHub 
issue](seattleflu/incidence-mapper#87)
for more context.
  • Loading branch information
kairstenfay committed Jul 11, 2019
1 parent 6c5043f commit 83b099b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 28 deletions.
9 changes: 6 additions & 3 deletions data/variableChoices.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@
"modellingDisplayVariable": {
"sidebarLabel": "Modelling value",
"choices": [
{"value": "mean", "label": "mean"},
{"value": "mode", "label": "mode"},
{"value": "quintile", "label": "quintile"}
{"value": "modeled_intensity_mean", "label": "mean"},
{"value": "modeled_intensity_mode", "label": "mode"},
{"value": "modeled_intensity_median", "label": "median"},
{"value": "modeled_intensity_lower_95_CI", "label": "lower 95% CI"},
{"value": "modeled_intensity_upper_95_CI", "label": "upper 95% CI"},
{"value": "modeled_intensity_sd", "label": "standard deviation"}
]
}
}
48 changes: 27 additions & 21 deletions src/middleware/getModellingData.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
import * as types from "../actions/types";
import { selectSettingsForModelRequest, isModelViewSelected } from "../reducers/settings";

const fetchModellingData = (body) => {
const config = {
method: 'POST',
headers: {
Authorization: localStorage.getItem('user'),
"Content-Type": "application/json"
},
credentials: 'omit', // no cookies!
body: JSON.stringify(body)
};
if (!config.headers.Authorization) {
throw new Error("No JWT (needed to fetch modelling results)");
}
return fetch('/getModelResults', config)
.then((res) => {
if (res.status !== 200) throw new Error(res.statusText);
return res;
})
.then((res) => res.json());
const fetchModellingData = async (pathogen) => {
const response = await fetch(`/getModelResults/${pathogen}`);
const data = await response.json();
return data;
};


/**
* What is this middleware?
*
Expand Down Expand Up @@ -59,11 +43,33 @@ const getModellingDataMiddleware = (store) => (next) => async (action) => {
return result;
}



const postBody = selectSettingsForModelRequest(state);
console.log(postBody);

let pathogenIDM;
switch (postBody.pathogen) {
case 'all':
pathogenIDM = 'all'; // technically incorrect
break;
case 'allPositive':
pathogenIDM = 'all';
break;
case 'h1n1pdm':
pathogenIDM = 'Flu_A_H1';
break;
case 'h3n2':
pathogenIDM = 'Flu_A_H3';
break;
default:
throw Error(`Organism ${postBody.pathogen} not yet implemented.`);
}

console.log(pathogenIDM);
let modelResults;
try {
modelResults = await fetchModellingData(postBody);
modelResults = await fetchModellingData(pathogenIDM);
} catch (err) {
console.error("Error getting modeling results:");
console.error(err);
Expand Down
21 changes: 17 additions & 4 deletions src/reducers/modelResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,27 @@ export const areModelResultsReady = (state) => state.modelResults.ready;

export const selectModelErrorMessage = (state) => state.modelResults.message;

export const selectModelResults = (modelData, demes, geoLinks, geoResolution, modellingDisplayVariable) => {
export const selectModelResults = (
modelData, demes, geoLinks, geoResolution, modellingDisplayVariable) => {

let geoResIDM;

if (geoResolution.value === 'neighborhood') {
geoResIDM = 'residence_neighborhood_district_name';
} else {
geoResIDM = 'residence_census_tract';
}

const categories = ["incidence"];
let maxValue = 0;
const counts = modelData.map((d) => {
const deme = geoLinks[d.residence_census_tract][geoResolution.value];
// const deme = geoLinks[d.residence_census_tract][geoResolution.value];
const deme = d[geoResIDM];
const value = d[modellingDisplayVariable.value];
if (value > maxValue) maxValue = value;
return {key: deme, incidence: value};
maxValue = Math.max(value, maxValue);
const res = {key: deme, incidence: value};

return res;
});

return {
Expand Down

0 comments on commit 83b099b

Please sign in to comment.