-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEcoCounterData.php
executable file
·68 lines (51 loc) · 2.05 KB
/
EcoCounterData.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
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<title>Ubi eco-counter test</title>
</head>
<body>
<?php
//get contents from oulunliikenne (bike/walk eco-counters)
echo "Eco-Counters for biking/walking:<br>";
$oulunliikenne = file_get_contents('http://www.oulunliikenne.fi/public_traffic_api/eco_traffic/eco_counters.php');
echo "<br><br>Decode the data for eco-counters:<br><br>";
//Get all eco-counters
//this could be done probably by javascript/jquery because the 3 inner foreach-loops is very heavy
$decoded = json_decode($oulunliikenne, true);
foreach($decoded as $item)
{
foreach($item as $subitem) {
//get eco-counters' id
$counterid = $subitem['id'];
echo "id: ".$counterid.", ";
//get name of the eco-counter
echo "name: ".$subitem['name'].", ";
//Geom returns coordinates in latitude and longitude
echo "geom: ".$subitem['geom'].", ";
//return the direction (keskustaan = to the oulu center / pois keskustaan = away from the oulu center)
echo "direction_name: ".$subitem['direction_name'].", ";
//type returns the type (biking/walking)
echo "type: ".$subitem['type'];
echo "<br>";
//get weekly data for each eco-counter
$getcount = file_get_contents('http://www.oulunliikenne.fi/public_traffic_api/eco_traffic/eco_counter_daydata.php?measurementPointId='.$counterid.'&daysFromHistory=7');
$ddecoded = json_decode($getcount, true);
//result title is the time of the query == current time
echo "Result title: ".$ddecoded['resultTitle'].", ";
//return this year's max data
echo "Year's max date: ".$ddecoded['yearMaxDate'].", ";
echo "Year's max weekday: ".$ddecoded['yearMaxWeekday'].", ";
echo "Year's max value: ".$ddecoded['yearMaxValue']."<br><br>";
echo "Week's amount of data:<br>";
//print the data for 1 week for each eco-counter
foreach($ddecoded['ecoCounterDayResults'] as $item) {
echo "Date: ".$item['date'].", ";
echo "Weekday: ".$item['weekday'].", ";
echo "Value: ".$item['value']."<br>";
}
echo "<br><br>";
}
}
?>
</body>
</html>