Advertisement
Artem78

Untitled

Jun 30th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.59 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.     error_reporting(E_ERROR);
  5.     ini_set('display_errors', 1);
  6.  
  7.     date_default_timezone_set('Europe/Moscow');
  8.     setlocale(LC_ALL, 'ru_RU.UTF-8');
  9.  
  10.     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Datum aus Vergangenheit
  11.     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  12.     header("Cache-Control: no-store, no-cache, must-revalidate");
  13.     header("Cache-Control: post-check=0, pre-check=0", false);
  14.     header("Pragma: no-cache");
  15.  
  16.     require_once('lib/phplot-6.2.0/phplot.php');
  17.     require_once('config.php');
  18.  
  19.  
  20.  
  21.     $mysqli = new mysqli($cfg['db_host'], $cfg['db_user'], $cfg['db_pass'], $cfg['db_base']) or die(mysqli_connect_error());
  22.     $mysqli->set_charset("utf8");
  23.  
  24.  
  25.  
  26.     $data = array();
  27.  
  28.     $query = "SELECT * FROM `sms` WHERE `date` >= now() - interval 30 day";
  29.     $res = $mysqli->query($query);
  30.     if ($res) {
  31.         while ($row = $res->fetch_assoc()) {
  32.             $name = $row['order_id'] . ' ' . $row['offer'];
  33.             if (!$data[$name]) {
  34.                 $data[$name] = array();
  35.             }
  36.  
  37.             $date = getdate(strtotime($row['date']));
  38.             $hour = $date['hours'] + $date['minutes'] / 60;
  39.             $hours = array('', '', '', '', '', '');
  40.  
  41.             if ($row['type'] == 'text' && $row['status'] == -1) {
  42.                 $hours[0] = $hour;
  43.             } if ($row['type'] == 'text' && $row['status'] == 0) {
  44.                 $hours[1] = $hour;
  45.             } if ($row['type'] == 'text' && $row['status'] == 1) {
  46.                 $hours[2] = $hour;
  47.             } if ($row['type'] == 'voice' && $row['status'] == -1) {
  48.                 $hours[3] = $hour;
  49.             } if ($row['type'] == 'voice' && $row['status'] == 0) {
  50.                 $hours[4] = $hour;
  51.             } if ($row['type'] == 'voice' && $row['status'] == 1) {
  52.                 $hours[5] = $hour;
  53.             }
  54.  
  55.             $data[$name][] = array(
  56.                 '',
  57.                 strtotime($row['date']),
  58.                 $hours[0],
  59.                 $hours[1],
  60.                 $hours[2],
  61.                 $hours[3],
  62.                 $hours[4],
  63.                 $hours[5],
  64.             );
  65.         }
  66.     }
  67.  
  68.     //var_dump($data);
  69.     /////////
  70.     $data = array_slice($data, 0, 3);
  71.     ///////////
  72.  
  73.  
  74.  
  75.     $w = 1600;
  76.     $h = 280;
  77.  
  78.     $start_date = time() - 29 * 60 * 60 * 24;
  79.     $end_date = time() + 1 * 60 * 60 * 24;
  80.  
  81.     //$plot = new PHPlot($w, $h * count($data));
  82.     /////////
  83.     $plot = new PHPlot($w, $h * count($data));
  84.     /////////
  85.     $plot->SetImageBorderType('plain');
  86.  
  87.  
  88.  
  89.     $plot->SetPlotType('points');
  90.     $plot->SetDataType('data-data');
  91.     //$plot->SetDrawBrokenLines($true);
  92.  
  93.     $plot->SetXLabelType('time', '%d %b');
  94.     $plot->SetXTickIncrement(24 * 60 * 60);
  95.     $plot->SetYTickIncrement(1);
  96.  
  97.     //$plot->SetYTitle('Часы (по местному времени)');
  98.     $plot->SetYTitle('Часы (MSK)');
  99.  
  100.     $plot->SetDataColors(array(
  101.         array(178, 34, 34),
  102.         array(255, 165, 0),
  103.         array(30, 144, 255),
  104.         array(178, 34, 34),
  105.         array(255, 165, 0),
  106.         array(30, 144, 255)
  107.     ));
  108.  
  109.     $plot->TuneYAutoRange(0);
  110.     $plot->SetPointShapes(array('delta', 'delta', 'delta', 'rect', 'rect', 'rect'));
  111.  
  112.     $plot->SetLegend(array(
  113.         'текст. ошибка',
  114.         'текст. неизвестно',
  115.         'текст. успех',
  116.         'голос. ошибка',
  117.         'голос. неизвестно',
  118.         'голос. успех',
  119.     ));
  120.     $plot->SetUseTTF(true);
  121.  
  122.     $plot->SetDrawXGrid(true);
  123.     $plot->SetDrawYGrid(true);
  124.  
  125.     $plot->SetPlotAreaWorld($start_date, 0, $end_date, 24);
  126.  
  127.     $plot->SetPrintImage(0);
  128.  
  129.     //$plot->SetMarginsPixels(null, null);
  130.  
  131.     $i = 0;
  132.     foreach (array_keys($data) as $title) {
  133.         //$plot->SetPlotAreaPixels(40, 40, $w - 40 * 2, $i * $h + $h - 40 * 2);
  134.         $plot->SetPlotAreaPixels(null, $h * $i, null, $h);
  135.         //$plot->SetMarginsPixels(20, 20, 20, 20);
  136.  
  137.         $plot->SetYTitle("Заказ №$title");
  138.         $plot->SetDataValues($data[$title]);
  139.  
  140.         $plot->DrawGraph();
  141.  
  142.         $i++;
  143.     }
  144.  
  145.  
  146.     $plot->PrintImage();
  147.  
  148.  
  149.  
  150.  
  151.     $mysqli->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement