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
+ }
0 commit comments