Plugin Directory

Changeset 1426454


Ignore:
Timestamp:
05/29/2016 07:46:07 PM (10 years ago)
Author:
peterkodermac
Message:

display week and month readings

Location:
raspberry-weather/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • raspberry-weather/trunk/functions.php

    r1343414 r1426454  
    44 * Plugin URI: www.raspberryweather.com
    55 * Description: Easily display temperatures and humidity taken by your Raspberry Pi.
    6  * Version: 1.1
     6 * Version: 1.4
    77 * Author: Peter Kodermac
    88 * Author URI: http://www.kodermac.com
     
    8989   
    9090    //Create the graph
     91    $whereConditions    = "";
    9192    $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   
    93100    $temperatureMeasurement = esc_sql($options[temperatureMeasurement]); //celsius or fahrenheit?
    94101    $display                = esc_sql($options[display]); //do we show only temp, only humidity or both?
     
    97104    //check for all types of temperature
    98105    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";
    100107   
    101108    else if (strcasecmp($display, "Humidity") == 0 OR strcasecmp($display, "Hum") == 0)
    102         $display = "hourMeasured, humidity";
     109        $display = "hourMeasured, humidity, dateMeasured";
    103110   
    104111    else
     
    111118        $displayMeasurement = "F";
    112119   
    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);
    114121   
    115122   
     
    192199    }
    193200   
     201    //graph content - readings from sensor
    194202    foreach ($resultSet as $row) {
    195203        $hourMeasured = $row['hourMeasured'];
    196         if (strcmp($displayMeasurement, "C") == 0)
     204        if (strcmp($displayMeasurement, "C") == 0)//display celsius
    197205            $temperature = $row['temperature'];
    198206       
     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']));
    199213        else
    200             $temperature = $row['temperature'] * (9 / 5) + 32;
    201        
     214            $AxisX=gmdate("H:i", ($hourMeasured * 60));
     215
    202216        if (strpos($display, "humidity") != 0) //for displaying humidity only
    203             $content .= "['" . gmdate("H:i", ($hourMeasured * 60)) . "'," . $row['humidity'] . "],";
     217            $content .= "['" . $AxisX . "'," . $row['humidity'] . "],";
    204218        else
    205             $content .= "['" . gmdate("H:i", ($hourMeasured * 60)) . "'," . $temperature . "," . $row['humidity'] . "],";
     219            $content .= "['" . $AxisX . "'," . $temperature . "," . $row['humidity'] . "],";
    206220    }
    207221   
     
    217231    $graph_draw_js .= 'var options = {';
    218232    $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
    219240    $graph_draw_js .= 'animation: {duration: 1200, easing:"in"}, ';
    220241    $graph_draw_js .= 'title:"' . $options['title'] . '",';
     
    230251    if (!empty($options['v_title']))
    231252    {
    232         $resultSet =$wpdb->get_results("SELECT temperature FROM temperatures WHERE dateMeasured='" . $dateChosen . "' ORDER BY temperature ASC LIMIT 1");//get lowest temperature  for chosen date
     253        $resultSet =$wpdb->get_results("SELECT temperature FROM temperatures WHERE " . $whereConditions . " ORDER BY temperature ASC LIMIT 1");//get lowest temperature  for chosen date
    233254        $graph_draw_js .= 'vAxis: {title: "' . $options['v_title'] . '", viewWindow: {min:".$resultSet."}}';
    234255   
  • raspberry-weather/trunk/readme.txt

    r1343414 r1426454  
    22Tags: Raspberry Pi, Raspberry Weather, temperature, humidity
    33Requires at least: 3.0.1
    4 Tested up to: 4.4.2
    5 Stable tag: 4.4.2
     4Tested up to: 4.5.2
     5Stable tag: 4.5.2
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5353== Changelog ==
    5454
     55= 1.4 =
     56
     57Added option to display last 30 days and last 7 days in a graph
     58
    5559= 1.3 =
    5660
Note: See TracChangeset for help on using the changeset viewer.