Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://www.mdwestserve.com/coronavirus/graphs.php
- global $today;
- global $normal;
- $today = array();
- $normal = array();
- $q = "SELECT distinct name_of_location FROM coronavirus_populations ";
- $r = $core->query($q);
- while($d = mysqli_fetch_array($r)){
- $today[$d[name_of_location]] = 0; // count
- $normal[$d[name_of_location]] = ''; // string
- }
- global $days_to_predict;
- $days_to_predict = '7';
- if(isset($_POST['days'])){
- $days_to_predict = $_POST['days'];
- }
- global $buffer;
- $buffer = '.85';
- if(isset($_POST['buffer'])){
- $buffer = $_POST['buffer'];
- }
- global $debug_in;
- global $debug_out;
- function total_count($county){
- global $core;
- $q = "SELECT number_of_people FROM coronavirus_populations where name_of_location = '$county' ";
- $r = $core->query($q);
- $d = mysqli_fetch_array($r);
- return $d['number_of_people'];
- }
- function rate_of_infection($county){
- global $core;
- $q = "SELECT rate_of_infection FROM coronavirus_populations where name_of_location = '$county' ";
- $r = $core->query($q);
- $d = mysqli_fetch_array($r);
- return $d['rate_of_infection'];
- }
- function show_on_graph($county){
- // if has cases = true else false
- global $core;
- $q = "SELECT * FROM `coronavirus` order by id desc limit 1";
- $r = $core->query($q);
- $d = mysqli_fetch_array($r);
- $key = $county.'COVID19Cases';
- $count = $d[$key];
- if ($count == 0){
- return 'false';
- }else{
- return 'true';
- }
- }
- function make_county($county){
- global $core;
- $return = '';
- $t = '0'; // days
- $dt= '1'; // change in days
- // history
- $q = "SELECT distinct just_date FROM `coronavirus` order by just_date asc";
- $r = $core->query($q);
- $count=0;
- global $today;
- while($d = mysqli_fetch_array($r)){
- $date = $d['just_date'];
- $q2 = "SELECT * FROM `coronavirus` where just_date = '$date' order by id desc";
- $r2 = $core->query($q2);
- $d2 = mysqli_fetch_array($r2);
- $key = $county.'COVID19Cases';
- $last_count = $count;
- $count = $d2[$key];
- $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 $core;
- $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</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</b></li>";
- }
- $r = $r + $base;
- $debug_out .= "<li>$out N:$N r:$r</li>";
- $return .= '{ label: "'.$out.'", y: '.$r.' }, ';
- global $today;
- global $normal;
- if (intval($today[$county]) > intval($r) && intval($r) != 0 && $normal[$county] == '' && $day_buffer > 14){
- $normal[$county] = "<p style='background-color:lightgreen; '>On $out $county went under ".$today[$county]." to $r</p>";
- }
- $day_buffer++;
- }
- return $return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement