forked from Simon90/Semvis-Air
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosm_id_und_werte_f.php
189 lines (166 loc) · 4.95 KB
/
cosm_id_und_werte_f.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
//This script contains all the function necessary to get values from Cosm. Included by cosm_id_und_werte.php.
//returns all the IDs from a text in $alle. In this case $alle contains all information about a feed with the tag 'munster' (ID,Title, see http://cosm.com/docs/v2/feed/list.html for further information)
function get_ids($alle){
$temp2=explode("https://api.cosm.com/v2/feeds/",$alle);
$ids=array();
$count2=count($temp2);
for($i=0;$i<$count2;$i++){
if(strpos($temp2[$i],'.json')!==false){
$temp=explode(".json",$temp2[$i]);
array_push($ids, $temp[0]);
}
}
return $ids;
}
//returns an array. In every slot is a text in JSON format for the appropriate ID with the values from Cosm.
function get_json($ids){
$pachubes=array();
global $pachube;
$count3=count($ids);
for($i=0;$i<$count3;$i++){
$feed = $ids[$i];;
$pachub=$pachube->getFeed("json", $feed);
array_push($pachubes, $pachub);
}
//echo "<code>" . $pachubes . "</code><br/>";
return $pachubes;
}
//$json_fulltext is an array. Each slot contains the meassured values, coordinates... for one ID.
//The following two function get an array $json_fulltext and return arrays with coordinates.
function get_lat($json_fulltext){
$lat=array();
$count4=count($json_fulltext);
for($i=0;$i<$count4;$i++){
if(strpos($json_fulltext[$i],'"lat":')!==false){
$temp1=explode('"lat":',$json_fulltext[$i]);
array_push($lat, substr($temp1[1],0,16));
}
else{
array_push($lat, -1);
}
} return $lat;
}
function get_lon($json_fulltext){
$lon=array();
$count5=count($json_fulltext);
for($i=0;$i<$count5;$i++){
if(strpos($json_fulltext[$i],'"lon":')!==false){
$temp1=explode('"lon":',$json_fulltext[$i]);
array_push($lon, substr($temp1[1],0,12));
}
else{
array_push($lon, -1);
}
} return $lon;
}
//Gets and array $json_fulltext and returns an array with timestamps for every ID.
function get_timestamp($json_fulltext){
$timestamp=array();
$count6=count($json_fulltext);
for($i=0;$i<$count6;$i++){
if(strpos($json_fulltext[$i],'"at":"')!==false){
$temp1=explode('"at":"',$json_fulltext[$i]);
if(strpos($temp1[1],'","max_value"')!==false){
$temp=explode('","max_value"',$temp1[1]);
array_push($timestamp, $temp[0]);
}
else{
array_push($timestamp, -1);
}
}
else{
array_push($timestamp, -1);
}
} return $timestamp;
}
//Returns an array with NO2 values.
function get_NO2($json_fulltext){
$no2_values=array();
for($i=0;$i<count($json_fulltext);$i++){
if(strpos($json_fulltext[$i],'"id":"NO2","current_value":"')!==false){
$temp=explode('"id":"NO2","current_value":"',$json_fulltext[$i]);
$temp0=explode('","at"',$temp[1]);
array_push($no2_values, $temp0[0]);
}
else{
array_push($no2_values, -1);
}
} return $no2_values;
}
//Returns an array with O3 values.
function get_O3($json_fulltext){
$o3_values=array();
for($i=0;$i<count($json_fulltext);$i++){
if(strpos($json_fulltext[$i],'"id":"O3","current_value":"')!==false){
$temp=explode('"id":"O3","current_value":"',$json_fulltext[$i]);
$temp0=explode('","at"',$temp[1]);
array_push($o3_values, $temp0[0]);
}
else{
array_push($o3_values, -1);
}
} return $o3_values;
}
////Returns an array with humidity values.
function get_Humidity($json_fulltext){
$humidity_values=array();
for($i=0;$i<count($json_fulltext);$i++){
if(strpos($json_fulltext[$i],'"id":"humidity","current_value":"')!==false){
$temp=explode('"id":"humidity","current_value":"',$json_fulltext[$i]);
$temp1=explode('","at"',$temp[1]);
array_push($humidity_values, $temp1[0]);
}
else{
array_push($humidity_values, -1);
}
} return $humidity_values;
}
//Returns an array with CO values.
function get_CO($json_fulltext){
$co_values=array();
for($i=0;$i<count($json_fulltext);$i++){
if(strpos($json_fulltext[$i],'"id":"CO","current_value":"')!==false){
$temp=explode('"id":"CO","current_value":"',$json_fulltext[$i]);
$temp0=explode('","at"',$temp[1]);
array_push($co_values, $temp0[0]);
}
else{
array_push($co_values, -90);
}
} return $co_values;
}
//Returns an array with temperature values.
function get_Temperature($json_fulltext){
$temperature_values=array();
for($i=0;$i<count($json_fulltext);$i++){
if(strpos($json_fulltext[$i],'"id":"temperature","current_value":"')!==false){
$temp=explode('"id":"temperature","current_value":"',$json_fulltext[$i]);
$temp0=explode('","at"',$temp[1]);
array_push($temperature_values, $temp0[0]);
}
else{
array_push($temperature_values, -90);
}
} return $temperature_values;
}
function get_Name($json_fulltext){
$names=array();
for($i=0;$i<count($json_fulltext);$i++){
if(strpos($json_fulltext[$i],'"title":"')!==false){
$temp8=explode('"title":"',$json_fulltext[$i]);
$count8=count($temp8);
if(strpos($temp8[1],'","private')!==false){
$temp=explode('","private',$temp8[1]);
array_push($names, $temp[0]);
}
else{
array_push($names, '-');
}
}
else{
array_push($names, '-');
}
} return $names;
}
?>