-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgraph_zip_time.php
245 lines (223 loc) · 5.75 KB
/
graph_zip_time.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?PHP
global $show;
$show = '';
if(isset($_GET['show'])){
$show = $_GET['show'];
}
global $days_to_predict;
$days_to_predict = '1';
if(isset($_POST['days'])){
$days_to_predict = $_POST['days'];
}
if(isset($_GET['day'])){
$days_to_predict = $_GET['day'];
}
$logo = 'off';
$page_description = "Maryland Cases by Zip Code ";
include_once('menu.php');
global $today;
global $normal;
global $peak;
global $peak_str;
$today = array();
$normal = array();
$peak = array();
$peak_str = array();
global $maryland_history;
$url = 'https://services.arcgis.com/njFNhDsUCentVYJW/arcgis/rest/services/TEST_ZIPCodeCases/FeatureServer/0/query?where=1%3D1&outFields=OBJECTID,ZIPCODE1,ZIPName,ProtectedCount&returnGeometry=false&outSR=4326&f=json';
$maryland_history = make_maryland_array3($url,'');
global $buffer;
$buffer = '.85';
if(isset($_POST['buffer'])){
$buffer = $_POST['buffer'];
}
global $debug_in;
global $debug_out;
function total_count($county){
global $covid_db;
$q = "SELECT number_of_people FROM coronavirus_populations where name_of_location = '$county' ";
$r = $covid_db->query($q);
$d = mysqli_fetch_array($r);
return $d['number_of_people'];
}
function rate_of_infection($county){
global $covid_db;
$q = "SELECT rate_of_infection FROM coronavirus_populations where name_of_location = '$county' ";
$r = $covid_db->query($q);
$d = mysqli_fetch_array($r);
return $d['rate_of_infection'];
}
function show_on_graph($county){
global $show;
// if has cases = true else false
global $maryland_history;
//$date = $maryland_history['date'];
$date = '';
$aka = county_aka($county);
error_log("show_on_graph($county) $date $aka", 0);
$val = $maryland_history[$date][$aka];
$count = intval($val);
if ($show != ''){
if ($show == $county){
return 'true';
}else{
return 'false';
}
}
if ($count == 0){
return 'false';
}else{
return 'true';
}
}
function make_county($county){
global $covid_db;
$return = '';
$t = '0'; // days
$dt= '1'; // change in days
// history
global $maryland_history;
$aka = county_aka($county);
$count=0;
global $today;
foreach ($maryland_history as $date => $array){
$last_count = $count;
$count = intval($array[$aka]);
$return .= '{ label: "'.$date.'", y: '.$count.' }, ';
$today[$county] = $count;
}
// predictive
//$next = date('Y-m-d',strtotime($date)+86400);
//$return .= make_county_prediction($county,$next,$count,$dt);
$return = rtrim(trim($return), ",");
return $return;
}
function make_county_prediction($county,$start,$count,$dt){
global $debug_in;
global $debug_out;
global $covid_db;
$return = '';
$start = new DateTime ($start, new DateTimeZone ('UTC'));
global $days_to_predict;
$end = new DateTime (" +$days_to_predict days", new DateTimeZone ('UTC'));
$interval = new DateInterval ('P1D');
$range = new DatePeriod ($start, $interval, $end);
$N = $count; // total cases
$Nmax = total_count($county); // population
$a = rate_of_infection($county); // percentage infection rate
$day_buffer = 0;
foreach ($range as $date) {
$out = $date->format ('Y-m-d');
$debug_in .= "<li>$out N: $N Nold: $Nold Nmax:$Nmax a:$a</li>";
$Nold=$N;
$N=$N+$a*(1-$N/$Nmax)*$N*$dt;
$r=($N-$Nold)/$dt;
if(empty($base)){
// only set base once
global $buffer;
$base = ($N - $r)*$buffer;
$debug_out .= "<li><b>BASE: $base = ($N - $r) * $buffer</b></li>";
}
$r = $r + $base;
$debug_out .= "<li>$out N:$N r:$r</li>";
$return .= '{ label: "'.$out.'", y: '.$r.' }, ';
global $today;
global $normal;
global $peak;
global $peak_str;
$r_int = number_format($r, 0, '.', ',');
if($r > $peak[$county]){
$peak[$county] = $r;
$peak_str[$county] = "<p>On $out $county peaked at $r_int<p>";
}
if (intval($today[$county]) > intval($r) && intval($r) != 0 && $normal[$county] == '' && $day_buffer > 14){
$normal[$county] = "<p style='background-color:pink; '>On $out $county went under ".$today[$county]." to $r_int</p>";
}
$day_buffer++;
}
return $return;
}
function make_graph_block($county){
echo '{
type: "spline",
visible: false,
showInLegend: true,
yValueFormatString: "#####",
name: "'.$county.'",
dataPoints: [';
echo make_county($county);
echo ' ]
},';
}
?>
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme:"light2",
animationEnabled: true,
exportEnabled: true,
title:{
text: "The Great State of Maryland - <?PHP echo $page_description; ?> covid19math.net"
},
axisY :{
includeZero: false,
title: "COVID-19 Cases",
suffix: ""
},
toolTip: {
shared: "true"
},
legend:{
cursor:"pointer",
itemclick : toggleDataSeries
},
data: [
<?PHP echo make_graph_block('21093');?>,
{
type: "spline",
visible: false,
showInLegend: true,
yValueFormatString: "#####",
name: "Hospitalized Delta",
dataPoints: [
<?PHP echo make_county('hospitalizedDelta'); ?>
]
},
{
type: "spline",
visible: false,
showInLegend: true,
yValueFormatString: "#####",
name: "Released Delta",
dataPoints: [
<?PHP echo make_county('releasedDelta'); ?>
]
},
{
type: "spline",
visible: true,
showInLegend: true,
yValueFormatString: "#####",
name: "Deaths Delta",
dataPoints: [
<?PHP echo make_county('deathsDelta'); ?>
]
}]
}
);
chart.render();
function toggleDataSeries(e) {
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible ){
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
chart.render();
}
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; max-width: 1020px; margin: 0px auto;"></div>
<script src="canvasjs.min.js"></script>
<?PHP include_once('footer.php'); ?>