PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/webfrontend/www/include/graph_probe_drops_bar02.php

https://github.com/mobilipia/IPTV-Analyzer
PHP | 210 lines | 111 code | 40 blank | 59 comment | 25 complexity | 7e95772ff9e17735b8ff8bd9fb2e8dfe MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php /* -*- Mode: php; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /**
  3. * Graph over the drops on a probe
  4. *
  5. * This script needs to be included from another script that has the
  6. * DB connection and has selected array with the probes.
  7. *
  8. * Feature:
  9. * Use of HTML map, which allow a clickable graph.
  10. *
  11. */
  12. #$displayTiming = TRUE;
  13. $startg=getMicroTime();
  14. require_once 'Image/Graph.php';
  15. require_once 'Image/Canvas.php';
  16. ini_set('include_path',ini_get('include_path').':../:staging/');
  17. require_once("graphs.inc.php");
  18. require_once("functions.inc.php");
  19. $_REQUEST = cleanup_input_request();
  20. $probeid = $_REQUEST['probeid'];
  21. #$maxy = $_REQUEST['maxy'];
  22. $bucketsz = $_REQUEST['bucketsz'];
  23. /* A check for DB connectivity */
  24. global $DBH;
  25. if (!$DBH) {
  26. $err1 = "WARNING - This script is intended to be include, not used directly";
  27. $err2 = "Allowing your to continue, for testing purposes, establish DB conn";
  28. echo "<h3>$err1</h3>\n";
  29. echo "<h4>$err2</h4>\n";
  30. #exit;
  31. db_connect();
  32. $localdb = TRUE;
  33. $probes = probes_info_query();
  34. echo "\n<h4>Please select a probe:</h4>\n";
  35. probes_info_form_tabel($probes, $probeid);
  36. }
  37. $tstampF = $_REQUEST['tstampF'];
  38. $tstampT = $_REQUEST['tstampT'];
  39. # INPUT parsing
  40. # -------------
  41. $valid = true;
  42. if (!$probeid) {
  43. $valid = false;
  44. $err = "<h3>Please choose a valid probe</h3>";
  45. die("$err");
  46. } else {
  47. $probe = $probes[$probeid];
  48. if (!is_array($probe)) {
  49. $valid = false;
  50. } else {
  51. // extract probename, switch and shortloc
  52. $probename = $probe['name'];
  53. $switch = $probe['switch'];
  54. $shortloc = $probe['shortloc'];
  55. }
  56. }
  57. if ($probename == "") {
  58. $probename = "probeID:$probeid";
  59. }
  60. $droptype = $_REQUEST['droptype'];
  61. if ($droptype == "") {
  62. // Default drop type
  63. $droptype = 'drops';
  64. } elseif (($droptype != 'skips') && ($droptype != 'drops')) {
  65. $droptype = "INVALID-DROPTYPE";
  66. $valid = false;
  67. }
  68. $title = "$droptype on $probename/$switch/$shortloc";
  69. # GRAPH creation
  70. # --------------
  71. $Graph = & create_graph_usemap01();
  72. $Font = & $Graph->_font;
  73. $Plotarea = &create_plotarea_with_title02($Graph, $Font, $title);
  74. #$Title = $Graph->addNew('title', array("$title", 10));
  75. #$Plotarea = $Title->addNew('plotarea', array('axis', 'axis'));
  76. #$Plotarea->setFont($Font);
  77. // Create the dataset
  78. $Dataset =& Image_Graph::factory('dataset');
  79. #$Dataset_fake =& Image_Graph::factory('dataset');
  80. # DATA addPoints
  81. # --------------
  82. $max_y_value = $_REQUEST['maxy'];
  83. # query data
  84. if (is_numeric($bucketsz)) {
  85. $sec = $bucketsz;
  86. } else {
  87. $sec = 24 * 60 * 60; // One day
  88. }
  89. $startq=getMicroTime();
  90. $data = probe_data_query_ts($probeid, $sec, $tstampF, $tstampT);
  91. displayTimingInfo($startq, getMicroTime(), $displayTiming, "probe_data_query");
  92. //probe_data_show_table($data);
  93. if ($localdb == TRUE)
  94. db_disconnect();
  95. $urldata['bucketsz']=$bucketsz;
  96. $urldata['probeid'] =$probeid;
  97. if ($valid == true) {
  98. // Trick we add two datapoints, Start and End of the period we are plotting.
  99. $Dataset->addPoint($tstampF, 0);
  100. // Call data_addPoints()
  101. $records = data_addPoints01($Dataset, $data, $droptype,
  102. $max_y_value, $urldata);
  103. // End datapoint
  104. $Dataset->addPoint($tstampT, 0);
  105. # $fakerec = data_addPoints_fake($Dataset_fake, $bucketsz,
  106. # $tstampF, $tstampT, $urldata);
  107. } else {
  108. $err = "Invalid input data cannot proceed";
  109. trigger_error("$err", E_USER_ERROR);
  110. }
  111. // Create the 1st plot as 'bar' chart using the 1st dataset
  112. #$Plot =& $Plotarea->addNew('line', array(&$Dataset));
  113. #$Plot =& $Plotarea->addNew('area', array(&$Dataset));
  114. #$Plot =& $Plotarea->addNew('step', array(&$Dataset));
  115. #$Plot =& $Plotarea->addNew('Image_Graph_Plot_Band', array(&$Dataset));
  116. #$Plot =& $Plotarea->addNew('impulse', array(&$Dataset));
  117. $Plot =& $Plotarea->addNew('bar', array(&$Dataset));
  118. #$Plot2 =& $Plotarea->addNew('bar', array(&$Dataset_fake));
  119. #$percent = calcBarWidthPercentage($bucketsz, $tstampF, $tstampT, $records);
  120. #$Plot->setBarWidth($percent,"%");
  121. setBarWidth($Plot, $bucketsz, $tstampF, $tstampT, $records);
  122. #echo "procent: $procent (rec: $records)<br>";
  123. #$AllDatasets[0] =& $Dataset;
  124. #$AllDatasets[1] =& $Dataset_fake;
  125. #$Plot =& $Plotarea->addNew('Image_Graph_Plot_Bar', array($AllDatasets, 'stacked'));
  126. //$Plotarea->hideAxis('x');
  127. $Plotarea->setAxisPadding(3);
  128. $Fill =& Image_Graph::factory('Image_Graph_Fill_Array');
  129. $Fill->addColor('red', 'DROPS');
  130. $Fill->addColor('darkred', 'EXCESS');
  131. $Fill->addColor('yellow', 'NODROPS');
  132. $Plot->setFillStyle($Fill);
  133. // set a line color
  134. $Plot->setLineColor('darkred');
  135. //set a standard fill style
  136. //$Plot->setFillColor('red@0.9');
  137. $AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
  138. #$AxisX->setFontAngle(70);
  139. #
  140. # Needs auto adjustment
  141. $AxisX->setLabelOption('dateformat', "Y-m-d\nH:i:s");
  142. #$AxisX->setLabelOption('dateformat', 'Y-m-d (\HH)');
  143. #$AxisX->setLabelOption('dateformat', 'Y-m-d');
  144. #$AxisX->setLabelInterval(200);
  145. // Fix the Y-axis max
  146. $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
  147. if ($_REQUEST['maxy_fixed'] == "fixed") {
  148. if (is_numeric($max_y_value)) {
  149. $AxisY->forceMaximum($max_y_value);
  150. }
  151. }
  152. $filename = generateFilename("probe_drops_bar02", $_REQUEST, 'png');
  153. // Special output the Graph
  154. $output = $Graph->done(
  155. array(
  156. 'tohtml' => True,
  157. 'showtime' => $displayTiming,
  158. 'border' => 0,
  159. 'filename' => $filename,
  160. 'filepath' => './graphs/',
  161. 'urlpath' => 'graphs/'
  162. )
  163. );
  164. if ($records > 0) {
  165. print $output;
  166. } else {
  167. echo "<h3>Graph: No data available in choosen period</h3>";
  168. }
  169. displayTimingInfo($startg, getMicroTime(), $displayTiming, "graph_bar02 done");
  170. ?>