コード例 #1
0
ファイル: hour.php プロジェクト: Alwnikrotikz/energyathome
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;
}
コード例 #2
0
ファイル: time.php プロジェクト: Alwnikrotikz/energyathome
function updateTimeGraphTemperatureOverlay($range, $timeScale, $lastDataPoint)
{
    include 'config.php';
    include 'constants.php';
    $where = "";
    $group = getTimeSqlGroupClause($timeScale);
    $order = getTimeSqlOrderClause();
    $hourDiff = 0;
    if ($timeScale == "Hour") {
        $where = "WHERE (UNIX_TIMESTAMP(" . $DATE_TIME_FIELD_NAME . ") * 1000) >= (" . $lastDataPoint . " - (" . $SECONDS_IN_HOUR . " * " . $range . ")) AND " . $DATE_TIME_FIELD_NAME . " < ADDDATE(NOW(), INTERVAL -" . $range . " HOUR)";
        $hourDiff = $SECONDS_IN_HOUR * (int) $range;
    } elseif ($timeScale == "Day") {
        $where = "WHERE (UNIX_TIMESTAMP(" . $DATE_TIME_FIELD_NAME . ") * 1000) >= (" . $lastDataPoint . " - (" . $SECONDS_IN_DAY . " * " . $range . ")) AND " . $DATE_TIME_FIELD_NAME . " < ADDDATE(NOW(), INTERVAL -" . $range . " Day) ";
        $hourDiff = $SECONDS_IN_DAY * (int) $range;
    } elseif ($timeScale == "Week") {
        $where = "WHERE (UNIX_TIMESTAMP(" . $DATE_TIME_FIELD_NAME . ") * 1000) >= (" . $lastDataPoint . " - (" . $SECONDS_IN_WEEK . " * " . $range . ")) AND " . $DATE_TIME_FIELD_NAME . " < ADDDATE(NOW(), INTERVAL -" . $range . " Week) ";
        $hourDiff = $SECONDS_IN_WEEK * (int) $range;
    } elseif ($timeScale == "Month") {
        $where = "WHERE (UNIX_TIMESTAMP(" . $DATE_TIME_FIELD_NAME . ") * 1000) >= (" . $lastDataPoint . " - (" . $SECONDS_IN_MONTH . " * " . $range . ")) AND " . $DATE_TIME_FIELD_NAME . " < ADDDATE(NOW(), INTERVAL -" . $range . " Month)";
        $hourDiff = $SECONDS_IN_MONTH * (int) $range;
    } elseif ($timeScale == "Year") {
        $where = "WHERE (UNIX_TIMESTAMP(" . $DATE_TIME_FIELD_NAME . ") * 1000) >= (" . $lastDataPoint . " - (" . $SECONDS_IN_YEAR . " * " . $range . ")) AND " . $DATE_TIME_FIELD_NAME . " < ADDDATE(NOW(), INTERVAL -" . $range . " Year) ";
        $hourDiff = $SECONDS_IN_YEAR * (int) $range;
    } else {
        echo "";
        return;
    }
    // execute query
    $query = "SELECT (UNIX_TIMESTAMP(" . $DATE_TIME_FIELD_NAME . ") * 1000) + " . $hourDiff . ", ";
    if ($timeScale != "Hour") {
        $query .= "AVG(" . $TEMPERATURE_FIELD_NAME . ") ";
    } else {
        $query .= $TEMPERATURE_FIELD_NAME . " ";
    }
    $query .= "FROM " . $DATA_TABLE_FIELD_NAME . " " . $where . $group . $order;
    $result = executeQuery($query);
    $seriesArray = array("appId" => "ot", "label" => 'Temperature Overlay', "data" => convertResultToArray($result));
    return $seriesArray;
}