api/
ved/
admin/
modules/
gyar/
admin/
cron/
api/gyar/weather/old.php1 lines
<?php
# latest.php
# API endpoint
# Fil för att hämta äldre väderdata från en viss mätpunkt.
require_once "gyar/modules/utility.php";
# Hämtar äldre väderdata på en viss punkt.
$functionGET = function () {
require "gyar/modules/database.php";
$pointData = $db->query(
"SELECT mp.latitude, mp.longitude FROM measuringPoint mp WHERE mp.pointId=:pointId;",
[
"pointId" => $_GET["pointId"]
]
);
$intervalData = $db->queryAll(
"SELECT UNIX_TIMESTAMP(spt.timestamp) AS 'timestamp', wd.temperature, wd.humidity, wd.airPressure, wd.downfall, wd.windSpeed, wd.windDirection FROM measuringPoint mp JOIN stationPointInstance sp ON sp.pointId = mp.pointId JOIN weatherStation ws on sp.stationId = ws.stationId JOIN stationPointTimeData spt ON spt.stationPointInstanceId = sp.stationPointInstanceId JOIN weatherData wd ON wd.stationPointDataId = spt.stationPointDataId WHERE mp.pointId=:pointId AND spt.timestamp BETWEEN :date1 AND :date2 ORDER BY spt.timestamp ASC;",
[
"pointId" => $_GET["pointId"],
"date1" => $_GET["date1"],
"date2" => $_GET["date2"]
]
);
$returnData = [
"latitude" => $pointData["latitude"],
"longitude" => $pointData["longitude"],
"data" => []
];
foreach ($intervalData as $dateData) {
array_push($returnData["data"], [
"timestamp" => $dateData["timestamp"],
"data" => [
"temperature" => $dateData["temperature"],
"humidity" => $dateData["humidity"],
"airPressure" => $dateData["airPressure"],
"downfall" => $dateData["downfall"],
"windSpeed" => $dateData["windSpeed"],
"windDirection" => $dateData["windDirection"],
],
]);
}
return $returnData;
};
$api = new APIEndpoint();
$httpGET = new APIMethod("GET", $functionGET);
$httpGET->setRequiredGETParameters(["pointId", "date1", "date2"]);
$api->addMethod($httpGET);
return $api;
?>