Ignore:
Timestamp:
May 11, 2014, 4:28:01 PM (11 years ago)
Author:
chronos
Message:
  • Opraveno: Zobrazování grafů mřených veličin.
Location:
trunk/Modules/TimeMeasure
Files:
4 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}
  • trunk/Modules/TimeMeasure/Main.php

    r577 r655  
    33class PageMeasure extends Page
    44{
    5   var $Months = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
    6 
    7   var $GraphTimeRanges = array
     5  var $Months;
     6  var $GraphTimeRanges;
     7  var $DefaultVariables;
     8  var $ImageHeight;
     9  var $ImageWidth;
     10
     11  function __construct($System)
     12  {
     13    parent::__construct($System);
     14    $this->ShortTitle = 'Grafy';
     15    $this->FullTitle = 'Časové grafy veličin';
     16    $this->ImageWidth = 800;
     17    $this->ImageHeight = 200;
     18    $this->ParentClass = 'PagePortal';
     19        $this->DefaultVariables = array(
     20      'TimeSpecify' => 0,
     21      'Period' => 'day',
     22      'Measure' => 1,
     23      'Differential' => 0,
     24    );
     25    $this->Months = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen',
     26      'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
     27    $this->GraphTimeRanges = array
    828  (
    929    'hour' => array(
     
    2242      'caption' => 'Měsíc',
    2343      'period' => 2592000, // 3600 * 24 * 30,
    24     ), 
     44    ),
    2545    'year' => array(
    2646      'caption' => 'Rok',
     
    3252    ),
    3353  );
     54  }
    3455
    3556  function EditTime($Time)
     
    4465    for($I = 1; $I < 32; $I++)
    4566    {
    46       if($I == $TimeParts['mday']) $Selected = ' selected="1"'; else $Selected = ''; 
     67      if($I == $TimeParts['mday']) $Selected = ' selected="1"'; else $Selected = '';
    4768      $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
    4869    }
     
    5273    $Output .= '<select name="Month">';
    5374    foreach($this->Months as $Index => $Month)
    54     { 
     75    {
    5576      if($Index == $TimeParts['mon']) $Selected = ' selected="1"'; else $Selected = '';
    5677      if($Index > 0) $Output .= '<option value="'.$Index.'"'.$Selected.'>'.$Month.'</option>';
     
    6182    $Output .= '<select name="Year">';
    6283    for($I = 2000; $I < 2010; $I++)
    63     { 
     84    {
    6485      if($I == $TimeParts['year']) $Selected = ' selected="1"'; else $Selected = '';
    6586      $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
     
    7091    $Output .= '<select name="Hour">';
    7192    for($I = 0; $I < 24; $I++)
    72     { 
     93    {
    7394      if($I == $TimeParts['hours']) $Selected = ' selected="1"'; else $Selected = '';
    7495      $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
     
    7899    // Minute selection
    79100    $Output .= '<select name="Minute">';
    80     for($I = 0; $I < 60; $I++) 
     101    for($I = 0; $I < 60; $I++)
    81102    {
    82103      if($I == $TimeParts['minutes']) $Selected = ' selected="1"'; else $Selected = '';
     
    98119    $Debug = 0;
    99120
    100     foreach($this->System->Config['Application']['DefaultVariables'] as $Index => $Variable)
     121    foreach($this->DefaultVariables as $Index => $Variable)
    101122    {
    102123      if(!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable;
     
    110131      $_SESSION['TimeEnd'] = time() - 60;
    111132      $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GraphTimeRanges[$_SESSION['Period']]['period'];
    112     } 
    113 
    114     $Output = '<div class="Title">Statistiky</div>';
     133    }
     134
     135    $Output = '';
    115136
    116137    if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = '';
     
    128149          }
    129150        }
    130         break; 
     151        break;
    131152      case 'SetTimeNow':
    132         if(array_key_exists('Time', $_GET)) 
     153        if(array_key_exists('Time', $_GET))
    133154        {
    134155          if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
     
    160181    $Output .= '<br/>'.$this->MeasureTable();
    161182    return($Output);
    162   } 
    163  
     183  }
     184
    164185  function Graph()
    165186  {
    166187    $Output = '<strong>Graf:</strong><br/>';
    167     $Output .= '<img alt="Graf" src="?M=Graph&amp;Measure='.$_SESSION['Measure'].'&amp;From='.$_SESSION['TimeStart'].'&amp;To='.$_SESSION['TimeEnd'].'&amp;Width='.$this->Config['Application']['GraphSize']['Width'].'&amp;Height='.$this->Config['Application']['GraphSize']['Height'].'&amp;Differential='.$_SESSION['Differential'].'" width="'.$this->Config['Application']['GraphSize']['Width'].'" height="'.$this->Config['Application']['GraphSize']['Height'].'"><br>';
    168     $Output .= '<a href="?Measure='.$_SESSION['Measure'].'&amp;TimeStart='.$_SESSION['TimeStart'].'&amp;TimeEnd='.$_SESSION['TimeEnd'].'&amp;TimeSpecify=1&amp;Differential='.$_SESSION['Differential'].'">Odkaz na vybraný graf</a><br>';
    169     return($Output);
    170   }
    171  
     188    $Output .= '<img alt="Graf" src="'.$this->System->Link('/grafy/graf.png?Measure='.$_SESSION['Measure'].
     189      '&amp;From='.$_SESSION['TimeStart'].'&amp;To='.$_SESSION['TimeEnd'].'&amp;Width='.
     190      $this->ImageWidth.'&amp;Height='.$this->ImageHeight.'&amp;Differential='.
     191      $_SESSION['Differential']).'" width="'.$this->ImageWidth.'" height="'.$this->ImageHeight.'"><br>';
     192    $Output .= '<a href="?Measure='.$_SESSION['Measure'].'&amp;TimeStart='.
     193      $_SESSION['TimeStart'].'&amp;TimeEnd='.$_SESSION['TimeEnd'].'&amp;TimeSpecify=1&amp;Differential='.$_SESSION['Differential'].'">Odkaz na vybraný graf</a><br>';
     194    return($Output);
     195  }
     196
    172197  function MeasureTable()
    173198  {
     199    $PrefixMultiplier = new PrefixMultiplier();
    174200    $Output = '<table border="1" cellspacing="0" cellpadding="2" style="font-size: small;">';
    175201    $Output .= '<tr><th>Měřená veličina</th><th>Poslední hodnota</th><th>Čas posledního měření</th><th>Interpolace</th><th>Poznámky</th>';
     
    181207      $DbResult2 = $this->Database->select('MeasureMethod', '*', 'Id='.$Measure['Method']);
    182208      $MeasureMethod = $DbResult2->fetch_assoc();
    183       $StopWatchStart = $this->System->GetMicrotime();
     209      $StopWatchStart = GetMicrotime();
    184210      if(array_key_exists('Debug', $_GET))
    185211      {
     
    192218      {
    193219        $Row = $Result2->fetch_array();
    194         $LastMeasureTime = date('j.n.Y G:i:s', $this->Database->MysqlDateTimeToTime($Row['Time']));
    195         $LastMeasureValue = $this->System->AddPrefixMultipliers($Row['Avg'], $MeasureMethod['Unit']);
     220        $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['Time']));
     221        $LastMeasureValue = $PrefixMultiplier->Add($Row['Avg'], $MeasureMethod['Unit']);
    196222      } else
    197223      {
     
    199225        $LastMeasureValue = '&nbsp;';
    200226      }
    201       if($Measure['Continuity'] == 1) $Interpolate = 'Ano'; 
     227      if($Measure['Continuity'] == 1) $Interpolate = 'Ano';
    202228        else $Interpolate = 'Ne';
    203       if($Measure['Info'] == '') $Measure['Info'] = '&nbsp;';
    204       $GenerationTime = floor(($this->System->GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
     229      //if($Measure['Description'] == '') $Measure['Description'] = '&nbsp;';
     230      $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
    205231      $Output .= '<tr><td><a href="?Measure='.$Measure['Id'].'&amp;Differential=0">'.$Measure['Name'].'</a></td><td align="center">'.$LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'.$Interpolate.'</td><td>'.$Measure['Description'].'</td>';
    206232      if(array_key_exists('Debug', $_GET)) $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>';
     
    211237    //print_r(gd_info());
    212238    //print_r($_SESSION);
    213  
     239
    214240    //ShowPage($Output);
    215     //echo(AddPrefixMultipliers('-0.000000071112345', 'B'));
     241    //echo($PrefixMultiplier->Add('-0.000000071112345', 'B'));
    216242    return($Output);
    217243  }
  • trunk/Modules/TimeMeasure/Measure.php

    r569 r655  
    1111  var $DivisionCount = 500;
    1212  var $ValueTypes = array('Min', 'Avg', 'Max');
    13  
     13
    1414  function Load($Id)
    1515  {
     
    2222    } else throw new Exception('Measure not found');
    2323  }
    24  
     24
    2525  function TimeSegment($Base, $Level)
    2626  {
     
    4848    $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2');
    4949    //echo($Database->LastQuery."\n");
    50     if($Result->num_rows == 0) 
    51     {
    52        $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => 0)); 
     50    if($Result->num_rows == 0)
     51    {
     52       $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => 0));
    5353       //echo($Database->LastQuery."\n");
    5454    } else if($Result->num_rows == 1)
     
    6161      $NextToLastValue = $Result->fetch_assoc();
    6262      //echo($Level.': '.$Time.' - '.MysqlDateTimeToTime($LastValue['Time']).' '.($Time - MysqlDateTimeToTime($LastValue['Time'])).' = '.$Measure['Period']."\n");
    63       if((($Time - $this->Database->MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0))
    64       { 
     63      if((($Time - MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0))
     64      {
    6565        echo('Too short period\n');
    6666      } else
    6767      {
    68         if(($Time - $this->Database->MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1;
     68        if(($Time - MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1;
    6969          else $Continuity = 0;
    7070        echo('('.$LastValue['Avg'].'=='.$NextToLastValue['Avg'].') and ('.$LastValue['Avg'].' == '.$Value.') and ('.$LastValue['Continuity'].' == 1) and ('.$Continuity.' == 1))'."\n");
    7171        if(($LastValue['Min'] == $NextToLastValue['Min']) and ($LastValue['Min'] == $Value['Min']) and ($LastValue['Avg'] == $NextToLastValue['Avg']) and ($LastValue['Avg'] == $Value['Avg']) and ($LastValue['Max'] == $NextToLastValue['Max']) and ($LastValue['Max'] == $Value['Max']) and ($LastValue['Continuity'] == 1) and ($Continuity == 1))
    7272        {
    73           $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$Measure['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time)));
     73          $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$this->Data['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time)));
    7474          //echo($this->Database->LastQuery."\n");
    7575        } else
     
    7777          $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => $Continuity));
    7878        }
    79       } 
     79      }
    8080
    8181      // Update next level
     
    9595        $Values = array();
    9696        //.'" AND Time < "'.TimeToMysqlDateTime($EndTime).'" AND Measure='.$Measure['Id'].' AND Level='.($Level - 1).' ORDER BY Time');
    97         $Result = $this->Database->select($this->Data['DataTable'], '*', '(Time > "'.$this->Database->TimeToMysqlDateTime($StartTime).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($EndTime).'") AND (Measure='.$this->Data['Id'].') AND (Level='.($Level - 1).') ORDER BY Time');
     97        $Result = $this->Database->select($this->Data['DataTable'], '*', '(Time > "'.TimeToMysqlDateTime($StartTime).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($EndTime).'") AND (Measure='.$this->Data['Id'].') AND (Level='.($Level - 1).') ORDER BY Time');
    9898        while($Row = $Result->fetch_assoc())
    9999        {
    100           $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);
     100          $Row['Time'] = MysqlDateTimeToTime($Row['Time']);
    101101          $Values[] = $Row;
    102102        }
     
    108108          // Load subsidary values
    109109          print_r($Values);
    110           $Values = array_merge($this->LoadLeftSideValue($Level - 1, $this->Data, $StartTime), $Values, $this->LoadRightSideValue($Level - 1, $EndTime));
     110          $Values = array_merge($this->LoadLeftSideValue($Level - 1, $this->Data,
     111            $StartTime), $Values, $this->LoadRightSideValue($Level - 1, $EndTime));
    111112          print_r($Values);
    112113
     
    114115        //print_r($Point);
    115116
    116           $this->Database->delete($this->Data['DataTable'], '(Time > "'.$this->Database->TimeToMysqlDateTime($StartTime).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($EndTime).'") AND Measure='.$this->Data['Id'].' AND Level='.$Level);
     117          $this->Database->delete($this->Data['DataTable'], '(Time > "'.TimeToMysqlDateTime($StartTime).
     118            '") AND (Time < "'.TimeToMysqlDateTime($EndTime).'") AND Measure='.$this->Data['Id'].' AND Level='.$Level);
    117119          $this->Data['Period'] = $TimeSegment;
    118           $this->AddValue(array('Min' => $Point['Min'], 'Avg' => $Point['Avg'], 'Max' => $Point['Max']), $Level, $StartTime + ($EndTime - $StartTime) / 2);
     120          $this->AddValue(array('Min' => $Point['Min'], 'Avg' => $Point['Avg'],
     121            'Max' => $Point['Max']), $Level, $StartTime + ($EndTime - $StartTime) / 2);
    119122        }
    120123      }
     
    180183            }
    181184          }
    182         } 
    183         else if($ValueType == 'Min') 
    184         {
    185           //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>'); 
     185        }
     186        else if($ValueType == 'Min')
     187        {
     188          //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>');
    186189          if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled'])
    187190          {
     
    201204      $NewValue[$ValueType] = $NewValue[$ValueType];
    202205    }
    203     //if(($RightTime - $LeftTime) > 0) 
    204     if($this->Data['Cumulative'] == 0) 
     206    //if(($RightTime - $LeftTime) > 0)
     207    if($this->Data['Cumulative'] == 0)
    205208    {
    206209      $NewValue['Avg'] = $NewValue['Avg'] / ($RightTime - $LeftTime);
     
    214217  {
    215218    // Get first and last time
    216     //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n"); 
     219    //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n");
    217220    $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time LIMIT 1');
    218221    if($Result->num_rows > 0)
     
    229232    } else $AbsoluteRightTime = 0;
    230233
    231     if($this->Debug) 
    232     {
    233       echo('AbsoluteLeftTime: '.$AbsoluteLeftTime.'('.$this->Database->TimeToMysqlDateTime($AbsoluteLeftTime).')<br>');
    234       echo('AbsoluteRightTime: '.$AbsoluteRightTime.'('.$this->Database->TimeToMysqlDateTime($AbsoluteRightTime).')<br>');
     234    if($this->Debug)
     235    {
     236      echo('AbsoluteLeftTime: '.$AbsoluteLeftTime.'('.TimeToMysqlDateTime($AbsoluteLeftTime).')<br>');
     237      echo('AbsoluteRightTime: '.$AbsoluteRightTime.'('.TimeToMysqlDateTime($AbsoluteRightTime).')<br>');
    235238    }
    236239    return(array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime));
     
    238241
    239242  function LoadRightSideValue($Level, $Time)
    240   { 
     243  {
    241244    $Result = array();
    242     $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.$this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1');
     245    $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1');
    243246    if($DbResult->num_rows > 0)
    244247    {
    245248      $Row = $DbResult->fetch_assoc();
    246       $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);
     249      $Row['Time'] = MysqlDateTimeToTime($Row['Time']);
    247250      return(array($Row));
    248251    } else
     
    251254      //array_push($Values, array('Time' => $Time, 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));
    252255      $Result[] = array('Time' => ($Time + $this->TimeSegment($this->Data['Period'], $Level)), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0);
    253       $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'.$this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1');
     256      $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'.
     257        TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1');
    254258      if($DbResult->num_rows > 0)
    255259      {
    256260        $Row = $DbResult->fetch_assoc();
    257         array_unshift($Result, array('Time' => ($this->Database->MysqlDateTimeToTime($Row['Time']) + 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));
     261        array_unshift($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) + 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));
    258262      }
    259263     // if($Debug) print_r($Result);
     
    266270    $Result = array();
    267271    //echo('SELECT * FROM '.StatTableName($Level). ' WHERE '. 'Time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY Time DESC LIMIT 1'."<br>\n");
    268     $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'.$this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1');
     272    $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1');
    269273    if($DbResult->num_rows > 0)
    270274    {
    271275      $Row = $DbResult->fetch_assoc();
    272       $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);
     276      $Row['Time'] = MysqlDateTimeToTime($Row['Time']);
    273277      return(array($Row));
    274278    } else
     
    279283      $Result[] = array('Time' => ($Time - $this->TimeSegment($this->Data['Period'], $Level)), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0);
    280284
    281       $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.$this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1');
     285      $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1');
    282286      if($DbResult->num_rows > 0)
    283287      {
    284288        $Row = $DbResult->fetch_assoc();
    285         array_push($Result, array('Time' => ($this->Database->MysqlDateTimeToTime($Row['Time']) - 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));
     289        array_push($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) - 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));
    286290      }
    287291//    if($Debug) print_r($Result);
     
    292296  function GetValues($TimeFrom, $TimeTo, $Level)
    293297  {
    294     if($this->Debug) echo('TimeFrom: '.$TimeFrom.'('.$this->Database->TimeToMysqlDateTime($TimeFrom).')<br>');
    295     if($this->Debug) echo('TimeTo: '.$TimeTo.'('.$this->Database->TimeToMysqlDateTime($TimeTo).')<br>');
     298    if($this->Debug) echo('TimeFrom: '.$TimeFrom.'('.TimeToMysqlDateTime($TimeFrom).')<br>');
     299    if($this->Debug) echo('TimeTo: '.$TimeTo.'('.TimeToMysqlDateTime($TimeTo).')<br>');
    296300
    297301    //$AbsoluteTime = GetTimeRange($MeasureId);
    298302
    299     //  if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 
     303    //  if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and
    300304    //    ($TimeTo > $AbsoluteLeftTime) and ($TimeTo < $AbsoluteRightTime))
    301305    //  {
    302306
    303307    // Load values in time range
    304     $Result = $this->Database->select($this->Data['DataTable'], 'Time, Min, Avg, Max, Continuity', '(Time > "'.$this->Database->TimeToMysqlDateTime($TimeFrom).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($TimeTo).'") AND (Measure='.$this->Data['Id'].') AND (Level='.$Level.') ORDER BY Time');
     308    $Result = $this->Database->select($this->Data['DataTable'], 'Time, Min, Avg, Max, Continuity', '(Time > "'.
     309      TimeToMysqlDateTime($TimeFrom).'") AND (Time < "'.
     310      TimeToMysqlDateTime($TimeTo).'") AND (Measure='.
     311      $this->Data['Id'].') AND (Level='.$Level.') ORDER BY Time');
    305312    //  echo($Level.' '.TimeToMysqlDateTime($TimeFrom).' '.TimeToMysqlDateTime($TimeTo));
    306313    $Values = array();
     
    311318      //    echo($III.' '.$Row['Time'].' '.memory_get_usage().',');
    312319      //    $III++;
    313       $Values[] = array('Time' => $this->Database->MysqlDateTimeToTime($Row['Time']), 'Min' => $Row['Min'], 'Avg' => $Row['Avg'], 'Max' => $Row['Max'], 'Continuity' => $Row['Continuity']);
     320      $Values[] = array('Time' => MysqlDateTimeToTime($Row['Time']), 'Min' => $Row['Min'],
     321        'Avg' => $Row['Avg'], 'Max' => $Row['Max'], 'Continuity' => $Row['Continuity']);
    314322    }
    315323    // array_pop($Values);
     
    317325    //  die();
    318326    if($this->Debug) echo('Item count: '.count($Values));
    319  
     327
    320328    $Points = array();
    321329    if(count($Values) > 0)
     
    385393        while($Row = $DbResult->fetch_assoc())
    386394        {
    387           $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);
     395          $Row['Time'] = MysqlDateTimeToTime($Row['Time']);
    388396          $Values[] = $Row;
    389397        }
     
    416424        // Load values in time range
    417425        //array_pop($NextValues);
    418       } 
     426      }
    419427      echo("Uroven dokoncena<br>\n");
    420428      $DbResult = $this->Database->select($this->Data['DataTable'], 'COUNT(*)', 'Level='.$Level.' AND Measure='.$this->Data['Id']);
  • trunk/Modules/TimeMeasure/TimeMeasure.php

    r586 r655  
    1717    $this->Dependencies = array('User');
    1818  }
    19  
     19
    2020  function DoInstall()
    2121  {
    2222  }
    23  
     23
    2424  function DoUnInstall()
    2525  {
     
    2828  function DoStart()
    2929  {
    30     $this->System->Pages['grafy'] = 'PageMeasure';
     30    $this->System->RegisterPage('grafy', 'PageMeasure');
     31    $this->System->RegisterPage(array('grafy', 'graf.png'), 'PageGraph');
    3132    $this->System->FormManager->RegisterClass('Measure', array(
    3233      'Title' => 'Měření',
     
    4546        'DataTable' => array('Type' => 'String', 'Caption' => 'Tabulka měřených dat', 'Default' => 'data'),
    4647      ),
    47     ));   
     48    ));
    4849  }
    4950
Note: See TracChangeset for help on using the changeset viewer.