-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwd_geo_test.php
59 lines (48 loc) · 2.04 KB
/
dwd_geo_test.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
<?php
use FWidm\DWDHourlyCrawler\DWDLib;
use FWidm\DWDHourlyCrawler\Hourly\Variables\DWDHourlyParameters;
use FWidm\DWDHourlyCrawler\Model\DWDCompactParameter;
use FWidm\DWDHourlyCrawler\Transformer\CompactParameterTransformer;
use FWidm\DWDHourlyCrawler\Transformer\ParameterTransformer;
use FWidm\DWDHourlyCrawler\Transformer\StationTransformer;
use FWidm\DWDHourlyCrawler\Util\FractalWrapper;
use League\Fractal\Manager;
use League\Fractal\Serializer\ArraySerializer;
use Location\Coordinate;
use Location\Formatter\Coordinate\GeoJSON;
use Carbon\Carbon;
require 'vendor/autoload.php';
function prettyPrint($obj)
{
echo "<pre>";
print_r($obj);
echo "</pre>";
}
$coordinates = new Coordinate(48.398400, 9.091550);
$date = Carbon::parse('2017-09-17 00:01:00');
$date = Carbon::instance($date)->setTimezone('utc');;
prettyPrint("Checking for Coordinates: " . $coordinates->format(new GeoJSON()) . ", @ " . $date->format(DateTime::ATOM));
$dwdLib = new DWDLib("storage");
$requestParams = new DWDHourlyParameters();
$requestParams->addAirTemperature()->addCloudiness()->addPrecipitation()->addPressure()->addSoilTemperature()->addSun()->addWind()/*->add...*/;
[$param,$stations] = $dwdLib->getHourlyInInterval($requestParams, $date, $coordinates->getLat(), $coordinates->getLng());
/*
* Print all retrieved items in the 'values' part => weather parameters as json
*/
foreach ($param as $key => $obj) {
print "obj=$key - ".count($obj)."<br>";
$collection=FractalWrapper::toResource($obj,new ParameterTransformer());
prettyPrint(FractalWrapper::toJson($collection,JSON_PRETTY_PRINT));
}
/*
* Print all stations as json
*/
foreach ($stations as $key => $obj) {
print "obj=$key<br>";
/* @var $obj \FWidm\DWDHourlyCrawler\Model\DWDStation */
prettyPrint(FractalWrapper::toJson(FractalWrapper::toResource($obj,new StationTransformer()),JSON_PRETTY_PRINT));
}
print "<hr>";
$dwdCompact = new DWDCompactParameter(1, ["a" => "b"], "none", 100.3, 10, 20, Carbon::now(), 2030.45, "x");
var_dump($dwdCompact);
prettyPrint(json_encode($dwdCompact));