Changeset 1426454
- Timestamp:
- 05/29/2016 07:46:07 PM (10 years ago)
- Location:
- raspberry-weather/trunk
- Files:
-
- 2 edited
-
functions.php (modified) (7 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
raspberry-weather/trunk/functions.php
r1343414 r1426454 4 4 * Plugin URI: www.raspberryweather.com 5 5 * Description: Easily display temperatures and humidity taken by your Raspberry Pi. 6 * Version: 1. 16 * Version: 1.4 7 7 * Author: Peter Kodermac 8 8 * Author URI: http://www.kodermac.com … … 89 89 90 90 //Create the graph 91 $whereConditions = ""; 91 92 $options[day] = esc_sql($options[day]); 92 $dateChosen = date('Y-m-d', esc_sql(strtotime($options[day]))); //what day needs to be displayed? 93 if(strpos($options[day],"Week")!==false) //current week 94 $whereConditions= "datemeasured between '".date("Y-m-d", strtotime("-1 week"))."' and '".date('Y-m-d')."'"; 95 else if(strpos($options[day],"Month")!==false) //current month 96 $whereConditions= "MONTH(datemeasured)='".date('m')."'"; 97 else 98 $whereConditions= "datemeasured='".date('Y-m-d', esc_sql(strtotime($options[day])))."'"; //what day needs to be displayed? 99 93 100 $temperatureMeasurement = esc_sql($options[temperatureMeasurement]); //celsius or fahrenheit? 94 101 $display = esc_sql($options[display]); //do we show only temp, only humidity or both? … … 97 104 //check for all types of temperature 98 105 if (strcasecmp($display, "Temperature") == 0 OR strcasecmp($display, "Temperatures") == 0 || strcasecmp($display, "Temp") == 0 || strcasecmp($display, "Temps") == 0) 99 $display = "hourMeasured, temperature ";106 $display = "hourMeasured, temperature, dateMeasured"; 100 107 101 108 else if (strcasecmp($display, "Humidity") == 0 OR strcasecmp($display, "Hum") == 0) 102 $display = "hourMeasured, humidity ";109 $display = "hourMeasured, humidity, dateMeasured"; 103 110 104 111 else … … 111 118 $displayMeasurement = "F"; 112 119 113 $resultSet = $wpdb->get_results("SELECT " . $display . " FROM temperatures WHERE dateMeasured='" . $dateChosen . "'", ARRAY_A);120 $resultSet = $wpdb->get_results("SELECT " . $display . " FROM temperatures WHERE " . $whereConditions, ARRAY_A); 114 121 115 122 … … 192 199 } 193 200 201 //graph content - readings from sensor 194 202 foreach ($resultSet as $row) { 195 203 $hourMeasured = $row['hourMeasured']; 196 if (strcmp($displayMeasurement, "C") == 0) 204 if (strcmp($displayMeasurement, "C") == 0)//display celsius 197 205 $temperature = $row['temperature']; 198 206 207 else//calculate to fahrenheit 208 $temperature = $row['temperature'] * (9 / 5) + 32; 209 210 //x axis - if weekly or monthly display selected, do not show hourMeasured but date 211 if(strpos($options[day],"Month")!==false || strpos($options[day],"Week")!==false) 212 $AxisX=date("d.m", strtotime($row['dateMeasured'])); 199 213 else 200 $ temperature = $row['temperature'] * (9 / 5) + 32;201 214 $AxisX=gmdate("H:i", ($hourMeasured * 60)); 215 202 216 if (strpos($display, "humidity") != 0) //for displaying humidity only 203 $content .= "['" . gmdate("H:i", ($hourMeasured * 60)). "'," . $row['humidity'] . "],";217 $content .= "['" . $AxisX . "'," . $row['humidity'] . "],"; 204 218 else 205 $content .= "['" . gmdate("H:i", ($hourMeasured * 60)). "'," . $temperature . "," . $row['humidity'] . "],";219 $content .= "['" . $AxisX . "'," . $temperature . "," . $row['humidity'] . "],"; 206 220 } 207 221 … … 217 231 $graph_draw_js .= 'var options = {'; 218 232 $graph_draw_js .= 'curveType: "function", '; 233 234 if($wpdb->num_rows>90) //there are more than 4 days of readings that need to be displayed 235 { 236 $graph_draw_js .= 'hAxis:{showTextEvery: 90}, '; //TODO 237 } 238 239 219 240 $graph_draw_js .= 'animation: {duration: 1200, easing:"in"}, '; 220 241 $graph_draw_js .= 'title:"' . $options['title'] . '",'; … … 230 251 if (!empty($options['v_title'])) 231 252 { 232 $resultSet =$wpdb->get_results("SELECT temperature FROM temperatures WHERE dateMeasured='" . $dateChosen . "'ORDER BY temperature ASC LIMIT 1");//get lowest temperature for chosen date253 $resultSet =$wpdb->get_results("SELECT temperature FROM temperatures WHERE " . $whereConditions . " ORDER BY temperature ASC LIMIT 1");//get lowest temperature for chosen date 233 254 $graph_draw_js .= 'vAxis: {title: "' . $options['v_title'] . '", viewWindow: {min:".$resultSet."}}'; 234 255 -
raspberry-weather/trunk/readme.txt
r1343414 r1426454 2 2 Tags: Raspberry Pi, Raspberry Weather, temperature, humidity 3 3 Requires at least: 3.0.1 4 Tested up to: 4. 4.25 Stable tag: 4. 4.24 Tested up to: 4.5.2 5 Stable tag: 4.5.2 6 6 License: GPLv2 or later 7 7 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 53 53 == Changelog == 54 54 55 = 1.4 = 56 57 Added option to display last 30 days and last 7 days in a graph 58 55 59 = 1.3 = 56 60
Note: See TracChangeset
for help on using the changeset viewer.