Ejemplo n.º 1
0
function hourGraphEnergy($timeScale)
{
    include 'config.php';
    include 'general.php';
    // Get all the appliances to retrieve data for
    $applianceChannels = getDeviceChannels();
    $applianceArray = array();
    $count = 0;
    // Array to store the number channels each appliance has
    //$applianceChannelCount = countChannelsPerAppliance($applianceChannels);
    // Loop through results again to build data to be returned
    while ($row = mysql_fetch_array($applianceChannels)) {
        $where = getHourSqlWhereClause($row[$CHANNEL_ID_PK_FIELD_NAME], $timeScale);
        $group = getHourSqlGroupByClause();
        $query = "SELECT HOUR(" . $DATE_TIME_FIELD_NAME . "), AVG(" . $DATA_FIELD_NAME . "), " . $UNIT_FIELD_NAME . " " . "FROM " . $DATA_TABLE_FIELD_NAME . " " . $where . $group;
        $result = executeQuery($query);
        $seriesArray = array("chId" => $row[$CHANNEL_ID_PK_FIELD_NAME], "label" => $row[$APPLIANCE_DISPLAY_NAME_FIELD_NAME], "color" => $count, "data" => convertResultToArray($result));
        array_push($applianceArray, $seriesArray);
        $count++;
        // Ensure 1 is always the temperature colour because it's blue
        if ($count == 1) {
            $count++;
        }
    }
    return $applianceArray;
}
Ejemplo n.º 2
0
function updateTimeGraphEnergy($range, $timeScale)
{
    include 'config.php';
    include 'general.php';
    // Get all the appliances to retrieve data for
    $applianceChannels = getDeviceChannels();
    $applianceArray = array();
    while ($row = mysql_fetch_array($applianceChannels)) {
        // Check if the appliance last datapoint was passed
        if (isset($_GET["lastEnergyDataPoint_" . $row[$CHANNEL_ID_PK_FIELD_NAME]])) {
            $lastDataPoint = $_GET["lastEnergyDataPoint_" . $row[$CHANNEL_ID_PK_FIELD_NAME]];
            $where = updateSqlWhereClause($row[$CHANNEL_ID_PK_FIELD_NAME], $lastDataPoint);
            $group = getTimeSqlGroupClause($timeScale);
            $order = getTimeSqlOrderClause();
            $query = "SELECT UNIX_TIMESTAMP(" . $DATE_TIME_FIELD_NAME . ") * 1000, ";
            /* Only average data if time frame is not for an hour.
             * Hour times return raw data and therefore are not grouped
             * and averaged to reduce data when AJAX 'GET' request is sent
             */
            if ($timeScale != "Hour") {
                $query .= "AVG(" . $DATA_FIELD_NAME . ")";
            } else {
                $query .= $DATA_FIELD_NAME;
            }
            $query .= ", " . $UNIT_FIELD_NAME . " FROM " . $DATA_TABLE_FIELD_NAME . $where . $group . $order;
            $result = executeQuery($query);
            $seriesArray = array("chId" => $row[$CHANNEL_ID_PK_FIELD_NAME], "data" => convertResultToArray($result));
            array_push($applianceArray, $seriesArray);
        }
    }
    return $applianceArray;
}