This repository was archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweatherarray.php
More file actions
507 lines (351 loc) · 19.2 KB
/
weatherarray.php
File metadata and controls
507 lines (351 loc) · 19.2 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<?php
// THIS FILE IS MAINLY USED FOR SETTING UP THE WEATHERARRAY AND GETTING AND SETTING OUR INITIAL VARIABLES THROUGHOUT THE WEB APPLICATION. INCLUDE FILES AND FUNCTIONS DO MOST OF THE DIRTY WORK.
function weathersetup($weatherperiod) {
$weatherperiod;
$websiteFolder = $_SERVER['DOCUMENT_ROOT'];
$options = get_option('wviewforwp_options');
$weatherArray['wordpressFolder'] = WVIEWFORWP_PATH;
//$jpgraphImages = $options['jpgraphimages']; //Where to put JPGraph Images Old Support for JPGraph Library removed.
$wviewparamslist = $options['paramFile']; //Location of PHP Parameter File from WP Options
$wviewparamslist = (ABSPATH . $wviewparamslist);
$webServerTime = $options['webTime']; //Web Server Timezone from WP Options
$timeOffsetSymbol = $options['wviewTime']; //Wview Weather Station Timezone from WP Options
//Now Database Options (Which are optional so may or may not have anything to use.
$wviewdbtoggle = $options['wviewdbtoggle']; // Is the DB Being used or not.
$userdbTableName = $options['mysqltable']; //Wview mySQL Table Name
$weatherArray['dbtableName'] = $userdbTableName; //This sets the name of the database table you are using
$mysqlpass = $options['mysqlpass'];
$mysqluser = $options['mysqluser'];
$mysqldbname = $options['mysqldbname'];
$mysqlhost = $options['mysqlhost'];
$sensors = $options['wviewsensors']; //What Sensors are you using?
$currentSys = $options['currentSys'];
// NOW WE GET THE FIRST DATA ---- THIS IS FROM THE PARAMETER FILE GENERATED BY WVIEW
/*** Grabbing 1 Minute Data from file ****/
$weatherdatalist = fopen($wviewparamslist, "r");
$weatherdatainitial = fgetcsv($weatherdatalist, 100000, ";");
$i = 0;
foreach($weatherdatainitial as $val) {
if($i % 2) {
$weatherArray[$previousval] = $val;
//echo $previousval;
//echo $weatherArray[$previousval];
//echo $val;
//echo ';';
}
else {
$previousval = $val;
//echo $val;
//echo'->';
}
$i++;
}
date_default_timezone_set($webServerTime);
$filemodtime = date("U", filemtime($wviewparamslist)); //Get File modification time to check with current time in seconds since EPOCH
$currenttime = date("U"); // Sets the current time for comparison to uploaded file to catch delays in seconds since EPOCH.
$timedif = round((($currenttime - $filemodtime) / 60)); // The difference in minutes
$timeZoneServer = new DateTimeZone($webServerTime);
$timeZoneServerNow = new DateTime("now", $timeZoneServer);
$timeZoneLocal = new DateTimeZone($timeOffsetSymbol);
$timeZoneLocalNow = new DateTime("now", $timeZoneLocal);
$timeOffsetServerNum = $timeZoneServerNow->getOffset();
$timeOffsetServerNum = $timeOffsetServerNum / 3600;
$timeOffsetNum = $timeZoneLocalNow->getOffset();
$timeOffsetNum = $timeOffsetNum / 3600;
// Get Difference in Offets between Server and Weather
$timeServerOffsetNum = abs($timeOffsetNum) - abs($timeOffsetServerNum);
// Now get the Plus or Minus value of the weather station offset....
if ($timeOffsetNum >= 0){
$timeOffsetSign = '+';
}
else {
$timeOffsetSign = '-';
}
//$timeServerOffsetNum = 3; //Hours Difference from your Server
//Now we're checking to make sure nothing is delayed...
$weatherArray['timedif'] = $timedif;
$timedelay = $options['timedelay'];
if ($weatherArray['timedif'] > $timedelay) {
$weatherArray['delayed'] = TRUE;
}
else {
$weatherArray['delayed'] = FALSE;
}
// NOW THAT WE HAVE DATA WE CAN START DOING STUFF. LETS GET ALL THE FILES
require($weatherArray['wordpressFolder'] . 'include/php/includefiles.inc.php');
// Now populate the array with the SQL table rows:
$weatherArray['archiveTableArray'] = array('dateTime' => 'dateTime' ,'usUnits' => 'usUnits','arcInt' => 'arcInt','barometer' => 'barometer','pressure' => 'pressure','altimeter'=>'altimeter','inTemp' => 'inTemp','outTemp' => 'outTemp','inHumidity'=>'inHumidity','outHumidity'=>'outHumidity','windSpeed'=>'windSpeed','windDir'=>'windDir','windGust'=>'windGust','windGustDir'=>'windGustDir','rainRate'=>'rainRate','rain'=>'rain','dewpoint'=>'dewpoint','windchill'=>'windchill','heatindex'=>'heatindex','ET'=>'ET','radiation'=>'radiation','UV'=>'UV','extraTemp1'=>'extraTemp1','extraTemp2'=>'extraTemp2','extraTemp3'=>'extraTemp3','soilTemp1'=>'soilTemp1','soilTemp2'=>'soilTemp2','soilTemp3'=>'soilTemp3','soilTemp4'=>'soilTemp4','leafTemp1'=>'leafTemp1','leafTemp2'=>'leafTemp2','extraHumid1'=>'extraHumid1','extraHumid2'=>'extraHumid2','soilMoist1'=>'soilMoist1','soilMoist2'=>'soilMoist2','soilMoist3'=>'soilMoist3','soilMoist4'=>'soilMoist4','leafWet1'=>'leafWet1','leafWet2'=>'leafWet2','rxCheckPercent'=>'rxCheckPercent','txBatteryStatus'=>'txBatteryStatus','consBatteryVoltage'=>'consBatteryVoltage','hail'=>'hail','hailRate'=>'hailRate','heatingTemp'=>'heatingTemp','heatingVoltage'=>'heatingVoltage','supplyVoltage'=>'supplyVoltage','referenceVoltage'=>'referenceVoltage','windBatteryStatus'=>'windBatteryStatus','rainBatteryStatus'=>'rainBatteryStatus','outTempBatteryStatus'=>'outTempBatteryStatus','inTempBatteryStatus'=>'inTempBatteryStatus','tableoutTemp'=>'outTemp','tablebaromPressure'=>'baromPressure','tabledewpoint'=>'dewPoint','tableET'=>'ET','tableheatIndex'=>'heatIndex','tableinHumidity'=>'inHumidity','tableinTemp'=>'inTemp','tableoutHumidity'=>'outHumidity','tablerain'=>'rain','tablerainRate'=>'rainRate','tablesolarRadiation'=>'solarRadiation','tableUV'=>'UV','tablewindchill'=>'windChill','tablewindDir'=>'windDir','tablewindGust'=>'windGust','tablewindSpeed'=>'windSpeed', 'timeHigh'=>'timeHigh', 'timeLow'=>'timeLow');
//Now we'll stick everything in the array... eventually we're going to make more than one array so that we can be a little smarter about this.
$weatherArray['timeOffsetSymbol'] = $timeOffsetSymbol;
$weatherArray['sensors'] = $sensors;
$weatherArray['timeOffsetSymbol'] = $timeOffsetSymbol;
if ($timeOffsetSign == '+') {
$weatherArray['mySQLDateMod'] = 'DATE_ADD';
}
else {
$weatherArray['mySQLDateMod'] = 'DATE_SUB';
}
$weatherArray['timeOffsetSign'] = $timeOffsetSign;
$weatherArray['timeOffsetNum'] = $timeOffsetNum;
$weatherArray['timeServerOffsetNum'] = $timeServerOffsetNum;
$weatherArray['timeOffsetUnixNum'] = 3600 * $weatherArray['timeOffsetNum'];
$weatherArray['timeServerOffsetUnixNum'] = 3600 * $weatherArray['timeServerOffsetNum'];
$weatherArray['offset'] = $weatherArray['timeOffsetSign'] . $weatherArray['timeOffsetNum'];
$weatherArray['UnixOffset'] = $timeOffsetSign . $weatherArray['timeOffsetUnixNum'];
$weatherArray['filemodtime'] = $filemodtime;
$weatherArray['currenttime'] = $currenttime;
date_default_timezone_set($timeOffsetSymbol);
//Now We'll check what time period we will be running. Default is 24hr values but there are also weekly, monthly, yearly and Custom
$weatherArray['weatherperiod'] = $weatherperiod;
if ($weatherArray['sensors'] == 0){ //Checking for Standard vs. Extended sensors/mode...
//0 is standard (no UV, Solar, leaf or soil sensors).
//echo 'standard';
if ($wviewdbtoggle == 1) { // CHECKING TO SEE IF THE DATABASE OPTION IS CHECKED
//echo 'db on';
$weatherArray = dbstandardrun($weatherArray); //LOTS TO DO HERE in dbrun.inc.php
}//END DATABASE CHECK
}// END SENSORS 0 IF
else { // Otherwise Sensors is 1 so include Extended functions
//echo 'extended';
if ($wviewdbtoggle == 1) { //CHECK FOR THE DB AGAIN
//echo 'db on';
$weatherArray = dbextendedrun($weatherArray); //LOTS TO DO HERE in dbrun.inc.php
}
//$weatherArray = dayTempChillHeat($weatherArray);
}// END OF SENSORS 1
/**************************** END OF DATABASE QUERY SECTION *******************/
switch ($currentSys) {
/**First We'll set the units we want for the System selected Canadian Metric is first, this does not affect "default" which is set in the header. For each system, we make the necessary entries in the Array for the Units... then we do any conversions we need to do. **/
case '1': //Canadian Metric Units (Default)
// First do the Units
$weatherArray['tempUnit'] = $TempUnits[0];
$weatherArray['humUnit'] = $HumidUnits[0];
$weatherArray['rainUnit'] = $RainUnits[0];
$weatherArray['rateUnit'] = $RainRateUnits[0];
$weatherArray['windUnit'] = $WindUnits[1];
$weatherArray['cumulusBaseUnit'] = $DistanceUnits[0];
$weatherArray['barUnit'] = $BaromUnits[0];
$weatherArray['airDensityUnit'] = $AirDensityUnit[0];
$weatherArray['solarUnit'] = $SolarUnit[0];
$weatherArray['windPowerUnit'] = $WindPowerUnit[0];
$weatherArray['windRunUnit'] = $DistanceUnits[5];
$weatherArray['Sys'] = $UnitsSystem[0];
//Wind Power Density Calculations
$weatherArray = calculateWindPowerDensity($weatherArray);
//Wind Power Density Calculations
$weatherArray = calcSolarPotential($weatherArray);
//Calculate Freezing Level first before any temp conversions
$weatherArray = calculateFreezingLevel($weatherArray);
$weatherArray = setcssalert($weatherArray);
//Now Starting to Convert values...
//Barometer Conversions
$weatherArray = convertdataBaromtokPa($weatherArray, 1);
//CumulusBase Conversion - And Calculation for Non-Working in WView 3.3
$weatherArray = cumulusBase($weatherArray);
$weatherArray = convertdataftttometer($weatherArray);
//Check Chill/Heat
$weatherArray = hidechillheat($weatherArray);
//Change Times
$weatherArray = OFFSETtimes($weatherArray);
break;
case '2': //Defining US Imperial System Units
$weatherArray = setcssalert($weatherArray);
$weatherArray['tempUnit'] = $TempUnits[1];
$weatherArray['humUnit'] = $HumidUnits[0];
$weatherArray['rainUnit'] = $RainUnits[2];
$weatherArray['rateUnit'] = $RainRateUnits[2];
$weatherArray['windUnit'] = $WindUnits[2];
$weatherArray['cumulusBaseUnit'] = $DistanceUnits[3];
$weatherArray['barUnit'] = $BaromUnits[3];
$weatherArray['airDensityUnit'] = $AirDensityUnit[1];
$weatherArray['solarUnit'] = $SolarUnit[1];
$weatherArray['windPowerUnit'] = $WindPowerUnit[1];
$weatherArray['windRunUnit'] = $DistanceUnits[1];
$weatherArray['Sys'] = $UnitsSystem[3];
//Wind Power Density Calculations
$weatherArray = calculateWindPowerDensity($weatherArray);
//Wind Power Density Calculations
$weatherArray = calcSolarPotential($weatherArray);
//Calculate Freezing Level first before any temp conversions
$weatherArray = calculateFreezingLevel($weatherArray);
$weatherArray = setcssalert($weatherArray);
//Now Starting to Convert values...
//Cloud Base Conversion Must come before any temp or dew conversions because it is calculated independant of wview data due to bug in wview 3.3
$weatherArray = cumulusBase($weatherArray);
//Wind Power Density Calculations
$weatherArray = calculateWindPowerDensity($weatherArray);
//Calculate Freezing Level first before any temp conversions
$weatherArray = calculateFreezingLevel($weatherArray);
//Temperature/Dew/Chill/Heat Conversions
$weatherArray = convertdataCtoF($weatherArray);
//Barometer Conversions
$weatherArray = convertdataBaromtoInch($weatherArray, 1);
//Rain Conversions
$weatherArray = convertdataMMtoInch($weatherArray);
//Wind Conversions
$weatherArray = convertdatakphtomph($weatherArray);
//WindRun Conversions
$weatherArray = convertdatakmttomiles($weatherArray);
//Air Density Conversion
$weatherArray = convertdatakgtolbs($weatherArray);
//CloudBase Meters conversion
$weatherArray = convertdatameterttoft($weatherArray);
//Watts per Meter to Inch
$weatherArray = convertdatawattMetertoft($weatherArray);
//Check Chill/Heat
$weatherArray = hidechillheat($weatherArray);
//Change Times
$weatherArray = OFFSETtimes($weatherArray);
break;
case '3': //Defining UK Metric System Units
$weatherArray = setcssalert($weatherArray);
$weatherArray['tempUnit'] = $TempUnits[0];
$weatherArray['humUnit'] = $HumidUnits[0];
$weatherArray['rainUnit'] = $RainUnits[0];
$weatherArray['rateUnit'] = $RainRateUnits[0];
$weatherArray['windUnit'] = $WindUnits[2];
$weatherArray['cumulusBaseUnit'] = $DistanceUnits[3];
$weatherArray['barUnit'] = $BaromUnits[2];
$weatherArray['airDensityUnit'] = $AirDensityUnit[1];
$weatherArray['solarUnit'] = $SolarUnit[0];
$weatherArray['windPowerUnit'] = $WindPowerUnit[0];
$weatherArray['windRunUnit'] = $DistanceUnits[1];
$weatherArray['Sys'] = $UnitsSystem[4];
//Wind Power Density Calculations
$weatherArray = calculateWindPowerDensity($weatherArray);
//Wind Power Density Calculations
$weatherArray = calcSolarPotential($weatherArray);
//Calculate Freezing Level first before any temp conversions
$weatherArray = calculateFreezingLevel($weatherArray);
$weatherArray = setcssalert($weatherArray);
//Cloud Base Conversion Must come before any temp or dew conversions
$weatherArray = cumulusBase($weatherArray);
//Calculate Freezing Level first before any temp conversions
$weatherArray = calculateFreezingLevel($weatherArray);
//Wind Power Density Calculations
$weatherArray = calculateWindPowerDensity($weatherArray);
//Now Starting to Convert values...
//Wind Conversions
$weatherArray = convertdatakphtomph($weatherArray);
//Air Density Conversion
$weatherArray = convertdatakgtolbs($weatherArray);
//WindRun Conversions
$weatherArray = convertdatakmttomiles($weatherArray);
$weatherArray = convertdataBaromtokPa($weatherArray, 0); //Don't actually need any conversion... but will run it through anyway to strip out the automatic barometer trend.
//CloudBase Meters conversion
$weatherArray = convertdatameterttoft($weatherArray);
//Check Chill/Heat
$weatherArray = hidechillheat($weatherArray);
//Change Times
$weatherArray = OFFSETtimes($weatherArray);
break;
case '4': //Defining Nautical System Units
$weatherArray = setcssalert($weatherArray);
$weatherArray['tempUnit'] = $TempUnits[0];
$weatherArray['humUnit'] = $HumidUnits[0];
$weatherArray['rainUnit'] = $RainUnits[0];
$weatherArray['rateUnit'] = $RainRateUnits[0];
$weatherArray['windUnit'] = $WindUnits[4];
$weatherArray['cumulusBaseUnit'] = $DistanceUnits[3];
$weatherArray['barUnit'] = $BaromUnits[2];
$weatherArray['airDensityUnit'] = $AirDensityUnit[1];
$weatherArray['solarUnit'] = $SolarUnit[0];
$weatherArray['windPowerUnit'] = $WindPowerUnit[0];
$weatherArray['windRunUnit'] = $DistanceUnits[4];
$weatherArray['Sys'] = $UnitsSystem[2];
//Wind Power Density Calculations
$weatherArray = calculateWindPowerDensity($weatherArray);
//Wind Power Density Calculations
$weatherArray = calcSolarPotential($weatherArray);
//Calculate Freezing Level first before any temp conversions
$weatherArray = calculateFreezingLevel($weatherArray);
$weatherArray = setcssalert($weatherArray);
//Cloud Base Conversion Must come before any temp or dew conversions because it is calculated independant of wview data due to bug in wview 3.3
$weatherArray = cumulusBase($weatherArray);
//Calculate Freezing Level first before any temp conversions
$weatherArray = calculateFreezingLevel($weatherArray);
//Wind Power Density Calculations
$weatherArray = calculateWindPowerDensity($weatherArray);
//Wind Conversions
$weatherArray = convertdatakphtoknot($weatherArray);
//Air Density Conversion
$weatherArray = convertdatakgtolbs($weatherArray);
//WindRun Conversions
$weatherArray = convertdatakmttonautmiles($weatherArray);
//Barometer Conversion
$weatherArray = convertdataBaromtokPa($weatherArray, 0); //Don't actually need any conversion... but will run it through anyway to strip out the automatic barometer trend.
//CloudBase Meters conversion
$weatherArray = convertdatameterttoft($weatherArray);
//Check Chill/Heat
$weatherArray = hidechillheat($weatherArray);
//Change Times
$weatherArray = OFFSETtimes($weatherArray);
break;
case '5': //Defining European Metric System Units
$weatherArray = setcssalert($weatherArray);
$weatherArray['tempUnit'] = $TempUnits[0];;
$weatherArray['humUnit'] = $HumidUnits[0];
$weatherArray['rainUnit'] = $RainUnits[0];
$weatherArray['rateUnit'] = $RainRateUnits[0];
$weatherArray['windUnit'] = $WindUnits[1];
$weatherArray['cumulusBaseUnit'] = $DistanceUnits[0];
$weatherArray['windRunUnit'] = $DistanceUnits[5];
$weatherArray['barUnit'] = $BaromUnits[1];
$weatherArray['airDensityUnit'] = $AirDensityUnit[0];
$weatherArray['solarUnit'] = $SolarUnit[0];
$weatherArray['windPowerUnit'] = $WindPowerUnit[0];
$weatherArray['Sys'] = $UnitsSystem[1];
//Solar Power Density Calculations
$weatherArray = calcSolarPotential($weatherArray);
$weatherArray = setcssalert($weatherArray);
//Cloud Base Conversion
$weatherArray = cumulusBase($weatherArray);
//Wind Power Density Calculations
$weatherArray = calculateWindPowerDensity($weatherArray);
//Calculate Freezing Level first before any temp conversions
$weatherArray = calculateFreezingLevel($weatherArray);
$weatherArray = convertdataftttometer($weatherArray);
$weatherArray = convertdataBaromtokPa($weatherArray, 0); //Don't actually need any conversion... but will run it through anyway to strip out the automatic barometer trend.
//Check Chill/Heat
$weatherArray = hidechillheat($weatherArray);
//Change Times
$weatherArray = OFFSETtimes($weatherArray);
break;
case '6': //Defining Scientific Metric System Units
$weatherArray = setcssalert($weatherArray);
$weatherArray['tempUnit'] = $TempUnits[0];;
$weatherArray['humUnit'] = $HumidUnits[0];
$weatherArray['rainUnit'] = $RainUnits[0];
$weatherArray['rateUnit'] = $RainRateUnits[0];
$weatherArray['windUnit'] = $WindUnits[0];
$weatherArray['cumulusBaseUnit'] = $DistanceUnits[0];
$weatherArray['windRunUnit'] = $DistanceUnits[5];
$weatherArray['barUnit'] = $BaromUnits[1];
$weatherArray['airDensityUnit'] = $AirDensityUnit[0];
$weatherArray['solarUnit'] = $SolarUnit[0];
$weatherArray['windPowerUnit'] = $WindPowerUnit[0];
$weatherArray['Sys'] = $UnitsSystem[1];
//Cloud Base Conversion Must come before any temp or dew conversions because it is calculated independant of wview data due to bug in wview 3.3
$weatherArray = cumulusBase($weatherArray);
//Calculate Freezing Level first before any temp conversions
$weatherArray = calculateFreezingLevel($weatherArray);
//Wind Power Density Calculations
$weatherArray = calculateWindPowerDensity($weatherArray);
//Wind Power Density Calculations
$weatherArray = calcSolarPotential($weatherArray);
$weatherArray = setcssalert($weatherArray);
//Wind Conversions
$weatherArray = convertdatakphtomps($weatherArray);
$weatherArray = convertdataBaromtokPa($weatherArray, 0); //Don't actually need any conversion... but will run it through anyway to strip out the automatic barometer trend.
//Cloud Base and Meter to Foot Conversion
$weatherArray = convertdataftttometer($weatherArray);
//Check Chill/Heat
$weatherArray = hidechillheat($weatherArray);
//Change Times
$weatherArray = OFFSETtimes($weatherArray);
break;
}
//} //END OF USER DATABASE CHECKBOX OPTION
return $weatherArray;
} //END Weathersetup function
?>