Skip to content

Commit 9734ad6

Browse files
committed
Added plot data support for ILINet indicator set
1 parent d29ac85 commit 9734ad6

File tree

3 files changed

+289
-52
lines changed

3 files changed

+289
-52
lines changed

src/assets/js/indicatorHandler.js

+263
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
class IndicatorHandler{
2+
constructor() {
3+
this.indicators = {};
4+
}
5+
6+
fluviewIndicatorsMapping = {
7+
"wili": "%wILI",
8+
"ili": "%ILI",
9+
}
10+
11+
fluSurvRegions = [
12+
{ value: 'network_all', label: 'Entire Network' },
13+
{ value: 'network_eip', label: 'EIP Netowrk' },
14+
{ value: 'network_ihsp', label: 'IHSP Network' },
15+
{ value: 'CA', label: 'CA' },
16+
{ value: 'CO', label: 'CO' },
17+
{ value: 'CT', label: 'CT' },
18+
{ value: 'GA', label: 'GA' },
19+
{ value: 'IA', label: 'IA' },
20+
{ value: 'ID', label: 'ID' },
21+
{ value: 'MD', label: 'MD' },
22+
{ value: 'MI', label: 'MI' },
23+
{ value: 'MN', label: 'MN' },
24+
{ value: 'NM', label: 'NM' },
25+
{ value: 'NY_albany', label: 'NY (Albany)' },
26+
{ value: 'NY_rochester', label: 'NY (Rochester)' },
27+
{ value: 'OH', label: 'OH' },
28+
{ value: 'OK', label: 'OK' },
29+
{ value: 'OR', label: 'OR' },
30+
{ value: 'RI', label: 'RI' },
31+
{ value: 'SD', label: 'SD' },
32+
{ value: 'TN', label: 'TN' },
33+
{ value: 'UT', label: 'UT' },
34+
]
35+
36+
fluviewRegions = [
37+
{ id: 'nat', text: 'U.S. National' },
38+
{ id: 'hhs1', text: 'HHS Region 1' },
39+
{ id: 'hhs2', text: 'HHS Region 2' },
40+
{ id: 'hhs3', text: 'HHS Region 3' },
41+
{ id: 'hhs4', text: 'HHS Region 4' },
42+
{ id: 'hhs5', text: 'HHS Region 5' },
43+
{ id: 'hhs6', text: 'HHS Region 6' },
44+
{ id: 'hhs7', text: 'HHS Region 7' },
45+
{ id: 'hhs8', text: 'HHS Region 8' },
46+
{ id: 'hhs9', text: 'HHS Region 9' },
47+
{ id: 'hhs10', text: 'HHS Region 10' },
48+
{ id: 'cen1', text: 'Census Region 1' },
49+
{ id: 'cen2', text: 'Census Region 2' },
50+
{ id: 'cen3', text: 'Census Region 3' },
51+
{ id: 'cen4', text: 'Census Region 4' },
52+
{ id: 'cen5', text: 'Census Region 5' },
53+
{ id: 'cen6', text: 'Census Region 6' },
54+
{ id: 'cen7', text: 'Census Region 7' },
55+
{ id: 'cen8', text: 'Census Region 8' },
56+
{ id: 'cen9', text: 'Census Region 9' },
57+
{ id: 'AK', text: 'AK' },
58+
{ id: 'AL', text: 'AL' },
59+
{ id: 'AR', text: 'AR' },
60+
{ id: 'AZ', text: 'AZ' },
61+
{ id: 'CA', text: 'CA' },
62+
{ id: 'CO', text: 'CO' },
63+
{ id: 'CT', text: 'CT' },
64+
{ id: 'DC', text: 'DC' },
65+
{ id: 'DE', text: 'DE' },
66+
{ id: 'FL', text: 'FL' },
67+
{ id: 'GA', text: 'GA' },
68+
{ id: 'HI', text: 'HI' },
69+
{ id: 'IA', text: 'IA' },
70+
{ id: 'ID', text: 'ID' },
71+
{ id: 'IL', text: 'IL' },
72+
{ id: 'IN', text: 'IN' },
73+
{ id: 'KS', text: 'KS' },
74+
{ id: 'KY', text: 'KY' },
75+
{ id: 'LA', text: 'LA' },
76+
{ id: 'MA', text: 'MA' },
77+
{ id: 'MD', text: 'MD' },
78+
{ id: 'ME', text: 'ME' },
79+
{ id: 'MI', text: 'MI' },
80+
{ id: 'MN', text: 'MN' },
81+
{ id: 'MO', text: 'MO' },
82+
{ id: 'MS', text: 'MS' },
83+
{ id: 'MT', text: 'MT' },
84+
{ id: 'NC', text: 'NC' },
85+
{ id: 'ND', text: 'ND' },
86+
{ id: 'NE', text: 'NE' },
87+
{ id: 'NH', text: 'NH' },
88+
{ id: 'NJ', text: 'NJ' },
89+
{ id: 'NM', text: 'NM' },
90+
{ id: 'NV', text: 'NV' },
91+
{ id: 'NY', text: 'NY' },
92+
{ id: 'OH', text: 'OH' },
93+
{ id: 'OK', text: 'OK' },
94+
{ id: 'OR', text: 'OR' },
95+
{ id: 'PA', text: 'PA' },
96+
{ id: 'RI', text: 'RI' },
97+
{ id: 'SC', text: 'SC' },
98+
{ id: 'SD', text: 'SD' },
99+
{ id: 'TN', text: 'TN' },
100+
{ id: 'TX', text: 'TX' },
101+
{ id: 'UT', text: 'UT' },
102+
{ id: 'VA', text: 'VA' },
103+
{ id: 'VT', text: 'VT' },
104+
{ id: 'WA', text: 'WA' },
105+
{ id: 'WI', text: 'WI' },
106+
{ id: 'WV', text: 'WV' },
107+
{ id: 'WY', text: 'WY' },
108+
{ id: 'ny_minus_jfk', text: 'NY (minus NYC)' },
109+
{ id: 'as', text: 'American Samoa' },
110+
{ id: 'mp', text: 'Mariana Islands' },
111+
{ id: 'gu', text: 'Guam' },
112+
{ id: 'pr', text: 'Puerto Rico' },
113+
{ id: 'vi', text: 'Virgin Islands' },
114+
{ id: 'ord', text: 'Chicago' },
115+
{ id: 'lax', text: 'Los Angeles' },
116+
{ id: 'jfk', text: 'New York City' },
117+
]
118+
119+
checkForCovidcastIndicators() {
120+
return this.indicators.some((indicator) => {
121+
return indicator["_endpoint"] === "covidcast";
122+
});
123+
}
124+
125+
showFluviewRegions() {
126+
var fluviewRegionSelect = `
127+
<div class="row margin-top-1rem">
128+
<div class="col-2">
129+
<label for="fluviewRegions" class="col-form-label">ILINet Location(s):</label>
130+
</div>
131+
<div class="col-10">
132+
<select id="fluviewRegions" name="fluviewRegions" class="form-select" multiple="multiple"></select>
133+
</div>
134+
</div>`
135+
$("#otherEndpointLocations").append(fluviewRegionSelect)
136+
$("#fluviewRegions").select2({
137+
placeholder: "Select ILINet Location(s)",
138+
data: this.fluviewRegions,
139+
allowClear: true,
140+
width: '100%',
141+
});
142+
}
143+
144+
generateEpivisCustomTitle(indicator, geoValue) {
145+
var epivisCustomTitle;
146+
if (indicator["member_short_name"]) {
147+
epivisCustomTitle = `${indicator["signal_set_short_name"]}:${indicator["member_short_name"]} : ${geoValue}`
148+
} else {
149+
epivisCustomTitle = `${indicator["signal_set_short_name"]} : ${geoValue}`
150+
}
151+
return epivisCustomTitle;
152+
}
153+
154+
plotData(){
155+
var dataSets = {};
156+
var covidCastGeographicValues = $('#geographic_value').select2('data');
157+
var fluviewRegions = $('#fluviewRegions').select2('data');
158+
console.log(fluviewRegions)
159+
160+
this.indicators.forEach((indicator) => {
161+
if (indicator["_endpoint"] === "covidcast") {
162+
covidCastGeographicValues.forEach((geoValue) => {
163+
var geographicValue = (typeof geoValue.id === 'string') ? geoValue.id.toLowerCase() : geoValue.id;
164+
var geographicType = geoValue.geoType;
165+
dataSets[`${indicator["signal"]}_${geographicValue}`] = {
166+
color: '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'),
167+
title: "value",
168+
params: {
169+
_endpoint: indicator["_endpoint"],
170+
data_source: indicator["data_source"],
171+
signal: indicator["signal"],
172+
time_type: indicator["time_type"],
173+
geo_type: geographicType,
174+
geo_value: geographicValue,
175+
custom_title: this.generateEpivisCustomTitle(indicator, geoValue.text)
176+
}
177+
}
178+
})
179+
} else if (indicator["_endpoint"] === "fluview") {
180+
fluviewRegions.forEach((region) => {
181+
dataSets[`${indicator["signal"]}_${indicator["_endpoint"]}_${region.id}`] = {
182+
color: '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'),
183+
title: this.fluviewIndicatorsMapping[indicator["signal"]] || indicator["signal"],
184+
params: {
185+
_endpoint: indicator["_endpoint"],
186+
regions: region.id,
187+
custom_title: this.generateEpivisCustomTitle(indicator, region.text)
188+
}
189+
}
190+
})
191+
}
192+
// else if (indicator["_endpoint"] === "flusurv") {
193+
// // TODO: Add support for flusurv. Need to figure out how to get the geographic value for flusurv.
194+
// // For now, we will just use the static geographic value.
195+
// dataSets[`${indicator["signal"]}_${indicator["_endpoint"]}`] = {
196+
// color: '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'),
197+
// title: indicator["signal"],
198+
// params: {
199+
// _endpoint: indicator["_endpoint"],
200+
// locations: "network_all",
201+
// custom_title: this.generateEpivisCustomTitle(indicator, "Entire Network")
202+
// }
203+
// }
204+
// } else if (indicator["_endpoint"] === "gft") {
205+
// // TODO: Add support for gft. Need to figure out how to get the geographic value for gft.
206+
// // For now, we will just use the static geographic value.
207+
// dataSets[`${indicator["signal"]}_${indicator["_endpoint"]}`] = {
208+
// color: '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'),
209+
// title: indicator["signal"],
210+
// params: {
211+
// _endpoint: indicator["_endpoint"],
212+
// locations: "nat",
213+
// custom_title: this.generateEpivisCustomTitle(indicator, "U.S. National")
214+
// }
215+
// }
216+
// } else if (indicator["_endpoint"] === "wiki") {
217+
// dataSets[`${indicator["signal"]}_${indicator["_endpoint"]}`] = {
218+
// color: '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'),
219+
// title: indicator["signal"],
220+
// params: {
221+
// _endpoint: indicator["_endpoint"],
222+
// articles: "fatigue_(medical)",
223+
// language: "en",
224+
// resolution: "daily",
225+
// custom_title: this.generateEpivisCustomTitle(indicator, "U.S. National")
226+
// }
227+
// }
228+
// } else if (indicator["_endpoint"] === "cdc") {
229+
// dataSets[`${indicator["signal"]}_${indicator["_endpoint"]}`] = {
230+
// color: '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'),
231+
// title: indicator["signal"],
232+
// params: {
233+
// _endpoint: indicator["_endpoint"],
234+
// auth: "390da13640f61",
235+
// locations: "nat",
236+
// custom_title: this.generateEpivisCustomTitle(indicator, "U.S. National")
237+
// }
238+
// }
239+
// } else if(indicator["_endpoint"] === "sensors") {
240+
// dataSets[`${indicator["signal"]}_${indicator["_endpoint"]}`] = {
241+
// color: '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'),
242+
// title: indicator["signal"],
243+
// params: {
244+
// _endpoint: indicator["_endpoint"],
245+
// auth: "390da13640f61",
246+
// names: "wiki",
247+
// locations: "nat",
248+
// custom_title: this.generateEpivisCustomTitle(indicator, "U.S. National")
249+
// }
250+
// }
251+
// }
252+
});
253+
var requestParams = [];
254+
for (var key in dataSets) {
255+
requestParams.push(dataSets[key]);
256+
}
257+
258+
var urlParamsEncoded = btoa(`{"datasets":${JSON.stringify(requestParams)}}`);
259+
260+
var linkToEpivis = `${epiVisUrl}#${urlParamsEncoded}`
261+
window.open(linkToEpivis, '_blank').focus();
262+
}
263+
}

