|
|
@ -127,7 +127,46 @@ function makeMarker(int $id){ // generate appropriate markers based on latest JS |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function appendJSON($filename, $data){ // create historical json data for documentation over time |
|
|
|
|
|
|
|
// read the file if present |
|
|
|
$handle = @fopen($filename, 'r+'); |
|
|
|
|
|
|
|
// create the file if needed |
|
|
|
if ($handle === null) |
|
|
|
{ |
|
|
|
$handle = fopen($filename, 'w+'); |
|
|
|
} |
|
|
|
|
|
|
|
if ($handle) |
|
|
|
{ |
|
|
|
// seek to the end |
|
|
|
fseek($handle, 0, SEEK_END); |
|
|
|
|
|
|
|
// are we at the end of is the file empty |
|
|
|
if (ftell($handle) > 0) |
|
|
|
{ |
|
|
|
// move back a byte |
|
|
|
fseek($handle, -1, SEEK_END); |
|
|
|
|
|
|
|
// add the trailing comma |
|
|
|
fwrite($handle, ',', 1); |
|
|
|
|
|
|
|
// add the new json string |
|
|
|
fwrite($handle, json_encode($data) . ']'); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// write the first event inside an array |
|
|
|
fwrite($handle, json_encode(array($data))); |
|
|
|
} |
|
|
|
|
|
|
|
// close the handle on the file |
|
|
|
fclose($handle); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// make date time file------ |
|
|
@ -249,14 +288,18 @@ function callAPI($url){ |
|
|
|
map.addLayer(Stamen_Toner); |
|
|
|
|
|
|
|
|
|
|
|
//for each scooter in $scooters array, request status and construct marker |
|
|
|
//the magic: for each scooter in $scooters array, request status and construct marker |
|
|
|
<?php |
|
|
|
|
|
|
|
$filename = "./latestData.json"; |
|
|
|
$filename = "./latestData.json"; //latest locations, 1 entry per scooter |
|
|
|
$filename_history = "./historicalData.json"; //historical locations |
|
|
|
|
|
|
|
// check how old the latest json is |
|
|
|
if (time()-filemtime($filename) > 60) { |
|
|
|
$arrayToEcho = saveLatestJSON(); |
|
|
|
if (time()-filemtime($filename) > 60) { //if older than 60 seconds |
|
|
|
$arrayToEcho = saveLatestJSON(); |
|
|
|
//append to historical json |
|
|
|
appendJSON($filename_history, $arrayToEcho); |
|
|
|
|
|
|
|
$latestData = json_encode($arrayToEcho, JSON_FORCE_OBJECT); // force object accepts 0 as a key for the array and not NULL |
|
|
|
file_put_contents($filename, $latestData, LOCK_EX); |
|
|
|
|
|
|
|