function viewReports($userID, $domainID) { $viewReports = ""; $chart = ''; $statistics = ""; $chartSeriesData = ''; $chartGraphData = ''; $chartData = ''; $showChart = false; $gid = 0; $valueRotation = 0; $graphSettings = ''; $labelFreq = '1'; $gridCount = '4'; $settingsString = ''; $aryColors = array(1 => '#1B6097', 2 => '#7C1787', 3 => '#874417', 4 => '#228717', 5 => '#207DBC', 6 => '#BC5E20', 7 => '#17877C', 8 => '#871722', 9 => '#172287', 10 => '#87175A', 11 => '#877C17', 12 => '#178744', 13 => '#441787', 14 => '#5A8717', 15 => '#3B9DDE', 16 => '#DE7C3B'); $aryColorPairs = array(1 => '#1B6097', 2 => '#2994DB', 3 => '#7C1787', 4 => '#C929DB', 5 => '#874417', 6 => '#DB7029', 7 => '#228717', 8 => '#3BDB29', 9 => '#207DBC', 10 => '#5EAEE4', 11 => '#BC5E20', 12 => '#E4935E', 13 => '#17877C', 14 => '#29DBC9', 15 => '#871722', 16 => '#DB293B', 17 => '#172287', 18 => '#293BDB', 19 => '#87175A', 20 => '#DB2994', 21 => '#877C17', 22 => '#DBC929', 23 => '#178744', 24 => '#29DB70', 25 => '#441787', 26 => '#7029DB', 27 => '#5A8717', 28 => '#94DB29', 29 => '#3B9DDE', 30 => '#92C8ED', 31 => '#DE7C3B', 32 => '#EDB692'); $aryUnits = array('KWh' => 'KW', 'kVarh' => 'kVar'); $reports = new Reports(); $userObject = clone $_SESSION['UserObject']; if (!isset($_POST['repPoints'])) { $viewReports = '<div class="error" style="width: 700px;">You must select one or more points to display a report.</div>' . "\n"; } elseif (!(isset($_POST['repBaseDateFrom']) || isset($_POST['repBaseDateTo']))) { $viewReports = '<div class="error" style="width: 700px;">You must select a from date and a to date to display a report.</div>' . "\n"; } elseif (!isset($_POST['repBaseDateFrom'])) { $viewReports = '<div class="error" style="width: 700px;">You must select a from date to display a report.</div>' . "\n"; } elseif (!isset($_POST['repBaseDateTo'])) { $viewReports = '<div class="error" style="width: 700px;">You must select a to date to display a report.</div>' . "\n"; } elseif (!isset($_POST['report'])) { $viewReports = '<div class="error" style="width: 700px;">You must select a Report Type to display.</div>' . "\n"; } elseif ($_POST['report'] == 'aveHourlyProfile') { $viewReports = BuildReportHeader("Average Hourly Profile", $_POST['repBaseDateFrom'], $_POST['repBaseDateTo']); foreach ($_POST['repPoints'] as $pointChannel => $state) { $ids = explode(":", $pointChannel); $chartSeriesData = ''; $chartData = ''; $chartGraphData = ''; if ($reports->GetAverageHourlyProfile($ids[0], $ids[1], $_POST['repBaseDateFrom'], $_POST['repBaseDateTo'])) { $gid++; $graphName = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription(); $valueUnits = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->units()->unitOfMeasureName(); $graphSettings .= compileGraphSettings($gid, $aryColors[$gid], $graphName); $chartGraphData .= '<graph gid=\\"' . $gid . '\\">'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartGraphData .= '<value xid=\\"' . $inx . '\\">' . $reports->values($inx) . '</value>'; } $chartGraphData .= '</graph>'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartSeriesData .= '<value xid=\\"' . $inx . '\\">' . $reports->labels($inx) . '</value>'; } $chartData = '<chart><series>' . $chartSeriesData . '</series><graphs>' . $chartGraphData . '</graphs></chart>'; $chart .= assembleCharts($ids[0] . '_' . $ids[1], 'bar', $chartData, $valueRotation, $aryUnits[$valueUnits], $reports->labelUnits(), $labelFreq, $gridCount, $graphSettings); $chart .= '<div align="center">' . '<table border="1" cellspacing="0" cellpadding="3">' . '<tr><td align="right">Average Hourly Demand:</td><td align="right">' . $reports->statistic("AverageHourlyDemand") . '</td></tr>' . '<tr><td align="right">Maximum Hourly Demand:</td><td align="right">' . $reports->statistic("MaximumHourlyDemand") . '</td></tr>' . '<tr><td align="right">Total Usage:</td><td align="right">' . $reports->statistic("TotalUsage") . '</td></tr>' . '</table>' . '</div>'; } else { $viewReports .= '<div class="error" style="width: 700px;">Could not retreive Average Hourly Profile Report for ' . $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription() . ' for the selected dates.</div>' . "\n"; } } } elseif ($_POST['report'] == 'aveHourVsPeakHour') { $viewReports = BuildReportHeader("Average Hour Vs. Peak Hour", $_POST['repBaseDateFrom'], $_POST['repBaseDateTo']); //$viewReports = '<table>'; foreach ($_POST['repPoints'] as $pointChannel => $state) { $ids = explode(":", $pointChannel); $chartSeriesData = ''; $chartData = ''; $chartGraphData01 = ''; $chartGraphData02 = ''; if ($reports->GetAverageHourlyProfile($ids[0], $ids[1], $_POST['repBaseDateFrom'], $_POST['repBaseDateTo'])) { for ($inx = 0; $inx < $reports->size(); $inx++) { $averageHour[$inx] = $reports->values($inx); } if ($reports->GetPeakHourlyProfile($ids[0], $ids[1], $_POST['repBaseDateFrom'], $_POST['repBaseDateTo'])) { $graphName = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription(); $valueUnits = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->units()->unitOfMeasureName(); $gid++; $chartGraphData01 .= '<graph gid=\\"' . $gid . '\\">'; $graphSettings .= compileLineGraphSettings($gid, $aryColorPairs[$gid], $graphName . ': Average ' . $aryUnits[$valueUnits]); $gid++; $chartGraphData02 .= '<graph gid=\\"' . $gid . '\\">'; $graphSettings .= compileLineGraphSettings($gid, $aryColorPairs[$gid], $graphName . ': Peak ' . $aryUnits[$valueUnits]); //$viewReports .= '<tr><td>' . $reports->labelUnits() . '</td><td> Average ' . $reports->valueUnits() . '</td><td> Peak ' . $reports->valueUnits() . '</td></tr>' . "\n"; for ($inx = 0; $inx < $reports->size(); $inx++) { //$viewReports .= '<tr><td>' . $reports->labels($inx) . '</td><td>' . $averageHour[$inx] . '</td><td>' . $reports->values($inx) . '</td></tr>' . "\n"; $chartGraphData01 .= '<value xid=\\"' . $inx . '\\">' . $averageHour[$inx] . '</value>'; $chartGraphData02 .= '<value xid=\\"' . $inx . '\\">' . $reports->values($inx) . '</value>'; } $chartGraphData01 .= '</graph>'; $chartGraphData02 .= '</graph>'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartSeriesData .= '<value xid=\\"' . $inx . '\\">' . $reports->labels($inx) . '</value>'; } $valueRotation = 0; $chartData = '<chart><series>' . $chartSeriesData . '</series><graphs>' . $chartGraphData01 . $chartGraphData02 . '</graphs></chart>'; $chart .= assembleCharts($ids[0] . '_' . $ids[1], 'line', $chartData, $valueRotation, $aryUnits[$valueUnits], $reports->labelUnits(), 1, 24, $graphSettings); $chart .= '<div align="center">' . '<table border="1" cellspacing="0" cellpadding="3">' . '<tr><td>Maximum Demand:</td><td>' . $reports->statistic("IntervalValue") . '</td><td> on ' . $reports->statistic("IntervalDate") . '</td></tr>' . '</table>' . '</div>'; } else { $viewReports .= '<div class="error" style="width: 700px;">Could not retreive Average Hour Vs. Peak Hour Report for ' . $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription() . ' for the selected dates.</div>' . "\n"; } } else { $viewReports .= '<div class="error" style="width: 700px;">Could not retreive Average Hour Vs. Peak Hour Report for ' . $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription() . ' for the selected dates.</div>' . "\n"; } //$viewReports .= '</tbody>' . "\n" . '</table>' . "\n"; } } elseif ($_POST['report'] == 'topTenPeaks') { $viewReports = BuildReportHeader("Top Ten Peaks", $_POST['repBaseDateFrom'], $_POST['repBaseDateTo']); foreach ($_POST['repPoints'] as $pointChannel => $state) { $ids = explode(":", $pointChannel); $chartSeriesData = ''; $chartData = ''; $chartGraphData = ''; if ($reports->GetTopTenPeaks($ids[0], $ids[1], $_POST['repBaseDateFrom'], $_POST['repBaseDateTo'])) { $gid++; $graphName = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription(); $valueUnits = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->units()->unitOfMeasureName(); $graphSettings .= compileGraphSettings($gid, $aryColors[$gid], $graphName); $chartGraphData .= '<graph gid=\\"' . $gid . '\\">'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartGraphData .= '<value xid=\\"' . $inx . '\\">' . $reports->values($inx) . '</value>'; } $chartGraphData .= '</graph>'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartSeriesData .= '<value xid=\\"' . $inx . '\\">' . $reports->labels($inx) . '</value>'; } $chartData = '<chart><series>' . $chartSeriesData . '</series><graphs>' . $chartGraphData . '</graphs></chart>'; $chart .= assembleCharts($ids[0] . '_' . $ids[1], 'bar', $chartData, 30, $aryUnits[$valueUnits], $reports->labelUnits(), $labelFreq, $gridCount, $graphSettings); $chart .= '<div align="center">' . '<table border="1" cellspacing="0" cellpadding="3">' . '<tr><td colspan="3">Top Ten Peaks</td></tr>' . '<tr><td> </td><td>Demand (KW)</td><td>Date</td></tr>'; $inx = 0; foreach ($reports->statistics() as $date => $value) { $chart .= "<tr><td>" . ++$inx . "</td><td>{$value}</td><td>{$date}</td></tr>"; } $chart .= '</table></div>'; } else { $viewReports .= '<div class="error" style="width: 700px;">Could not retreive Top Ten Peaks Report for ' . $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription() . ' for the selected dates.</div>' . "\n"; } } if ($chartGraphData != "") { for ($inx = 0; $inx < $reports->size(); $inx++) { $chartSeriesData .= '<value xid=\\"' . $inx . '\\">' . $reports->labels($inx) . '</value>'; } } } elseif ($_POST['report'] == 'dailyUsageProfile') { $viewReports = BuildReportHeader("Daily Usage Profile", $_POST['repBaseDateFrom'], $_POST['repBaseDateTo']); foreach ($_POST['repPoints'] as $pointChannel => $state) { $ids = explode(":", $pointChannel); $chartSeriesData = ''; $chartData = ''; $chartGraphData = ''; $valueRotation = 90; if ($reports->GetDailyUsageProfile($ids[0], $ids[1], $_POST['repBaseDateFrom'], $_POST['repBaseDateTo'])) { //$reports->preDebugger($reports); $gid++; $graphName = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription(); $valueUnits = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->units()->unitOfMeasureName(); $graphSettings .= compileGraphSettings($gid, $aryColors[$gid], $graphName); $chartGraphData .= '<graph gid=\\"' . $gid . '\\">'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartGraphData .= '<value xid=\\"' . $inx . '\\">' . $reports->values($inx) . '</value>'; } $chartGraphData .= '</graph>'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartSeriesData .= '<value xid=\\"' . $inx . '\\">' . $reports->labels($inx) . '</value>'; } $chartData = '<chart><series>' . $chartSeriesData . '</series><graphs>' . $chartGraphData . '</graphs></chart>'; $chart .= assembleCharts($ids[0] . '_' . $ids[1], 'line', $chartData, $valueRotation, $aryUnits[$valueUnits], $reports->labelUnits(), 1, 24, $graphSettings); $chart .= '<div align="center">' . '<table border="1" cellspacing="0" cellpadding="3">' . '<tr>' . '<td align="right">Maximim Hourly Usage:</td><td align="right">' . $reports->statistic("MaximumUsage") . '</td>' . '<td>' . $reports->statistic("MaximumUsageDate") . '</td>' . '<tr>' . '<td align="right">Average Hourly Usage:</td><td align="right">' . $reports->statistic("AverageUsage") . '</td>' . '<td> </td>' . '</tr>' . '<tr>' . '<td align="right">Minimum Hourly Usage:</td><td align="right">' . $reports->statistic("MinimumUsage") . '</td>' . '<td>' . $reports->statistic("MinimumUsageDate") . '</td>' . '</tr>' . '<tr>' . '<td align="right">Total Usage:</td><td align="right">' . $reports->statistic("TotalUsage") . '</td>' . '<td> </td>' . '</tr>' . '</table>' . '</div>'; } else { $viewReports .= '<div class="error" style="width: 700px;">Could not retreive Daily Usage Profile Report for ' . $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription() . ' for the selected dates.</div>' . "\n"; } } } elseif ($_POST['report'] == 'weeklyUsageProfile') { /* print '<pre>'; print_r($reports); print '</pre>'; */ $fromDate = strtotime(str_replace("-", "/", $_POST['repBaseDateFrom'])); $toDate = strtotime(str_replace("-", "/", $_POST['repBaseDateTo'])); $daySpan = 1 + ($toDate - $fromDate) / 86400; if ($daySpan >= 7) { $viewReports = BuildReportHeader("Weekly Usage Profile", $_POST['repBaseDateFrom'], $_POST['repBaseDateTo']); foreach ($_POST['repPoints'] as $pointChannel => $state) { $ids = explode(":", $pointChannel); $chartSeriesData = ''; $chartData = ''; $chartGraphData = ''; if ($reports->GetWeeklyUsageProfile($ids[0], $ids[1], $_POST['repBaseDateFrom'], $_POST['repBaseDateTo'])) { /* print '<pre>'; print_r($reports); print '</pre>'; */ $gid++; $graphName = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription(); $valueUnits = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->units()->unitOfMeasureName(); $graphSettings .= compileGraphSettings($gid, $aryColors[$gid], $graphName); $chartGraphData .= '<graph gid=\\"' . $gid . '\\">'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartGraphData .= '<value xid=\\"' . $inx . '\\">' . $reports->values($inx) . '</value>'; } $chartGraphData .= '</graph>'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartSeriesData .= '<value xid=\\"' . $inx . '\\">' . $reports->labels($inx) . '</value>'; } $chartData = '<chart><series>' . $chartSeriesData . '</series><graphs>' . $chartGraphData . '</graphs></chart>'; /* print '<pre>'; print_r($chartData); print '</pre>'; */ $chart .= assembleCharts($ids[0] . '_' . $ids[1], 'line', $chartData, $valueRotation, $aryUnits[$valueUnits], $reports->labelUnits(), '1', '7', $graphSettings); $chart .= '<div align="center">' . '<table border="1" cellspacing="0" cellpadding="3">' . '<tr>' . '<td align="right">Maximim Daily Usage:</td><td align="right">' . $reports->statistic("MaximumUsage") . '</td>' . '<td>' . $reports->statistic("MaximumUsageDate") . '</td>' . '<tr>' . '<td align="right">Average Daily Usage:</td><td align="right">' . $reports->statistic("AverageUsage") . '</td>' . '<td> </td>' . '</tr>' . '<tr>' . '<td align="right">Minimum Daily Usage:</td><td align="right">' . $reports->statistic("MinimumUsage") . '</td>' . '<td>' . $reports->statistic("MinimumUsageDate") . '</td>' . '</tr>' . '<tr>' . '<td align="right">Total Usage:</td><td align="right">' . $reports->statistic("TotalUsage") . '</td>' . '<td> </td>' . '</tr>' . '</table>' . '</div>'; } else { $viewReports .= '<div class="error" style="width: 700px;">Could not retreive Weekly Usage Report for ' . $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription() . ' for the selected dates.</div>' . "\n"; } } if ($chartGraphData != "") { for ($inx = 0; $inx < $reports->size(); $inx++) { $chartSeriesData .= '<value xid=\\"' . $inx . '\\">' . $reports->labels($inx) . '</value>'; } $chartType = 'line'; $showChart = true; $labelFreq = '24'; $gridCount = '24'; $valueUnits = $reports->valueUnits(); $labelUnits = $reports->labelUnits(); $chartData = '<chart><series>' . $chartSeriesData . '</series><graphs>' . $chartGraphData . '</graphs></chart>'; } } else { $viewReports = '<div class="error" style="width: 700px;">You must select a minimum date span of 7 days to display the Weekly Usage Profile.</div>' . "\n"; } } elseif ($_POST['report'] == 'monthlyUsageProfile') { $fromDate = strtotime(str_replace("-", "/", $_POST['repBaseDateFrom'])); $toDate = strtotime(str_replace("-", "/", $_POST['repBaseDateTo'])); $daySpan = 1 + ($toDate - $fromDate) / 86400; if ($daySpan >= 28) { $viewReports = BuildReportHeader("Monthly Usage Profile", $_POST['repBaseDateFrom'], $_POST['repBaseDateTo']); foreach ($_POST['repPoints'] as $pointChannel => $state) { $ids = explode(":", $pointChannel); $chartSeriesData = ''; $chartData = ''; $chartGraphData = ''; if ($reports->GetMonthlyUsageProfile($ids[0], $ids[1], $_POST['repBaseDateFrom'], $_POST['repBaseDateTo'])) { $gid++; $graphName = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription(); $valueUnits = $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->units()->unitOfMeasureName(); $graphSettings .= compileGraphSettings($gid, $aryColors[$gid], $graphName); $chartGraphData .= '<graph gid=\\"' . $gid . '\\">'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartGraphData .= '<value xid=\\"' . $inx . '\\">' . $reports->values($inx) . '</value>'; } $chartGraphData .= '</graph>'; for ($inx = 0; $inx < $reports->size(); $inx++) { $chartSeriesData .= '<value xid=\\"' . $inx . '\\">' . $reports->labels($inx) . '</value>'; } $chartData = '<chart><series>' . $chartSeriesData . '</series><graphs>' . $chartGraphData . '</graphs></chart>'; $chart .= assembleCharts($ids[0] . '_' . $ids[1], 'bar', $chartData, $valueRotation, $aryUnits[$valueUnits], $reports->labelUnits(), $labelFreq, $gridCount, $graphSettings); $chart .= '<div align="center">' . '<table border="1" cellspacing="0" cellpadding="3">' . '<tr>' . '<td align="right">Maximim Monthly Usage:</td><td align="right">' . $reports->statistic("MaximumUsage") . '</td>' . '<td>' . $reports->statistic("MaximumUsageDate") . '</td>' . '<tr>' . '<td align="right">Average Monthly Usage:</td><td align="right">' . $reports->statistic("AverageUsage") . '</td>' . '<td> </td>' . '</tr>' . '<tr>' . '<td align="right">Minimum Monthly Usage:</td><td align="right">' . $reports->statistic("MinimumUsage") . '</td>' . '<td>' . $reports->statistic("MinimumUsageDate") . '</td>' . '</tr>' . '<tr>' . '<td align="right">Total Usage:</td><td align="right">' . $reports->statistic("TotalUsage") . '</td>' . '<td> </td>' . '</tr>' . '</table>' . '</div>'; } else { $viewReports .= '<div class="error" style="width: 700px;">Could not retreive Monthly Usage Report for ' . $userObject->pointChannels()->pointChannel($ids[0], $ids[1])->channelDescription() . ' for the selected dates.</div>' . "\n"; } } if ($chartGraphData != "") { for ($inx = 0; $inx < $reports->size(); $inx++) { $chartSeriesData .= '<value xid=\\"' . $inx . '\\">' . $reports->labels($inx) . '</value>'; } $chartType = 'bar'; $showChart = true; $valueUnits = $reports->valueUnits(); $labelUnits = $reports->labelUnits(); $chartData = '<chart><series>' . $chartSeriesData . '</series><graphs>' . $chartGraphData . '</graphs></chart>'; } } else { $viewReports = '<div class="error" style="width: 700px;">You must select a minimum date span of 28 days to display the Monthly Usage Profile.</div>' . "\n"; } } else { $viewReports = '<div class="error" style="width: 700px;">You have selected an unknown Report Type to display.</div>'; } return $viewReports . $chart; }