src/assets/js/signal_sets.js

+21-51
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const indicatorHandler = new IndicatorHandler();
2+
13
function initSelect2(elementId, data) {
24
$(`#${elementId}`).select2({
35
data: data,
@@ -27,7 +29,7 @@ async function checkGeoCoverage(geoType, geoValue) {
2729
}
2830
});
2931

30-
checkedSignalMembers.forEach(signal => {
32+
checkedSignalMembers.filter(signal => signal["_endpoint"] === "covidcast").forEach(signal => {
3133
const covered = result["epidata"].some(
3234
e => (e.source === signal.data_source && e.signal === signal.signal)
3335
);
@@ -43,50 +45,6 @@ async function checkGeoCoverage(geoType, geoValue) {
4345
}
4446
}
4547

46-
47-
48-
function plotData() {
49-
var dataSets = {};
50-
var geographicValues = $('#geographic_value').select2('data');
51-
checkedSignalMembers.forEach((signal) => {
52-
geographicValues.forEach((geoValue) => {
53-
var geographicValue = (typeof geoValue.id === 'string') ? geoValue.id.toLowerCase() : geoValue.id;
54-
var geographicType = geoValue.geoType;
55-
var epivisCustomTitle;
56-
if (signal["member_short_name"]) {
57-
epivisCustomTitle = `${signal["signal_set_short_name"]}:${signal["member_short_name"]} : ${geoValue.text}`
58-
} else {
59-
epivisCustomTitle = `${signal["signal_set_short_name"]} : ${geoValue.text}`
60-
}
61-
dataSets[`${signal["signal"]}_${geographicValue}`] = {
62-
color: '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'),
63-
title: "value",
64-
params: {
65-
_endpoint: signal["_endpoint"],
66-
data_source: signal["data_source"],
67-
signal: signal["signal"],
68-
time_type: signal["time_type"],
69-
geo_type: geographicType,
70-
geo_value: geographicValue,
71-
custom_title: epivisCustomTitle
72-
}
73-
}
74-
})
75-
76-
});
77-
78-
var requestParams = [];
79-
for (var key in dataSets) {
80-
requestParams.push(dataSets[key]);
81-
}
82-
83-
var urlParamsEncoded = btoa(`{"datasets":${JSON.stringify(requestParams)}}`);
84-
85-
var linkToEpivis = `${epiVisUrl}#${urlParamsEncoded}`
86-
window.open(linkToEpivis, '_blank').focus();
87-
}
88-
89-
9048
// Function to update the modal content
9149
function updateSelectedSignals(dataSource, signalDisplayName, signalSet, signal) {
9250
var selectedSignalsList = document.getElementById('selectedSignalsList');
@@ -120,6 +78,7 @@ function addSelectedSignal(element) {
12078
document.getElementById(`${element.dataset.datasource}_${element.dataset.signal}`).remove();
12179
}
12280

81+
indicatorHandler.indicators = checkedSignalMembers;
12382

12483
if (checkedSignalMembers.length > 0) {
12584
$("#showSelectedSignalsButton").show();
@@ -130,14 +89,24 @@ function addSelectedSignal(element) {
13089

13190
$("#showSelectedSignalsButton").click(function() {
13291
alertPlaceholder.innerHTML = "";
92+
if (!indicatorHandler.checkForCovidcastIndicators()) {
93+
$("#geographic_value").prop("disabled", true);
94+
}
13395
$('#geographic_value').select2("data").forEach(geo => {
13496
checkGeoCoverage(geo.geoType, geo.id).then((notCoveredSignals) => {
13597
if (notCoveredSignals.length > 0) {
13698
showNotCoveredGeoWarningMessage(notCoveredSignals, geo.text);
13799
}
138100
})
139-
140101
});
102+
var otherEndpointLocationsWarning = `<div class="alert alert-info" data-mdb-alert-init role="alert">` +
103+
` <div>Please, note that some indicator sets may require to select location(s) that is/are different from location above.<br> `
104+
nonCovidcastSignalSets = [...new Set(checkedSignalMembers.filter(signal => signal["_endpoint"] != "covidcast").map((signal) => signal["signal_set"]))];
105+
otherEndpointLocationsWarning += `Different location is required for following signal set(s): ${nonCovidcastSignalSets.join(", ")}`
106+
otherEndpointLocationsWarning += `</div></div>`
107+
$("#differentLocationNote").html(otherEndpointLocationsWarning)
108+
indicatorHandler.showFluviewRegions();
109+
141110
});
142111

143112
// Add an event listener to each 'bulk-select' element
@@ -468,14 +437,15 @@ $('#geographic_value').on('select2:select', function (e) {
468437
function submitMode(event) {
469438
event.preventDefault();
470439
var geographicValues = $('#geographic_value').select2('data');
471-
472-
if (geographicValues.length === 0) {
473-
appendAlert("Please select at least one geographic location", "warning")
474-
return;
440+
if (indicatorHandler.checkForCovidcastIndicators()) {
441+
if (geographicValues.length === 0) {
442+
appendAlert("Please select at least one geographic location", "warning")
443+
return;
444+
}
475445
}
476446

477447
if (currentMode === 'epivis') {
478-
plotData();
448+
indicatorHandler.plotData();
479449
} else if (currentMode === 'export') {
480450
exportData();
481451
} else {

0 commit comments

Comments
 (0)