17
17
fail ('Error loading epiweek info ' );
18
18
}
19
19
20
- // TODO - just need forecast and region ID for state
21
20
//List of all regions
22
- if (getRegionsExtended ($ dbh , $ output , $ output ['user_id ' ]) !== 1 ) {
23
- fail ('Error loading region details, history, or forecast ' );
21
+ if (getRegions ($ dbh , $ output , $ output ['user_id ' ]) !== 1 ) {
22
+ fail ('Error loading region details ' );
24
23
}
25
24
26
25
if (isset ($ _REQUEST ['skip_instructions ' ])) {
42
41
fail ('Invalid region_id ' .$ regionID );
43
42
}
44
43
44
+ //Forecast for this round
45
+ if (loadForecast ($ dbh , $ output , $ output ['user_id ' ], $ regionID ) !== 1 ) {
46
+ fail ('Error loading current forecast ' );
47
+ }
48
+ $ output ['regions ' ][$ regionID ]['forecast ' ] = $ output ['forecast ' ];
49
+
45
50
//Forecast from last round
46
51
if (loadForecast ($ dbh , $ output , $ output ['user_id ' ], $ regionID , true ) !== 1 ) {
47
52
fail ('Error loading last week forecast ' );
156
161
{{/seasons}}
157
162
</div>
158
163
</script>
159
- <script src="js/forecast.js?w=202014"></script>
164
+ <script src="js/forecast.js?w=202014.8 "></script>
160
165
<script src="js/delphi_epidata.js"></script>
161
166
<script src="https://unpkg.com/mustache@4.0.1"></script>
162
167
<script>
@@ -214,7 +219,7 @@ function min(x1,x2) { if (x1<x2) { return x1; } return x2; }
214
219
</script>
215
220
<script>
216
221
//globals
217
- var regionName = <?= $ region ['name ' ] ?> ;
222
+ var regionName = ' <?= $ region ['name ' ] ?> ' ;
218
223
var regionID = '<?= $ region ['fluview_name ' ] ?> '; // was: 34
219
224
220
225
var selectedSeasons = [];
@@ -230,14 +235,15 @@ function min(x1,x2) { if (x1<x2) { return x1; } return x2; }
230
235
231
236
var currentWeek = <?= $ currentWeek ?> ;
232
237
var currentSeason = <?= $ current_season ?> ;
238
+ var seasonDefn = [36,40];
233
239
234
- var xRange = [currentSeason*100+36, maxWeek ];
240
+ var xRange = [currentSeason*100+seasonDefn[0], (currentSeason+1)*100+seasonDefn[1] ];
235
241
var yRange = [0, 25];
236
242
var curves = {
237
243
lastForecast: [<?php
238
244
$ n = count ($ lastForecast ['date ' ]);
239
245
for ($ i =0 ; $ i <$ n ; $ i ++) {
240
- printf ('{epiweek:$ d, wili:$ .3f}, ' ,
246
+ printf ('{epiweek:% d, wili:% .3f}, ' ,
241
247
$ lastForecast ['date ' ][$ i ],
242
248
$ lastForecast ['wili ' ][$ i ]);
243
249
}
@@ -254,9 +260,9 @@ function min(x1,x2) { if (x1<x2) { return x1; } return x2; }
254
260
for ($ w =$ region ['forecast ' ]['date ' ][$ n -1 ]; $ w <$ maxEpiweek ; $ w ++) {
255
261
printf ('{epiweek:%d, wili:0}, ' ,$ w );
256
262
}
257
- ?> ];
263
+ ?> ],
258
264
};
259
- function loader(sidebarTitle,rid,parent) {
265
+ function loader(sidebarTitle,rid,parent,whitelist ) {
260
266
return function(result, message, epidata) {
261
267
console.log(sidebarTitle, result, message, epidata != null ? epidata.length : void 0);
262
268
var module = {}
@@ -268,15 +274,26 @@ function loader(sidebarTitle,rid,parent) {
268
274
var season = -1;
269
275
// CDC seasons run from week 36 to week 35 of the following year
270
276
for (var i=0; i<epidata.length; i++) {
271
- var si = Math.floor(epidata[i].epiweek / 100);
272
- if (epidata[i].epiweek % 100 < 36) si = si - 1;
273
- if (season<0 || season != si) {
274
- if (season>=0) module.season[season].end = i-1;
277
+ var modweek = epidata[i].epiweek % 100;
278
+
279
+ // end of last season overlaps with this one
280
+ if (modweek > seasonDefn[1] && module.season[season-1] && !module.season[season-1].end) {
281
+ module.season[season-1].end = i-1;
282
+ }
283
+
284
+ // check for new season
285
+ var si = Math.floor(epidata[i].epiweek / 100);
286
+ if (modweek < seasonDefn[0]) si = si - 1;
287
+ if (season<0 || (season != si && (!whitelist || si in whitelist))) {
288
+
275
289
season = si;
276
290
module.season[season] = {start:i,year:season,label:season==2009?(season+" pandemic"):season,color:getStyle(rid,season).color,current:season==currentSeason};
277
- module.seasons[mi++] = module.season[season]; // ugh
291
+ // the templating engine needs a list, so we make a list
292
+ module.seasons[mi++] = module.season[season];
278
293
}
279
294
}
295
+ module.season[season].end = epidata.length-1;
296
+
280
297
console.log(module);
281
298
curves[rid] = module;
282
299
$(parent).append($(Mustache.render(document.getElementById('sidebar_template').innerHTML, module)));
@@ -294,8 +311,24 @@ function loader(sidebarTitle,rid,parent) {
294
311
});
295
312
resize();
296
313
297
- Epidata.fluview(loader("South Carolina",'sc',"#current_region"), ['sc'], [Epidata.range(minWeek, currentWeek)]);
298
- Epidata.fluview(loader("Region HHS4",'hhs4',"#regional_pandemic"), ['hhs4'], [Epidata.range(200936,201035)]); // need to get region for state from epicast2 db
314
+ Epidata.fluview(loader(regionName,regionID,"#current_region"), [regionID], [Epidata.range(minWeek, currentWeek)]);
315
+ <?php
316
+ if ($ region ['id ' ] >= 11 ) {
317
+ $ regionForState = 1 ;
318
+ foreach ($ output ['regions ' ] as $ r ) {
319
+ printf ("<!-- region %d states: %s --> \n" ,$ r ['id ' ],$ r ['states ' ]);
320
+ $ pos = strpos ($ r ['states ' ],strtoupper ($ region ['fluview_name ' ]));
321
+ printf ("<!-- %s pos: %s --> \n" ,strtoupper ($ region ['fluview_name ' ]),$ pos );
322
+ if ($ pos or $ pos === 0 ) {
323
+ $ regionForState = $ r ['id ' ];
324
+ break ;
325
+ }
326
+ }
327
+ ?>
328
+ Epidata.fluview(loader('<?= $ output ['regions ' ][$ regionForState ]['name ' ] ?> ','<?= $ output ['regions ' ][$ regionForState ]['fluview_name ' ] ?> ',"#regional_pandemic",[2009]), ['<?= $ output ['regions ' ][$ regionForState ]['fluview_name ' ] ?> '], [Epidata.range(200936,201000+(maxWeek%100))]);
329
+ <?php
330
+ } // end if $region['id'] >= 11
331
+ ?>
299
332
});
300
333
</script>
301
334
<?php
0 commit comments