PageRenderTime 46ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/webfrontend/www/include/graph_probe_drops_bar01.php

https://github.com/mobilipia/IPTV-Analyzer
PHP | 151 lines | 90 code | 21 blank | 40 comment | 19 complexity | eaf9d2c126ccb664f4a98d5b74008829 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. require_once 'Image/Graph.php';
  13. require_once 'Image/Canvas.php';
  14. ini_set('include_path',ini_get('include_path').':../:staging/');
  15. require_once("graphs.inc.php");
  16. require_once("functions.inc.php");
  17. $_REQUEST = cleanup_input_request();
  18. $probeid = $_REQUEST['probeid'];
  19. $maxy = $_REQUEST['maxy'];
  20. $bucketsz = $_REQUEST['bucketsz'];
  21. $tstampF = $_REQUEST['tstampF'];
  22. $tstampT = $_REQUEST['tstampT'];
  23. /* A check for DB connectivity */
  24. global $DBH;
  25. if (!$DBH) {
  26. $err = "No database connection";
  27. echo "<h3>$err</h3>\n";
  28. exit;
  29. /*
  30. db_connect();
  31. $probes = probes_info_query();
  32. echo "\n<h4>Please select a probe:</h4>\n";
  33. probes_info_form_tabel($probes, $probeid);
  34. */
  35. }
  36. # INPUT parsing
  37. # -------------
  38. $valid = true;
  39. if (!$probeid) {
  40. $valid = false;
  41. $err = "<h3>Please choose a valid probe</h3>";
  42. die("$err");
  43. } else {
  44. $probe = $probes[$probeid];
  45. if (!is_array($probe)) {
  46. $valid = false;
  47. } else {
  48. // extract probename, switch and shortloc
  49. $probename = $probe['name'];
  50. $switch = $probe['switch'];
  51. $shortloc = $probe['shortloc'];
  52. }
  53. }
  54. if ($probename == "") {
  55. $probename = "probeID:$probeid";
  56. }
  57. $droptype = $_REQUEST['droptype'];
  58. if ($droptype == "") {
  59. // Default drop type
  60. $droptype = 'drops';
  61. } elseif (($droptype != 'skips') && ($droptype != 'drops')) {
  62. $droptype = "INVALID-DROPTYPE";
  63. $valid = false;
  64. }
  65. $title = "$droptype on $probename/$switch/$shortloc";
  66. # GRAPH creation
  67. # --------------
  68. $Graph = & create_graph_usemap01();
  69. $Font = & $Graph->_font;
  70. $Plotarea = &create_plotarea_with_title01($Graph, $Font, $title);
  71. // Create the dataset
  72. $Dataset =& Image_Graph::factory('dataset');
  73. // Create the 1st plot as 'bar' chart using the 1st dataset
  74. $Plot =& $Plotarea->addNew('bar', array(&$Dataset));
  75. //$Plotarea->hideAxis('x');
  76. $Plotarea->setAxisPadding(3);
  77. $Fill =& Image_Graph::factory('Image_Graph_Fill_Array');
  78. $Fill->addColor('red', 'DROPS');
  79. $Fill->addColor('darkred', 'EXCESS');
  80. $Plot->setFillStyle($Fill);
  81. // set a line color
  82. $Plot->setLineColor('darkred');
  83. //set a standard fill style
  84. //$Plot->setFillColor('red@0.9');
  85. $AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
  86. $AxisX->setFontAngle(70);
  87. #
  88. # Needs auto adjustment
  89. #$AxisX->setLabelOption('dateformat', 'Y-m-d (\HH)');
  90. $AxisX->setLabelOption('dateformat', 'Y-m-d');
  91. #$AxisX->setLabelInterval(200);
  92. # DATA addPoints
  93. # --------------
  94. $max_y_value=5000;
  95. # query data
  96. if (is_numeric($bucketsz)) {
  97. $sec = $bucketsz;
  98. } else {
  99. $sec = 24 * 60 * 60; // One day
  100. }
  101. $data = probe_data_query_ts($probeid, $sec, $tstampF, $tstampT);
  102. //probe_data_show_table($data);
  103. //db_disconnect();
  104. $urldata['bucketsz']=$bucketsz;
  105. $urldata['probeid'] =$probeid;
  106. if ($valid == true) {
  107. // Call data_addPoints()
  108. $records = data_addPoints01($Dataset, $data, $droptype, $max_y_value, $urldata);
  109. } else {
  110. $err = "Invalid input data cannot proceed";
  111. trigger_error("$err", E_USER_ERROR);
  112. }
  113. $filename = generateFilename("probe_drops_bar01", $_REQUEST, 'png');
  114. // Special output the Graph
  115. $output = $Graph->done(
  116. array(
  117. 'tohtml' => True,
  118. 'showtime' => True,
  119. 'border' => 0,
  120. 'filename' => $filename,
  121. 'filepath' => './graphs/',
  122. 'urlpath' => 'graphs/'
  123. )
  124. );
  125. if ($records > 0) {
  126. print $output;
  127. } else {
  128. echo "<h3>Graph: No data available in choosen period</h3>";
  129. }
  130. ?>