9
9
fluViewRegions ,
10
10
gftLocations ,
11
11
ghtLocations ,
12
- nidssDenqueLocations ,
12
+ nidssDengueLocations ,
13
13
nidssFluLocations ,
14
14
nowcastLocations ,
15
15
quidelLocations ,
@@ -64,9 +64,11 @@ function loadEpidata(
64
64
name : string ,
65
65
epidata : Record < string , unknown > [ ] ,
66
66
columns : string [ ] ,
67
+ columnRenamings : Record < string , string > ,
67
68
params : Record < string , unknown > ,
68
69
) : DataGroup {
69
70
const datasets : DataSet [ ] = [ ] ;
71
+ const colRenamings = new Map ( Object . entries ( columnRenamings ) ) ;
70
72
71
73
for ( const col of columns ) {
72
74
const points : EpiPoint [ ] = [ ] ;
@@ -91,7 +93,11 @@ function loadEpidata(
91
93
}
92
94
points . push ( new EpiPoint ( date , row [ col ] as number ) ) ;
93
95
}
94
- datasets . push ( new DataSet ( points , col , params ) ) ;
96
+ if ( points . length > 0 ) {
97
+ // overwrite default column name if there's an overwrite in columnRenamings
98
+ const title = colRenamings . has ( col ) ? colRenamings . get ( col ) : col ;
99
+ datasets . push ( new DataSet ( points , title , params ) ) ;
100
+ }
95
101
}
96
102
return new DataGroup ( name , datasets ) ;
97
103
}
@@ -112,6 +118,7 @@ export function loadDataSet(
112
118
fixedParams : Record < string , unknown > ,
113
119
userParams : Record < string , unknown > ,
114
120
columns : string [ ] ,
121
+ columnRenamings : Record < string , string > = { } ,
115
122
) : Promise < DataGroup | null > {
116
123
const duplicates = get ( expandedDataGroups ) . filter ( ( d ) => d . title == title ) ;
117
124
if ( duplicates . length > 0 ) {
@@ -135,7 +142,18 @@ export function loadDataSet(
135
142
url . searchParams . set ( 'format' , 'json' ) ;
136
143
return fetchImpl < Record < string , unknown > [ ] > ( url )
137
144
. then ( ( res ) => {
138
- return loadEpidata ( title , res , columns , { _endpoint : endpoint , ...params } ) ;
145
+ const data = loadEpidata ( title , res , columns , columnRenamings , { _endpoint : endpoint , ...params } ) ;
146
+ if ( data . datasets . length == 0 ) {
147
+ return UIkit . modal
148
+ . alert (
149
+ `
150
+ <div class="uk-alert uk-alert-error">
151
+ <a href="${ url . href } ">API Link</a> returned no data.
152
+ </div>` ,
153
+ )
154
+ . then ( ( ) => null ) ;
155
+ }
156
+ return data ;
139
157
} )
140
158
. catch ( ( error ) => {
141
159
console . warn ( 'failed fetching data' , error ) ;
@@ -318,7 +336,7 @@ export function importFluView({
318
336
auth ?: string ;
319
337
} ) : Promise < DataGroup | null > {
320
338
const regionLabel = fluViewRegions . find ( ( d ) => d . value === regions ) ?. label ?? '?' ;
321
- const title = appendIssueToTitle ( `[API] FluView: ${ regionLabel } ` , { issues, lag } ) ;
339
+ const title = appendIssueToTitle ( `[API] ILINet (aka FluView) : ${ regionLabel } ` , { issues, lag } ) ;
322
340
return loadDataSet (
323
341
title ,
324
342
'fluview' ,
@@ -339,6 +357,10 @@ export function importFluView({
339
357
'num_age_4' ,
340
358
'num_age_5' ,
341
359
] ,
360
+ {
361
+ wili : '%wILI' ,
362
+ ili : '%ILI' ,
363
+ } ,
342
364
) ;
343
365
}
344
366
@@ -378,9 +400,9 @@ export function importGHT({
378
400
) ;
379
401
}
380
402
381
- export function importNIDSSDenque ( { locations } : { locations : string } ) : Promise < DataGroup | null > {
382
- const regionLabel = nidssDenqueLocations . find ( ( d ) => d . value === locations ) ?. label ?? '?' ;
383
- const title = `[API] NIDSS-Denque : ${ regionLabel } ` ;
403
+ export function importNIDSSDengue ( { locations } : { locations : string } ) : Promise < DataGroup | null > {
404
+ const regionLabel = nidssDengueLocations . find ( ( d ) => d . value === locations ) ?. label ?? '?' ;
405
+ const title = `[API] NIDSS-Dengue : ${ regionLabel } ` ;
384
406
return loadDataSet (
385
407
title ,
386
408
'nidss_dengue' ,
0 commit comments