Ignore:
Timestamp:
May 11, 2014, 4:28:01 PM (10 years ago)
Author:
chronos
Message:
  • Opraveno: Zobrazování grafů mřených veličin.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/TimeMeasure/Graph.php

    r569 r655  
    11<?php
    22
    3 class GraphView extends View
     3class PageGraph extends Page
    44{
     5  var $FontSize;
     6  var $FontFileName;
     7  var $ValueToImageHeigthCoefficient;
     8  var $DefaultWidth;
     9  var $DefaultHeight;
     10
     11  function __construct($System)
     12  {
     13    parent::__construct($System);
     14    $this->FontSize = 10;
     15    $this->FontFileName = 'Arial.ttf';
     16    $this->ValueToImageHeigthCoefficient = 0.9;
     17  }
     18
     19  function Show()
     20  {
     21    $this->ClearPage = true;
     22        return($this->Render());
     23  }
     24
    525  function Render()
    626  {
    7     if(array_key_exists('Debug', $_GET)) $Debug = $_GET['Debug'];
     27    $PrefixMultiplier = new PrefixMultiplier();
     28
     29    if(array_key_exists('Debug', $_GET)) $Debug = $_GET['Debug'];
    830      else $Debug = 0;
    9  
     31
    1032    if(!array_key_exists('From', $_GET)) die('Musíte zadat čas počátku');
    1133    $StartTime = addslashes($_GET['From']);
     
    1537    $TimeDifference = $EndTime - $StartTime;
    1638    if(!array_key_exists('Measure', $_GET)) die('Musíte zadat měřenou veličinu');
    17     $MeasureId = addslashes($_GET['Measure']);   
    18     if(!array_key_exists('Width', $_GET)) $Width = $DefaultWidth;
     39    $MeasureId = addslashes($_GET['Measure']);
     40    if(!array_key_exists('Width', $_GET)) $Width = $this->DefaultWidth;
    1941      else $Width = addslashes($_GET['Width']);
    20     if(!array_key_exists('Height', $_GET)) $Height = $DefaultHeight;
     42    if(!array_key_exists('Height', $_GET)) $Height = $this->DefaultHeight;
    2143      else $Height = addslashes($_GET['Height']);
    2244    if(!array_key_exists('Differential', $_GET)) $Differential = $this->Config['Application']['DefaultVariables']['Differential'];
    2345      else $Differential = addslashes($_GET['Differential']);
    24     $VerticalLinesCount = round($Height / ($this->Config['Application']['FontSize'] + 4));
    25 
    26     $StopWatchStart = $this->System->GetMicrotime();
     46    $VerticalLinesCount = round($Height / ($this->FontSize + 4));
     47
     48    $StopWatchStart = GetMicrotime();
    2749
    2850    $Measure = new Measure($this->System);
    2951    $Measure->Load($MeasureId);
    30     $Measure->LevelReducing = $this->Config['Application']['LevelReducing'];
    31     $Measure->ReferenceTime = $this->Config['Application']['ReferenceTime'];
    32     $Measure->MaxLevel = $this->Config['Application']['MaxLevel'];
    33     $Measure->DivisionCount = $this->Config['Application']['DivisionCount'];
    34     $Measure->Differential = $this->Config['Application']['DefaultVariables']['Differential'];
     52    //$Measure->LevelReducing = $this->LevelReducing;
     53    //$Measure->ReferenceTime = $this->Config['Application']['ReferenceTime'];
     54    //$Measure->MaxLevel = $this->Config['Application']['MaxLevel'];
     55    //$Measure->DivisionCount = $this->Config['Application']['DivisionCount'];
     56    //$Measure->Differential = $this->Config['Application']['DefaultVariables']['Differential'];
    3557    $Measure->Debug = $Debug;
    3658    $DbResult2 = $this->Database->select('MeasureMethod', '*', 'Id='.$Measure->Data['Method']);
    3759    $MeasureMethod = $DbResult2->fetch_assoc();
    3860
    39     $FontSize = $this->Config['Application']['FontSize'];
    40     $FontFile = dirname(__FILE__).'/../Style/'.$this->Config['System']['Style'].'/'.$this->Config['Application']['FontFileName'];
     61    $FontSize = $this->FontSize;
     62    $FontFile = dirname(__FILE__).'/../../style/'.$this->System->Config['Web']['Style'].'/'.$this->FontFileName;
    4163
    4264    $Level = floor(log(($EndTime - $StartTime) / $Measure->DivisionCount / 60) / log($Measure->LevelReducing)) - 1;
     
    4769    $Points = $Measure->GetValues($StartTime, $EndTime, $Level);
    4870
    49     if($Debug) echo('Points count: '.count($Points).'<br/>'); 
    50     //if($Debug) foreach($Points as $Index => $Item) 
     71    if($Debug) echo('Points count: '.count($Points).'<br/>');
     72    //if($Debug) foreach($Points as $Index => $Item)
    5173    // echo($Index.': '.$Item['min'].'<br>');
    5274
     
    7092    $AvgValue = $AvgValue / count($Points); //round( * $Measure['Divider']) / $Measure['Divider'];
    7193
    72     // Generate polygon and recalculate y values to fit graph height 
     94    // Generate polygon and recalculate y values to fit graph height
    7395    $PointsMin = array(0, $Height - 1);
    7496    $PointsAvg = array(0, $Height - 1);
    7597    $PointsMax = array(0, $Height - 1);
    7698    if(($MaxValue - $MinValue) == 0) $MaxValue = $MinValue + 1;
    77     { 
     99    {
    78100      foreach($Points as $Index => $Item)
    79101      {
    80102        $PointsMin[] = $Index * $Width / $Measure->DivisionCount;
    81         $PointsMin[] = $Height - 1 - ($Points[$Index]['Min'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->Config['Application']['ValueToImageHeigthCoefficient'];
     103        $PointsMin[] = $Height - 1 - ($Points[$Index]['Min'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient;
    82104        $PointsAvg[] = $Index * $Width / $Measure->DivisionCount;
    83         $PointsAvg[] = $Height - 1 - ($Points[$Index]['Avg'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->Config['Application']['ValueToImageHeigthCoefficient'];
     105        $PointsAvg[] = $Height - 1 - ($Points[$Index]['Avg'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient;
    84106        $PointsMax[] = $Index * $Width / $Measure->DivisionCount;
    85         $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->Config['Application']['ValueToImageHeigthCoefficient'];
     107        $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient;
    86108        //echo($Index.' - '.$Item.' '.$Points[$Index].'<br>');
    87109      }
     
    107129
    108130    //print_r($PointsMax);
    109  
     131
    110132    // Generate image
    111     if(!$Debug) 
     133    if(!$Debug)
    112134    {
    113135      Header('Content-type: image/png');
    114       Header('Cache-Control: no-cache');  // Dynamic graph - no cache 
     136      Header('Cache-Control: no-cache');  // Dynamic graph - no cache
    115137      $Image = @imagecreate($Width, $Height);
    116138      $BackgroundColor = imagecolorallocate($Image, 255, 255, 255);
     
    129151      imagefilledpolygon($Image, $PointsAvg, count($PointsAvg) / 2, $LightGreen);
    130152      imagefilledpolygon($Image, $PointsMin, count($PointsMin) / 2, $LightBlue);
    131  
     153
    132154      $TimeMarks = array(1, 60, 60*60, 60*60*24, 60*60*24*7, 60*60*24*30, 60*60*24*365, 60*60*24*365*10);
    133  
     155
    134156      $TimeRange = $EndTime - $StartTime;
    135157      $TimeMarksIndex = 0;
     
    137159      if($TimeMarksIndex < 2) $TimeMarksIndex = 2;
    138160      $MajorTimeMarks = $TimeMarks[$TimeMarksIndex - 1];
    139       $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2]; 
    140    
    141       $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime; 
     161      $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2];
     162
     163      $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime;
    142164      //imagestring($Image, 10, 40, 50, $TimeShift, $Black);
    143  
     165
    144166      // Zobraz měřítko Y
    145167      $VerticalLinesDistance = $Height / $VerticalLinesCount;
     
    149171        for($X = 1; $X < $Width; $X = $X + 3) imagesetpixel($Image, $X, $Y, $Gray);
    150172        //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED);
    151       } 
    152 
    153       $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime; 
    154  
     173      }
     174
     175      $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime;
     176
    155177      // Zobraz měřítko X
    156178      $LastTextEnd = 0;
    157179      for($Time = $StartTime; $Time < $EndTime; $Time += $MajorTimeMarks)
    158180      {
    159         $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width; 
     181        $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width;
    160182        //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED);
    161183        if(($MajorTimeMarks > 60 * 60 * 24)) $Text = date('j.n.Y', $Time + $TimeShift);
     
    169191        }
    170192        else for($Y = 0; $Y < $Height; $Y = $Y + 3) imagesetpixel($Image, $X, $Y, $Gray);
    171       } 
    172  
     193      }
     194
    173195      // Popisky osy Y
    174196      for($I = 1; $I <= $VerticalLinesCount; $I++)
    175197      {
    176198        $Y = $Height - 1 - ($VerticalLinesDistance * $I);
    177         //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) * $this->Config['Application']['ValueToImageHeigthCoefficient'] * $Height);
    178         $Text = $this->System->AddPrefixMultipliers(round(($I * $VerticalLinesDistance / $Height / $this->Config['Application']['ValueToImageHeigthCoefficient'] * ($MaxValue - $MinValue) + $MinValue)), $MeasureMethod['Unit'], 3);
     199        //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) *
     200        //  $this->ValueToImageHeigthCoefficient * $Height);
     201        $Text = $PrefixMultiplier->Add(round(($I * $VerticalLinesDistance / $Height /
     202          $this->ValueToImageHeigthCoefficient * ($MaxValue - $MinValue) + $MinValue)), $MeasureMethod['Unit'], 3);
    179203        $BoundBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    180204        if(($Y - ($BoundBox[5] - $BoundBox[1]) / 2) > 10)
    181205          imagettftext($Image, $FontSize, 0, 2,  $Y - ($BoundBox[5] - $BoundBox[1]) / 2, $Black, $FontFile, $Text);
    182       } 
    183       $GenerationTime = floor(($this->System->GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
     206      }
     207      $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
    184208
    185209      $Left = $Width - 10;
    186       $Text = '    Max. '.$this->System->AddPrefixMultipliers($MaxValue, $MeasureMethod['Unit']);
     210      $Text = '    Max. '.$PrefixMultiplier->Add($MaxValue, $MeasureMethod['Unit']);
    187211      $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    188212      $Left -= ($BoundingBox[2] - $BoundingBox[0]);
    189213      imagettftext($Image, $FontSize, 0, $Left, 14, $Red, $FontFile, $Text);
    190214
    191       $Text = '    Avg.  '.$this->System->AddPrefixMultipliers($AvgValue, $MeasureMethod['Unit']);
     215      $Text = '    Avg.  '.$PrefixMultiplier->Add($AvgValue, $MeasureMethod['Unit']);
    192216      $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    193217      $Left -= ($BoundingBox[2] - $BoundingBox[0]);
    194218      imagettftext($Image, $FontSize, 0, $Left, 14, $Green, $FontFile, $Text);
    195219
    196       $Text = '    Min.  '.$this->System->AddPrefixMultipliers($MinValue, $MeasureMethod['Unit']);
     220      $Text = '    Min.  '.$PrefixMultiplier->Add($MinValue, $MeasureMethod['Unit']);
    197221      $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    198222      $Left -= ($BoundingBox[2] - $BoundingBox[0]);
     
    205229      imagepng($Image);
    206230      imagedestroy($Image);
    207     }   
     231    }
    208232  }
    209233}
Note: See TracChangeset for help on using the changeset viewer.