Skip to content

Commit 7828c8c

Browse files
committed
Interface works-like and looks-like existing prod; forecast submissions still broken
1 parent e2e260a commit 7828c8c

File tree

2 files changed

+138
-78
lines changed

2 files changed

+138
-78
lines changed

site/forecast.php

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
fail('Error loading epiweek info');
1818
}
1919

20-
// TODO - just need forecast and region ID for state
2120
//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');
2423
}
2524

2625
if(isset($_REQUEST['skip_instructions'])) {
@@ -42,6 +41,12 @@
4241
fail('Invalid region_id '.$regionID);
4342
}
4443

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+
4550
//Forecast from last round
4651
if(loadForecast($dbh, $output, $output['user_id'], $regionID, true) !== 1) {
4752
fail('Error loading last week forecast');
@@ -156,7 +161,7 @@
156161
{{/seasons}}
157162
</div>
158163
</script>
159-
<script src="js/forecast.js?w=202014"></script>
164+
<script src="js/forecast.js?w=202014.8"></script>
160165
<script src="js/delphi_epidata.js"></script>
161166
<script src="https://unpkg.com/mustache@4.0.1"></script>
162167
<script>
@@ -214,7 +219,7 @@ function min(x1,x2) { if (x1<x2) { return x1; } return x2; }
214219
</script>
215220
<script>
216221
//globals
217-
var regionName = <?= $region['name'] ?>;
222+
var regionName = '<?= $region['name'] ?>';
218223
var regionID = '<?= $region['fluview_name'] ?>'; // was: 34
219224

220225
var selectedSeasons = [];
@@ -230,14 +235,15 @@ function min(x1,x2) { if (x1<x2) { return x1; } return x2; }
230235

231236
var currentWeek = <?= $currentWeek ?>;
232237
var currentSeason = <?= $current_season ?>;
238+
var seasonDefn = [36,40];
233239

234-
var xRange = [currentSeason*100+36, maxWeek];
240+
var xRange = [currentSeason*100+seasonDefn[0], (currentSeason+1)*100+seasonDefn[1]];
235241
var yRange = [0, 25];
236242
var curves = {
237243
lastForecast: [<?php
238244
$n = count($lastForecast['date']);
239245
for ($i=0; $i<$n; $i++) {
240-
printf('{epiweek:$d, wili:$.3f},',
246+
printf('{epiweek:%d, wili:%.3f},',
241247
$lastForecast['date'][$i],
242248
$lastForecast['wili'][$i]);
243249
}
@@ -254,9 +260,9 @@ function min(x1,x2) { if (x1<x2) { return x1; } return x2; }
254260
for ($w=$region['forecast']['date'][$n-1]; $w<$maxEpiweek; $w++) {
255261
printf('{epiweek:%d, wili:0},',$w);
256262
}
257-
?>];
263+
?>],
258264
};
259-
function loader(sidebarTitle,rid,parent) {
265+
function loader(sidebarTitle,rid,parent,whitelist) {
260266
return function(result, message, epidata) {
261267
console.log(sidebarTitle, result, message, epidata != null ? epidata.length : void 0);
262268
var module = {}
@@ -268,15 +274,26 @@ function loader(sidebarTitle,rid,parent) {
268274
var season = -1;
269275
// CDC seasons run from week 36 to week 35 of the following year
270276
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+
275289
season = si;
276290
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];
278293
}
279294
}
295+
module.season[season].end = epidata.length-1;
296+
280297
console.log(module);
281298
curves[rid] = module;
282299
$(parent).append($(Mustache.render(document.getElementById('sidebar_template').innerHTML, module)));
@@ -294,8 +311,24 @@ function loader(sidebarTitle,rid,parent) {
294311
});
295312
resize();
296313

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+
?>
299332
});
300333
</script>
301334
<?php

0 commit comments

Comments
 (0)