echo "<br/>8---------------------------------------------<br/>"; //test of 8 $f = array("Sophia" => "31", "Jacob" => "41", "William" => "39", "Ramesh" => "40"); printArray(sortValueAscending($f)); echo "<br/>"; printArray(sortValueDescending($f)); echo "<br/>"; printArray(sortKeyDescending($f)); echo "<br/>"; printArray(sortKeyAscending($f)); echo "<br/>"; echo "<br/>9---------------------------------------------<br/>"; //test of 9 $temp = array(78, 60, 62, 68, 71, 68, 73, 85, 66, 64, 76, 63, 75, 76, 73, 68, 62, 73, 72, 65, 74, 62, 62, 65, 64, 68, 73, 75, 79, 73); //average echo "average of the temp= " . getAverage($temp); //sevenLowest print_r(getSevenLowest($temp)); //sevenHighest print_r(getSevenHighest($temp)); echo "<br/>10---------------------------------------------<br/>"; //test of 10 $d = array(5, 2, 3, 4, 1, 0); convertArrayToBead($d); echo "<br/>11---------------------------------------------<br/>"; //test of 11 $array1 = array(array(77, 87), array(23, 45)); $array2 = array("w3resource", "com"); print_r(mergeTwoArraysByIndex($array1, $array2)); echo "<br/>12---------------------------------------------<br/>"; //test of 12
function groupedGraph($chart, $item, $min, $max) { global $cmd; echo '<div class="col-xs-2"><select class="form-control" name="' . $item . '" id="' . $item . '">'; if (!isset($_POST[$item])) { $_POST[$item] = ''; echo '<option selected value="Select">Select</option>'; } else { echo '<option value="Select">Select</option>'; } $itemSelected = ''; $graphs = readGraphs(); foreach ($graphs as $graph) { if (isset($_POST) && $_POST[$item] == $graph['id_graph']) { echo '<option selected value="' . $graph['id_graph'] . '">' . $graph['name'] . '</option>'; $itemSelected = $graph['name']; } else { echo '<option value="' . $graph['id_graph'] . '">' . $graph['name'] . '</option>'; } } echo '</select></div>'; echo '<div class="col-xs-2"><select class="form-control" name="host" id="host">'; if (!isset($_POST['host'])) { $_POST['host'] = ''; echo '<option selected value="Select">Select</option>'; } else { echo '<option value="Select">Select</option>'; } $hostSelected = ''; $hosts = readHosts(0); foreach ($hosts as $host) { $thehost = $host['host']; if (isset($_POST['host']) && $_POST['host'] == $host['id_host']) { $hostSelected = $thehost; echo '<option selected value="' . $host['id_host'] . '">' . $thehost . '</option>'; } else { echo '<option value="' . $host['id_host'] . '">' . $thehost . '</option>'; } } echo '</select></div>'; $index = 0; $days = Days($_POST['date1'], $_POST['date2']); $divide = 1; $divide = getAverage($_POST['avg']); $divide = $divide[1]; if ($_POST['avg'] == "None") { $divideslot = 60 * 30; } else { $divideslot = $divide; } if (is_numeric($_POST['host'])) { $id_host = $_POST['host']; $col = 0; $monitors = readMonitorsForGraph($_POST[$item]); foreach ($monitors as $monitor) { $id_item = $monitor['id_item']; $rawData = loadRAWData($_POST['date1'], 0, $id_item, $_POST['date2'], $id_host); unset($data2); $prev = 0; $next = 0; $history = $rawData['historyList'][$id_host]; if (isset($history)) { $unit = $monitor['unit']; $div = 1; if ($unit == 'bps') { $div = 1024; //BGS011 $unit = 'Mbps'; } unset($finalData); foreach ($history as $ddata) { $tk = round($ddata['clock'] / $divide, 0) * $divide; if (!isset($finalData[$tk])) { $finalData[$tk] = array('clock' => $tk, 'sum' => 0, 'cnt' => 0); } $sum = $finalData[$tk]['sum']; $cnt = $finalData[$tk]['cnt']; $x = $sum + $ddata['value']; $y = $cnt + 1; $finalData[$tk] = array('clock' => $tk, 'sum' => $x, 'cnt' => $y); } foreach ($finalData as $row) { if (!isset($minClock)) { $minClock = $row['clock'] * 1000; $maxClock = $row['clock'] * 1000; } else { if ($minClock > $row['clock'] * 1000) { $minClock = $row['clock'] * 1000; } if ($maxClock < $row['clock'] * 1000) { $maxClock = $row['clock'] * 1000; } } $next = $row['clock']; if ($prev > 0 && $next > 0 && $next - $prev > $divideslot * 1.2) { $data2[] = array(($prev + 1000) * 1000, null); } $prev = $next; $v = null; if ($row['cnt'] != 0) { $v = round($row['sum'] / $row['cnt'] * 1 / $div, 2); } $data2[] = array($row['clock'] * 1000, $v * 1 / $div, 2); } $chart->series[]->name = $monitor['descriptionLong']; $chart->series[$index]->type = 'spline'; $chart->yAxis->title->text = $unit; $chart->series[$index]->color = getColor($col); $chart->series[$index]->data = $data2; $index++; $col++; } } } if (!isset($unit)) { $unit = ""; } $title = $hostSelected . ":" . $itemSelected; $subtitle = 'From ' . $_POST['date1'] . ' to ' . $_POST['date2']; $chart = chartHeader($chart, 'c_' . $item, $title, $subtitle, $unit, null); $chart->xAxis->type = 'datetime'; $chart->plotOptions->series->animation->complete = new HighchartJsExpr(" function () {redraw();}"); if (!isset($minClock)) { $minClock = 0; $maxClock = 0; } if (!isset($unit)) { $unit = ""; } $chart->tooltip->formatter = new HighchartJsExpr("\r\n function() {\r\n var s = '<b>'+ Highcharts.dateFormat('%e. %b %H:%M',this.x) +'</b>'; \r\n \$.each(this.points, function(i, point) {\r\n s += '<br/><span style=\"color:'+point.series.color+'\">'+ point.series.name +': '+ point.y +' " . $unit . "</span><b>';\r\n });\r\n return s;\r\n }"); //return array( 0 => $chart, 1 => $minClock , 2 => $maxClock); echo "\n" . '<script> function redraw() { chart1.xAxis[0].setExtremes(' . ($minClock - 60000) . ', ' . ($maxClock + 60000 * 5) . ');} </script>'; return $chart; }
/** * Retrieve the data needed for computation of this form */ function prepareStatsData() { global $statsinfo; $timeRange = $statsinfo->getRangeArray(); $this->dateFormat = $statsinfo->getDateFormat($timeRange['interval']); $timeRange['interval'] = $statsinfo->getIntervalTicks($timeRange['interval']); $diagram = $this->summaryType; $paramArray = array('api_call' => $this->summaryType); if (substr($diagram, 0, 8) == "nxhours:") { $paramArray = array('what' => substr($diagram, 8), 'api_call' => "hours"); $this->hours = true; } else { if (substr($diagram, 0, 11) == "nxweekdays:") { $paramArray = array('what' => substr($diagram, 11), 'api_call' => "weekdays"); $this->weekdays = true; } } if (substr($diagram, 0, 11) == "nxweekdays:") { $weekdays = true; $diagram = substr($diagram, 11); } $constraint = array(); if ($this->spid != "") { $constraint["constraints"] = array('document_string' => $this->spid); } $this->data = phpOpenTracker::get(array_merge($paramArray, $timeRange, $constraint)); $this->minTs = getMinTs($this->data); $this->maxTs = getMaxTs($this->data); $this->median = getMedian($this->data); $this->total = getTotal($this->data); $this->average = getAverage($this->data); }
} # if there IS a rating in this column (for this row) if ($column_order[$col_counter] == $row["userid"] and $col_counter < count($column_order)) { if (strlen($row["rating"]) > 1) { $base_rating = explode(".", $row["rating"]); $rating_css_class = $base_rating[0] . '_5'; } else { $rating_css_class = $row["rating"]; } echo '<td class="rating_' . $rating_css_class . '">'; echo $row["rating"]; echo '</td>'; array_push($all_ratings, $row["rating"]); # checking for end-of-row and appending average column if (count($column_order) - $col_counter == 1 and $avg_flag == 0) { $avg_flag = getAverage($column_order[$col_counter], count($column_order), $all_ratings); } $col_counter++; } } } # getting user averages echo '<tr id="user_averages"><td><strong>Average</strong></td>'; for ($i = 0; $i < $num_users; $i++) { $curr_array = $userids[$i]; $curr_id = $curr_array["userid"]; $select_user_avg_sql = 'SELECT AVG(r.Rating) AS Average FROM tblUsers AS u LEFT JOIN tblRatings AS r ON r.UserID = u.UserID LEFT JOIN tblFilms AS f ON f.FilmID = r.FilmID LEFT JOIN tblFilmTags AS ft ON ft.FilmID = f.FilmID
function GraphSonda($chart, $id_chart, $id_plan, $id_item, $from, $avg, $tag) { $offset = getOffset(); // setTimezone(); $dt = getDates($from); $index = 0; $average = getAverage($avg); $format = $average[0]; $divide = $average[1]; if ($divide == 60 * 60 * 6) { $offset = -60 * 60 * 2; } if ($divide == 60 * 60 * 12) { $offset = +60 * 60 * 4; } if ($divide == 60 * 60 * 24) { $offset = +60 * 60 * 4; } $colorIndex = 0; $ldata = loadRAWData($from, $id_plan, $id_item); $percentile = calculatePercentile($ldata['allData']); $div = $ldata['div']; if (isset($ldata['hostList'])) { foreach ($ldata['hostList'] as $host) { $id_host = $host['id_host']; $hostName = $host['host']; $nacD = $host['nacD']; $nacU = $host['nacU']; $critical = $host['critical']; $warning = $host['warning']; $nominal = $host['nominal']; if ($warning > 100) { $dir = 1; } else { $dir = 0; } if ($nominal == -1) { $nominal = $nacD; } if ($nominal == -2) { $nominal = $nacU; } unset($theSondaAvg); unset($theSondaQoE); unset($dataAvg); unset($dataQoE); if (isset($ldata['historyList'][$id_host])) { foreach ($ldata['historyList'][$id_host] as $key => $row) { $tk = round($row['clock'] / $divide, 0) * $divide; $skip = false; if (isset($_SESSION['filter']['P95']) && $row['value'] > $percentile['P95']) { $skip = true; } if (isset($_SESSION['filter']['P5']) && $row['value'] < $percentile['P5']) { $skip = true; } if (!$skip) { if (!isset($theSondaAvg[$tk])) { $theSondaAvg[$tk] = array($tk, 0, 0); } if (!isset($theSondaQoE[$tk])) { $theSondaQoE[$tk] = array($tk, 0, 0); } $sum = $theSondaAvg[$tk][1]; $cnt = $theSondaAvg[$tk][2]; $x = $sum + $row['value']; $y = $cnt + 1; $theSondaAvg[$tk] = array($tk, $x, $y); if ($row['value'] > $nominal) { $row['value'] = $nominal; } $sum = $theSondaQoE[$tk][1]; $cnt = $theSondaQoE[$tk][2]; $x = $sum + $row['value']; $y = $cnt + 1; $theSondaQoE[$tk] = array($tk, $x, $y); } } } if (isset($theSondaAvg)) { aasort($theSondaAvg, 0); $next = 0; $prev = 0; foreach ($theSondaAvg as $tvalue) { $next = $tvalue[0] + $offset; if ($prev > 0 && $next > 0 && $next - $prev > $divide * 2) { $dataAvg[] = array(($prev + 1000) * 1000, null); } $dataAvg[] = array($next * 1000, round($tvalue[1] / $tvalue[2] / $div, 2)); $prev = $next; } aasort($theSondaQoE, 0); $next = 0; $prev = 0; foreach ($theSondaQoE as $tvalue) { $next = $tvalue[0] + $offset; if ($prev > 0 && $next > 0 && $next - $prev > $divide * 2) { $dataQoE[] = array(($prev + 1000) * 1000, null); } $dataQoE[] = array($next * 1000, round($tvalue[1] / $tvalue[2] / $div, 2)); $prev = $next; } } if (isset($dataAvg)) { if (!isset($minClock)) { $minClock = $dataAvg[0][0]; $maxClock = $dataAvg[count($dataAvg) - 1][0]; } else { if ($dataAvg[0][0] < $minClock) { $minClock = $dataAvg[0][0]; } if ($dataAvg[count($dataAvg) - 2][0] > $maxClock) { $maxClock = $dataAvg[count($dataAvg) - 2][0]; } } if ($_GET['qoe'] == 'Average On' || $_GET['qoe'] == 'Both') { $chart->series[]->name = $hostName . "-AVG"; $chart->series[$index]->type = 'spline'; $chart->series[$index]->dashStyle = 'spline'; $chart->series[$index]->data = $dataAvg; $chart->series[$index]->color = getColor($colorIndex); $chart->series[$index]->lineWidth = 1; $chart->series[$index]->marker->radius = 2; $index++; } if ($_GET['qoe'] == 'QoE On' || $_GET['qoe'] == 'Both') { $chart->series[]->name = $hostName . '-QoE'; $chart->series[$index]->type = 'shortdot'; $chart->series[$index]->color = getColor($colorIndex); $chart->series[$index]->data = $dataQoE; $chart->series[$index]->lineWidth = 1; $chart->series[$index]->marker->radius = 2; $index++; } $colorIndex++; } } } $title = 'Sondas for "' . $ldata['item'] . '" on plan "' . $ldata['plan'] . '"'; $subtitle = 'From ' . $ldata['from'] . ' to ' . $ldata['to']; $chart = chartHeader($chart, $id_chart, $title, $subtitle, $ldata['unit'], null); if (!isset($minClock)) { $minClock = 0; $maxClock = 0; } $chart->xAxis->type = 'datetime'; $chart->tooltip->formatter = new HighchartJsExpr("\n function() {\n var s = '<b>'+ Highcharts.dateFormat('%e. %b %H:%M',this.x) +'</b>'; \n \$.each(this.points, function(i, point) {\n s += '<br/><span style=\"color:'+point.series.color+'\">'+ point.series.name +': '+ point.y +' " . $ldata['unit'] . "</span><b>';\n });\n return s;\n }"); echo "\n" . '<script> function redraw() { chart1.xAxis[0].setExtremes(' . $minClock . ', ' . (round($maxClock / (3600 * 24), 0) * 3600 * 24 + $divide * 1000) . ');} </script>'; //var_dump($chart->chart); return $chart; }
require_once "../as/aviasales.php"; $origin = $_GET['origin']; $dest = $_GET['destination']; $compare = isset($_GET['compare']) ? (100 - $_GET['compare']) / 100 : 0.85; echo 'Highlighted <span class="highlighted">' . (1 - $compare) * 100 . '%+</span> below average<br><br>'; $originIata = getCityCode($origin); $destIata = getCityCode($dest); $dates = array('2015-09', '2015-10', '2015-11', '2015-12', '2016-01', '2016-02', '2016-03', '2016-03'); //$dates = array('2016-02'); echo 'From: ' . $origin . '</br> To: ' . $dest . '</br></br>'; //Table header echo '<table>'; echo '<tr><th>Date</th><th>Price</th><th>Average</th><th>Transfers</th><th>Return at</th><th>Link</th></tr>'; foreach ($dates as $date) { $calendar = getCalendar($originIata, $destIata, $date); $average = getAverage($originIata, $destIata, $date); if (array_key_exists('success', $calendar) && $calendar['success'] == 1 && array_key_exists('data', $calendar)) { $color = false; foreach ($calendar['data'] as $day => $data) { if ($color) { echo '<tr class="colored">'; } else { echo '<tr>'; } $color = !$color; $tdHighlited = $data['price'] / $average < $compare ? '<td class="highlighted">' : '<td>'; $link = getSearchLink($originIata, $destIata, $day, substr($data['return_at'], 0, 10)); echo '<td>' . $day . '</td>' . $tdHighlited . $data['price'] . '</td>'; echo '<td>' . round($average) . '</td>'; echo '<td>' . $data['transfers'] . '</td><td>' . $data['return_at'] . '</td>'; echo '<td><a href="' . $link . '" target="_blank">link</a></td>';
echo '<head>'; echo '<link rel="stylesheet" type="text/css" href="../as/css/style.css">'; echo '</head>'; $compare = isset($_GET['compare']) ? (100 - $_GET['compare']) / 100 : 0.85; echo 'Highlighted <span class="highlighted">' . (1 - $compare) * 100 . '%+</span> below average<br><br>'; $results = getCheap($origin, $destination, $date); //$average = getAverage($origin, $destination, $date); //echo print_r($cheap); if (array_key_exists('success', $results) && $results['success'] == 1 && array_key_exists('data', $results)) { echo '<table><tr><th>Direction</th><th>Airline</th><th>Date Departure</th><th>Date Return</th><th>Price Rub</th><th>Average Price</th></tr>'; foreach ($results['data'] as $direction => $flights) { $color = false; foreach ($flights as $flight) { $departureDate = substr($flight['departure_at'], 0, 7); $returnDate = substr($flight['return_at'], 0, 7); $average = getAverage($origin, $direction, $departureDate); if ($color) { echo '<tr class="colored">'; } else { echo '<tr>'; } $color = !$color; echo '<td>' . $direction . ' - ' . getCityName($direction) . '</td>'; echo '<td>' . $flight['airline'] . '</td>'; echo '<td>' . $flight['departure_at'] . '</td>'; echo '<td>' . $flight['return_at'] . '</td>'; if ($flight['price'] / $average < 0.9) { echo '<td class="highlighted">' . $flight['price'] . '</td>'; } else { echo '<td>' . $flight['price'] . '</td>'; }
function getPlayerBatting($playerID) { $battingTable = ""; $connection = mysqli_connect("localhost", "root", "", "baseball"); $playerID = mysqlsafe($playerID, $connection); $query = mysqli_query($connection, "SELECT PlayerID, yearID, teamID, lgID, G, AB, R, H, 2B, 3B, HR, RBI, SB, CS, BB, SO, IBB, HBP, SH, SF, GIDP FROM `batting` WHERE playerID = '{$playerID}' ORDER BY yearID ASC"); $rowCount = mysqli_num_rows($query); if ($rowCount >= 1) { $battingTable = "<br><h1>Batting</h1>\n"; $battingTable .= "<table>\n"; $battingTable .= "\t<tr>\n"; $battingTable .= "\t\t<th>Year</th>\n"; $battingTable .= "\t\t<th>Team</th>\n"; $battingTable .= "\t\t<th>League</th>\n"; $battingTable .= "\t\t<th>G</th>\n"; $battingTable .= "\t\t<th>AB</th>\n"; $battingTable .= "\t\t<th>R</th>\n"; $battingTable .= "\t\t<th>H</th>\n"; $battingTable .= "\t\t<th>2B</th>\n"; $battingTable .= "\t\t<th>3B</th>\n"; $battingTable .= "\t\t<th>HR</th>\n"; $battingTable .= "\t\t<th>RBI</th>\n"; $battingTable .= "\t\t<th>SB</th>\n"; $battingTable .= "\t\t<th>CS</th>\n"; $battingTable .= "\t\t<th>BB</th>\n"; $battingTable .= "\t\t<th>SO</th>\n"; $battingTable .= "\t\t<th>IBB</th>\n"; $battingTable .= "\t\t<th>HBP</th>\n"; $battingTable .= "\t\t<th>SH</th>\n"; $battingTable .= "\t\t<th>SF</th>\n"; $battingTable .= "\t\t<th>GIDP</th>\n"; $battingTable .= "\t\t<th>AVG</th>\n"; $battingTable .= "\t\t<th>OBP</th>\n"; $battingTable .= "\t\t<th>SLG</th>\n"; $battingTable .= "\t\t<th>OPS</th>\n"; $battingTable .= "\t</tr>\n"; while ($row = mysqli_fetch_assoc($query)) { if ($row['AB'] != 0 || !is_null($row['AB'])) { $battingTable .= "\t<tr>\n"; $battingTable .= "\t\t<td>" . $row['yearID'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['teamID'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['lgID'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['G'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['AB'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['R'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['H'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['2B'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['3B'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['HR'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['RBI'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['SB'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['CS'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['BB'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['SO'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['IBB'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['HBP'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['SH'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['SF'] . "</td>\n"; $battingTable .= "\t\t<td>" . $row['GIDP'] . "</td>\n"; $battingTable .= "\t\t<td>" . getAverage($row['H'], $row['AB']) . "</td>\n"; $OBP = getOnBasePercent($row['H'], $row['BB'], $row['HBP'], $row['AB'], $row['SF']); $battingTable .= "\t\t<td>" . $OBP . "</td>\n"; $SLG = getSluggingPercent($row['H'], $row['2B'], $row['3B'], $row['HR'], $row['AB']); $battingTable .= "\t\t<td>" . $SLG . "</td>\n"; $battingTable .= "\t\t<td>" . getOnBasePercentPlusSlugging($OBP, $SLG) . "</td>\n"; $battingTable .= "\t</tr>\n"; } } $battingTable .= "</table>"; } mysqli_close($connection); return $battingTable; }
function GraphPlan($chart, $id_chart, $id_item, $from, $avg, $tag) { //$cache = phpFastCache(); $dt = getDates($from); $item = getItem($id_item); $index = 0; $thezero = '-1'; $average = getAverage($avg); $format = $average[0]; $divide = $average[1]; $color = array('#89A54E', 'none', '#4572A7', 'none', '#AA4643', 'none', '#808080', 'none', 'darksilver', 'none', 'black', 'none', 'magenta', 'none', 'lighrblue', 'none'); $offset = 0; $colorIndex = 0; $cacheAge = 60 * 30; // 30 minutes if ($divide == 60 * 60 * 6) { $offset = -60 * 60 * 2; } if ($divide == 60 * 60 * 12) { $offset = +60 * 60 * 4; } if ($divide == 60 * 60 * 24) { $offset = +60 * 60 * 4; } $planList = readPlan(); foreach ($planList as $plan) { $id_plan = $plan['id_plan']; unset($data2); unset($data3); unset($dataAvg); unset($dataQoE); unset($planAvg); unset($planQoE); unset($percentile); unset($ldata); $ldata = loadRAWData($from, $id_plan, $id_item); $unit = $ldata['unit']; $div = $ldata['div']; $percentile = calculatePercentile($ldata['allData']); if (isset($ldata['hostList'])) { foreach ($ldata['hostList'] as $host) { $id_host = $host['id_host']; $nacD = $host['nacD']; $nacU = $host['nacU']; $critical = $host['critical']; $warning = $host['warning']; $nominal = $host['nominal']; if ($warning > 100) { $dir = 1; } else { $dir = 0; } if ($nominal == -1) { $nominal = $nacD; } if ($nominal == -2) { $nominal = $nacU; } if (isset($ldata['historyList'][$id_host])) { foreach ($ldata['historyList'][$id_host] as $key => $row) { $tk = round($row['clock'] / $divide, 0) * $divide; $skip = false; if (isset($_SESSION['filter']['P95']) && $row['value'] > $percentile['P95']) { $skip = true; } if (isset($_SESSION['filter']['P5']) && $row['value'] < $percentile['P5']) { $skip = true; } if (!$skip) { if (!isset($planAvg[$tk])) { $planAvg[$tk] = array($tk, 0, 0); } if (!isset($planQoE[$tk])) { $planQoE[$tk] = array($tk, 0, 0); } $sum = $planAvg[$tk][1]; $cnt = $planAvg[$tk][2]; $x = $sum + $row['value']; $y = $cnt + 1; $planAvg[$tk] = array($tk, $x, $y); if ($row['value'] > $nacD) { $row['value'] = $nacD; } $sum = $planQoE[$tk][1]; $cnt = $planQoE[$tk][2]; $x = $sum + $row['value']; $y = $cnt + 1; $planQoE[$tk] = array($tk, $x, $y); } } } } } if (isset($planAvg)) { $next = 0; $prev = 0; aasort($planAvg, 0); aasort($planQoE, 0); foreach ($planAvg as $tvalue) { $next = $planAvg[$tvalue[0]][0] + $offset; if ($prev > 0 && $next > 0 && $next - $prev > $divide * 2) { $dataAvg[] = array(($prev + 1000) * 1000, null); $dataQoE[] = array(($prev + 1000) * 1000, null); } $dataAvg[] = array($planAvg[$tvalue[0]][0] * 1000, round($planAvg[$tvalue[0]][1] / $planAvg[$tvalue[0]][2] / $div, 2)); $dataQoE[] = array($planQoE[$tvalue[0]][0] * 1000, round($planQoE[$tvalue[0]][1] / $planQoE[$tvalue[0]][2] / $div, 2)); $prev = $next; } } if (isset($dataAvg)) { if (!isset($minClock)) { $minClock = $dataAvg[0][0]; $maxClock = $dataAvg[count($dataAvg) - 2][0]; } else { if ($dataAvg[0][0] < $minClock) { $minClock = $dataAvg[0][0]; } if ($dataAvg[count($dataAvg) - 2][0] > $maxClock) { $maxClock = $dataAvg[count($dataAvg) - 2][0]; } } if ($_GET['qoe'] == 'Average On' || $_GET['qoe'] == 'Both') { $chart->series[]->name = $ldata['plan'] . '-AVG'; $chart->series[$index]->type = 'spline'; $chart->series[$index]->color = getColor($colorIndex); $chart->series[$index]->data = $dataAvg; $chart->series[$index]->lineWidth = 1; $chart->series[$index]->marker->radius = 2; $index++; } if ($_GET['qoe'] == 'QoE On' || $_GET['qoe'] == 'Both') { $chart->series[]->name = $ldata['plan'] . '-QoE'; $chart->series[$index]->type = 'spline'; $chart->series[$index]->color = getColor($colorIndex); $chart->series[$index]->dashStyle = 'shortdot'; $chart->series[$index]->data = $dataQoE; $chart->series[$index]->lineWidth = 1; $chart->series[$index]->marker->radius = 2; $index++; } $colorIndex++; } } $title = 'Average by Plan for "' . $item; $subtitle = 'From ' . $ldata['from'] . ' to ' . $ldata['to']; $chart = chartHeader($chart, $id_chart, $title, $subtitle, $unit, null); $chart->xAxis->type = 'datetime'; if (!isset($minClock)) { $minclock = 0; $maxClock = 0; } $chart->tooltip->formatter = new HighchartJsExpr("\n function() {\n var s = '<b>'+ Highcharts.dateFormat('%e. %b %H:%M',this.x) + '</b>'; \n \$.each(this.points, function(i, point) {\n s += '<br/><span style=\"color:'+point.series.color+'\">'+ point.series.name +': '+ point.y +' " . $unit . "</span><b>';\n });\n return s;\n }"); echo "\n" . '<script> function redraw() { chart1.xAxis[0].setExtremes(' . round($minClock / (60 * 60), 0) * 60 * 60 . ', ' . round(($maxClock + 60 * 60 * 4 * 1000) / (60 * 60), 0) * 60 * 60 . ');} </script>'; return $chart; }
function GraphGroup($chart, $id_chart, $item, $itemName, $from, $avg, $type) { $offset = getOffset(); setTimezone(); $dt = getDates($from); $from = $dt[0]; $to = $dt[1]; $chart->chart->renderTo = $id_chart; $chart->chart->zoomType = 'x'; $chart->chart->spacingRight = 20; $chart->xAxis->type = 'datetime'; $chart->xAxis->lineWidth = 0; $chart->xAxis->tickWidth = 1; $chart->chart->shadow = true; $chart->chart->plotShadow = true; $chart->yAxis->startOnTick = false; $chart->yAxis->showFirstLabel = false; $chart->yAxis->min = 0; $chart->xAxis->gridLineWidth = 1; $chart->tooltip->shared = true; $chart->legend->enabled = true; $chart->subtitle->text = 'From ' . $from . ' to ' . $to; $index = 0; $thezero = '-1'; $average = getAverage($avg); $format = $average[0]; $divide = $average[1]; $filterHost = ''; if ($_GET['host'] != '') { $filterHost = ' and host="' . $_GET['host'] . '" '; } switch ($type) { case 'YouTube': $list = '%video youtube%AVG%'; $txt = 'Youtube Average for Plan ' . $_GET['plan']; if ($_GET['host'] != '') { $txt .= ' for Sonda ' . $_GET['host']; } $chart->title->text = $txt; break; case 'File': $list = 'file download% speed'; $txt = 'File Download Average for Plan ' . $_GET['plan']; if ($_GET['host'] != '') { $txt .= ' for Sonda ' . $_GET['host']; } $chart->title->text = $txt; break; case 'Video': $list = 'Video %experience%'; $txt = 'Video Experience for Plan ' . $_GET['plan']; if ($_GET['host'] != '') { $txt .= ' for Sonda ' . $_GET['host']; } $chart->title->text = $txt; break; case 'Ping': $list = 'ping%avg%'; $txt = 'Ping Average for Plan ' . $_GET['plan']; if ($_GET['host'] != '') { $txt .= ' for Sonda ' . $_GET['host']; } $chart->title->text = $txt; break; } $thezero = '0'; $q = 'select distinct descriptionLong from bm_items where descriptionLong like "' . $list . '" order by 1'; $q1 = mysql_query($q); while ($r = mysql_fetch_array($q1, MYSQL_ASSOC)) { $desc = $r['descriptionLong']; $query = "SELECT descriptionLong,unix_timestamp(date_format(from_unixtime(round(clock/" . $divide . ",0)*" . $divide . "),'" . $format . "')) as clk,\n round(avg(value),0) as value,\n max(unit) as unit \n FROM bm_host,bm_items,bm_history,bm_plan,bm_host_groups\n WHERE bm_host.id_host=bm_history.id_host and bm_history.id_item=bm_items.id_item and descriptionLong = '" . $desc . "'\n and bm_host.id_plan=bm_plan.id_plan \n and clock between unix_timestamp('" . $from . "') and unix_timestamp('" . $to . " 23:59:59')+3600*24\n and value > " . $thezero . "\n and plan='" . $_GET['plan'] . "' " . $filterHost . " \n and bm_host_groups.groupid=bm_host.groupid\n and bm_host_groups.groupid=" . $_SESSION['groupid'] . "\n GROUP BY descriptionLong,unit,unix_timestamp(date_format(from_unixtime(round(clock/" . $divide . ",0)*" . $divide . "),'" . $format . "'))\n ORDER BY 1"; //var_dump($query); $result = mysql_query($query) or die("SQL Error 1: " . mysql_error()); unset($data2); $unit = ''; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $unit = $row['unit']; $div = 1; if ($unit == 'bps') { $div = 1024 * 1024; $unit = 'Mbps'; } $data2[] = array($row['clk'] * 1000, round($row['value'] * 1 / $div, 2)); } $chart->yAxis->title->text = $unit; //$chart->tooltip->formatter = new HighchartJsExpr("function() { return '<b>'+ this.series.name +'</b><br/>'+ Highcharts.dateFormat('%e. %b %H:%M', this.x) +': '+ Highcharts.numberFormat(this.y, 2, ',') +' " . $unit . "';}"); $chart->series[]->name = $desc; $chart->series[$index]->type = 'spline'; $chart->series[$index]->data = $data2; $index++; } } return $chart; }
function graphCompare($chart, $item, $min, $max, $ch) { echo '<div class="col-xs-2"><select class="form-control" name="' . $item . '" id="' . $item . '">'; if (!isset($_POST[$item])) { $_POST[$item] = ''; echo '<option selected value="Seleccione">Select</option>'; } else { echo '<option value="Seleccione">Select</option>'; } $itemsSelected = ''; $monitors = readMonitors(); foreach ($monitors as $items) { if (isset($_POST) && $_POST[$item] == $items['id_item']) { $itemsSelected = $items['descriptionLong']; echo '<option selected value="' . $items['id_item'] . '">' . $items['descriptionLong'] . '</option>'; } else { echo '<option value="' . $items['id_item'] . '">' . $items['descriptionLong'] . '</option>'; } $itemsArry[$items['id_item']] = array("unit" => $items['unit'], "name" => $items['descriptionLong']); } echo '</select></div>'; $index = 0; if (isset($_POST['date1'])) { $days = Days($_POST['date1'], $_POST['date2']); } if (!isset($_POST['avg'])) { $_POST['avg'] = '4 Hours'; } $divide = getAverage($_POST['avg']); $divide = $divide[1]; /* $days = 1; $days = Days($_POST['date1'], $_POST['date2']); if ($days > 7 * 1) $format = '%Y/%m/%d %H:00:00'; if ($days > 7 * 2) $divide = 3600 * 4; if ($days > 7 * 4) $divide = 3600 * 6; if ($days > 7 * 5) $format = '%Y/%m/%d'; if ($days > 7 * 8) $divide = 3600 * 24 * 7; if ($days > 7 * 16) $format = '%Y/%m'; */ $col = 0; $timeStart = strtotime($_POST['date1'] . ' 00:00:00'); $timeFinish = strtotime($_POST['date2'] . ' 23:59:59'); $hosts = readHosts(0); foreach ($hosts as $r) { $unit = getUnit($_POST[$item]); $div = 1; if ($unit == 'bps') { $div = 1024; ///BUGS BGS009 $unit = 'Mbps'; } $sonda = $r['host']; $id_host = $r['id_host']; $id_item = $_POST[$item]; if ($id_item > 0) { $rawData = loadRAWData($_POST['date1'], 0, $id_item, $_POST['date2'], $id_host); $history = $rawData['historyList'][$id_host]; unset($finalData); unset($data2); if (isset($history)) { foreach ($history as $ddata) { $tk = round($ddata['clock'] / $divide, 0) * $divide; if (!isset($finalData[$tk])) { $finalData[$tk] = array('clock' => $tk, 'sum' => 0, 'cnt' => 0); } $sum = $finalData[$tk]['sum']; $cnt = $finalData[$tk]['cnt']; $x = $sum + $ddata['value']; $y = $cnt + 1; $finalData[$tk] = array('clock' => $tk, 'sum' => $x, 'cnt' => $y); } $data2[] = array($timeStart * 1000, null); foreach ($finalData as $row) { if ($row['cnt'] != 0) { $v = round($row['sum'] / $row['cnt'] * 1 / $div, 2); } $data2[] = array($row['clock'] * 1000, $v * 1 / $div, 2); if (!isset($minClock)) { $minClock = $row['clock']; $maxClock = $row['clock']; $maxClockIndex = $index; } else { if ($minClock > $row['clock']) { $minClock = $row['clock']; } if ($maxClock < $row['clock']) { $maxClock = $row['clock']; $maxClockIndex = $index; } } } } if (isset($data2)) { $data2[] = array($timeFinish * 1000, null); $chart->yAxis->title->text = $unit; $chart->series[]->name = $sonda; $chart->series[$index]->type = 'spline'; $chart->series[$index]->data = $data2; $chart->series[$index]->color = getColor($col); $index++; } unset($rawData); unset($history); $col++; } } if (!isset($maxClock)) { $maxClock = 0; $minClock = 0; } if (!isset($unit)) { $unit = ""; } $title = getItem($_POST[$item]); $subtitle = 'From ' . $_POST['date1'] . ' to ' . $_POST['date2']; $chart = chartHeader($chart, 'c_' . $item, $title, $subtitle, $unit, null); $chart->xAxis->type = 'datetime'; //$chart->plotOptions->series->animation->complete = new HighchartJsExpr(" function () {redraw" . $ch . "();}"); $chart->tooltip->formatter = new HighchartJsExpr("\n function() {\n var s = '<b>'+ Highcharts.dateFormat('%e. %b %H:%M',this.x) +'</b>'; \n \$.each(this.points, function(i, point) {\n s += '<br/><span style=\"color:'+point.series.color+'\">'+ point.series.name +': '+ point.y +' " . $unit . "</span><b>';\n });\n return s;\n }"); //echo "\n" . '<script> function redraw' . $ch . '() { ' . $ch . '.xAxis['.$maxClockIndex.'].setExtremes(' . $minClock* 1000 . ', ' . $maxClock* 1000 . ');} </script>'; return $chart; }