<?php
// Setting
$path_to_data = "../wxhalikko/stormtracker/NSGraph.txt";
// End of setting
@$bdataraw = file_get_contents($path_to_data);
$bdataraw = trim($bdataraw);
$bdataraw = preg_replace("/[\r\n]+[\s\t]*[\r\n]+/","\n",$bdataraw);

$ns = explode("\n",$bdataraw);
$lines = count($ns);
$offset = date('Z');
$tzone = date('T');
$g = 0;
for($l=0;$l < $lines-1;$l++) {
  
$data = explode(",", $ns[$l]);
  
    $strikes = $data[9];
    $cstrikes = $data[12];
    $dstrikes = $data[13];
    $estrikes = $data[14];
    $fstrikes = $data[15];
    
    //Create times
    $min = $data[4];
    if ($min < 10) { $min = "0".$min;}
    $time = $data[3].":".$min.":".$data[5];
    $timestr = $data[2].'-'.$data[1].'-'.$data[0].' '.$time.' '.$tzone ;
    $rawdate = ((strtotime($timestr)+($offset))*1000);

    $small = ($lines - 62);
    if($l > $small) {
    $t=(62-$g);
    $g++;
    $smalljson.= '['.$rawdate.', '.$strikes.'],';
    }
    $totjson.= '['.$rawdate.', '.$strikes.'],';
    
    $cjson.= '['.$rawdate.', '.$cstrikes.'],';
    $djson.= '['.$rawdate.', '.$dstrikes.'],';
    $ejson.= '['.$rawdate.', '.$estrikes.'],';
    $fjson.= '['.$rawdate.', '.$fstrikes.'],';
    
    }

// Remove the last comma from the data and wrap it in []
$smalljson = substr($smalljson, 0, -1);
$smalljson = '['.$smalljson.']';

$totjson = substr($totjson, 0, -1);
$totjson = '['.$totjson.']';

$cjson = substr($cjson, 0, -1);
$cjson = '['.$cjson.']';
$djson = substr($djson, 0, -1);
$djson = '['.$djson.']';
$ejson = substr($ejson, 0, -1);
$ejson = '['.$ejson.']';
$fjson = substr($fjson, 0, -1);
$fjson = '['.$fjson.']';

echo '[{"a1":'.$smalljson.'},{"a2":'.$totjson.'},{"b1":'.$cjson.'},{"b2":'.$djson.'},{"b3":'.$ejson.'},{"b4":'.$fjson.'}]';

?>