Changeset 655


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

Legend:

Unmodified
Added
Removed
  • trunk/Common/Global.php

    r636 r655  
    55/* @var $Database Database */
    66$Database = NULL;
    7      
     7
    88include_once(dirname(__FILE__).'/VarDumper.php');
    99include_once(dirname(__FILE__).'/Base.php');
     
    1717include_once(dirname(__FILE__).'/Config.php');
    1818include_once(dirname(__FILE__).'/Setup/Setup.php');
     19include_once(dirname(__FILE__).'/PrefixMultiplier.php');
    1920
    2021//define('NEW_PERMISSION', '1');
    2122
    22 $MonthNames = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 
     23$MonthNames = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen',
    2324        'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
    2425
    2526$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
    2627$YesNo = array(false => 'Ne', true => 'Ano');
    27  
     28
    2829function HumanSize($Value)
    2930{
     
    5455function HumanDate($Time)
    5556{
    56         if($Time != '') {               
     57        if($Time != '') {
    5758    $Date = explode(' ', $Time);
    5859    $Parts = explode('-', $Date[0]);
    5960    if($Date != '0000-00-00') return(($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]);
    6061    else return(' ');
    61         } else return(' '); 
     62        } else return(' ');
    6263}
    6364
     
    7071  if($Count>1)
    7172  {
    72     if($Page>0) 
     73    if($Page>0)
    7374    {
    7475      $Result.= '<a href="'.$URL.'0">&lt;&lt;</a> ';
     
    8889      $Result.= '<a href="'.$URL.$i.'">'.($i+1).'</a> ';
    8990      if($i==$Page) $Result.= '</strong>';
    90     } 
     91    }
    9192    if($PagesMax<($Count-1)) $Result .= ' .. ';
    92     if($Page<($Count-1)) 
     93    if($Page<($Count-1))
    9394    {
    9495      $Result.= '<a href="'.$URL.($Page+1).'">&gt;</a> ';
     
    9798  }
    9899  return($Result);
    99 } 
     100}
    100101
    101102function ExtractTime($Time)
    102 { 
     103{
    103104  return(array(
    104         'Year' => date('Y', $Time), 
    105         'Month' => date('n', $Time), 
     105        'Year' => date('Y', $Time),
     106        'Month' => date('n', $Time),
    106107        'Day' => date('j', $Time),
    107108        'Hour' => date('h', $Time),
     
    137138}
    138139
    139 class Paging 
     140class Paging
    140141{
    141142        var $TotalCount;
     
    144145        var $SQLLimit;
    145146        var $Page;
    146        
     147
    147148        function __construct()
    148149        {
    149150                global $System;
    150                
     151
    151152                $this->ItemPerPage = $System->Config['Web']['ItemsPerPage'];
    152153                $this->Around = $System->Config['Web']['VisiblePagingItems'];
    153154        }
    154        
     155
    155156  function Show()
    156157  {
    157158    $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
    158  
     159
    159160    $Result = '';
    160     if(array_key_exists('all', $QueryItems)) 
     161    if(array_key_exists('all', $QueryItems))
    161162    {
    162163      $PageCount = 1;
    163       $ItemPerPage = $this->TotalCount;   
    164     } else 
     164      $ItemPerPage = $this->TotalCount;
     165    } else
    165166    {
    166167      $ItemPerPage = $this->ItemPerPage;
     
    168169      $PageCount = floor($this->TotalCount / $ItemPerPage) + 1;
    169170    }
    170  
     171
    171172    if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
    172173    if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
    173174    if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
    174175    if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
    175     $CurrentPage = $_SESSION['Page']; 
    176        
     176    $CurrentPage = $_SESSION['Page'];
     177
    177178    $Result .= 'Počet položek: <strong>'.$this->TotalCount.'</strong> &nbsp; Stránky: ';
    178  
     179
    179180    $Result = '';
    180181    if($PageCount > 1)
    181182    {
    182       if($CurrentPage > 0) 
     183      if($CurrentPage > 0)
    183184      {
    184         $QueryItems['page'] = 0;     
     185        $QueryItems['page'] = 0;
    185186        $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;&lt;</a> ';
    186187        $QueryItems['page'] = ($CurrentPage - 1);
     
    202203         $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
    203204        }
    204       } 
     205      }
    205206      if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
    206       if($CurrentPage < ($PageCount - 1)) 
     207      if($CurrentPage < ($PageCount - 1))
    207208      {
    208209        $QueryItems['page'] = ($CurrentPage + 1);
     
    214215    $QueryItems['all'] = '1';
    215216    if($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';
    216  
     217
    217218    $Result = '<div style="text-align: center">'.$Result.'</div>';
    218219    $this->SQLLimit = ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage;
     
    225226{
    226227  global $System;
    227    
     228
    228229  $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
    229  
     230
    230231  $Result = '';
    231   if(array_key_exists('all', $QueryItems)) 
     232  if(array_key_exists('all', $QueryItems))
    232233  {
    233234    $PageCount = 1;
    234     $ItemPerPage = $TotalCount;   
    235   } else 
     235    $ItemPerPage = $TotalCount;
     236  } else
    236237  {
    237238    $ItemPerPage = $System->Config['Web']['ItemsPerPage'];
     
    239240    $PageCount = floor($TotalCount / $ItemPerPage) + 1;
    240241  }
    241  
     242
    242243  if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
    243244  if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
     
    245246  if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
    246247  $CurrentPage = $_SESSION['Page'];
    247  
    248        
     248
     249
    249250  $Result .= 'Počet položek: <strong>'.$TotalCount.'</strong> &nbsp; Stránky: ';
    250251
     
    252253  if($PageCount > 1)
    253254  {
    254     if($CurrentPage > 0) 
    255     {
    256       $QueryItems['page'] = 0;     
     255    if($CurrentPage > 0)
     256    {
     257      $QueryItems['page'] = 0;
    257258      $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;&lt;</a> ';
    258259      $QueryItems['page'] = ($CurrentPage - 1);
     
    274275       $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
    275276      }
    276     } 
     277    }
    277278    if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
    278     if($CurrentPage < ($PageCount - 1)) 
     279    if($CurrentPage < ($PageCount - 1))
    279280    {
    280281      $QueryItems['page'] = ($CurrentPage + 1);
     
    286287  $QueryItems['all'] = '1';
    287288  if($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';
    288  
     289
    289290  $Result = '<div style="text-align: center">'.$Result.'</div>';
    290   return(array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage, 
     291  return(array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage,
    291292    'Page' => $CurrentPage,
    292293    'Output' => $Result,
     
    300301{
    301302  global $OrderDirSQL, $OrderArrowImage, $Config, $System;
    302  
     303
    303304  if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
    304305  if(array_key_exists('OrderDir', $_GET)) $_SESSION['OrderDir'] = $_GET['OrderDir'];
    305306  if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn;
    306307  if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder;
    307  
     308
    308309  // Check OrderCol
    309310  $Found = false;
     
    312313    if($Column['Name'] == $_SESSION['OrderCol'])
    313314    {
    314       $Found = true;   
     315      $Found = true;
    315316      break;
    316317    }
     
    323324  // Check OrderDir
    324325  if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0;
    325  
     326
    326327  $Result = '';
    327328  $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
     
    362363{
    363364  global $Database;
    364  
     365
    365366  $DbResult = $Database->query('SELECT Id FROM Member WHERE (SELECT Member FROM NetworkDevice WHERE (SELECT Device FROM NetworkInterface WHERE LocalIP = "'.$IP.'") = NetworkDevice.Id) = Member.Id');
    366367  if($DbResult->num_rows > 0)
    367368  {
    368     $DbRow = $DbResult->fetch_assoc(); 
     369    $DbRow = $DbResult->fetch_assoc();
    369370    return($DbRow['Id']);
    370371  } else return('');
     
    374375{
    375376  return(str_replace(
    376     array('á', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ň', 'ó', 'ř', 'š', 'ť', 'ú', 'ů', 
     377    array('á', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ň', 'ó', 'ř', 'š', 'ť', 'ú', 'ů',
    377378      'ý', 'ž', 'Á', 'Č', 'Ď', 'É', 'Ě', 'Í', 'Ľ', 'Ň', 'Ó', 'Ř', 'Š', 'Ť', 'Ú', 'Ů', 'Ý', 'Ž'),
    378     array('a', 'c', 'd', 'e', 'e', 'i', 'l', 'n', 'o', 'r', 's', 't', 'u', 'u', 
    379       'y', 'z', 'A', 'C', 'D', 'E', 'E', 'I', 'L', 'N', 'O', 'R', 'S', 'T', 'U', 'U', 'Y', 'Z'), 
     379    array('a', 'c', 'd', 'e', 'e', 'i', 'l', 'n', 'o', 'r', 's', 't', 'u', 'u',
     380      'y', 'z', 'A', 'C', 'D', 'E', 'E', 'I', 'L', 'N', 'O', 'R', 'S', 'T', 'U', 'U', 'Y', 'Z'),
    380381    $Text));
    381382}
     
    384385{
    385386  return(strtr(strtolower(trim($Name)), array(' ' => '-', '.' => '', '(' => '-', ')' => '-',
    386   'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y', 
    387   'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd', 
     387  'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y',
     388  'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd',
    388389  'ť' => 't', 'ň' => 'n', 'ó' => 'o',
    389   'Č' => 'c', 'Š' => 's', 'Ě' => 'e', 'Ř' => 'r', 'Ž' => 'z', 'Ý' => 'y', 
    390   'Á' => 'a', 'Í' => 'i', 'É' => 'e', 'Ů' => 'u', 'Ú' => 'u', 'Ď' => 'd', 
     390  'Č' => 'c', 'Š' => 's', 'Ě' => 'e', 'Ř' => 'r', 'Ž' => 'z', 'Ý' => 'y',
     391  'Á' => 'a', 'Í' => 'i', 'É' => 'e', 'Ů' => 'u', 'Ú' => 'u', 'Ď' => 'd',
    391392  'Ť' => 't', 'Ň' => 'n', 'Ó' => 'o',
    392393)));
     
    395396function NotBlank($Text)
    396397{
    397   if($Text == '') return('&nbsp'); 
     398  if($Text == '') return('&nbsp');
    398399    else return($Text);
    399400}
     
    403404  preg_match_all('/<!\[cdata\[(.*?)\]\]>/is', $string, $matches);
    404405  return str_replace($matches[0], $matches[1], $string);
    405 } 
     406}
    406407
    407408function html2txt($document)
     
    414415  $text = preg_replace($search, '', $document);
    415416  return $text;
    416 } 
     417}
    417418
    418419function ProcessURL()
     
    425426  if(strpos($_SERVER['REQUEST_URI'], '?') !== false)
    426427    $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
    427     else $_SERVER['QUERY_STRING'] = '';   
     428    else $_SERVER['QUERY_STRING'] = '';
    428429  parse_str($_SERVER['QUERY_STRING'], $_GET);
    429430  return($PathItems);
  • trunk/Common/PrefixMultiplier.php

    r548 r655  
    7878      if($Value >= pow(10, $II))
    7979      {
    80         if($Digits < ($II + 1)) $RealDigits = $II + 1; 
     80        if($Digits < ($II + 1)) $RealDigits = $II + 1;
    8181          else $RealDigits = $Digits;
    8282        $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1);
     
    8787  }
    8888
    89   function AddPrefixMultipliers($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal')
     89  function Add($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal')
    9090  {
    9191    global $PrefixMultipliers;
     
    9898    $I = $PrefixMultipliers[$PrefixType]['BaseIndex'];
    9999    if($Value == 0) return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
    100      
    101     if($Value > 1) 
     100
     101    if($Value > 1)
    102102    {
    103103      while((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1))
    104104        $I = $I + 1;
    105     } else 
     105    } else
    106106    if($Value < 1)
    107107    {
     
    110110    }
    111111    $Value = $Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2];
    112    
     112
    113113    // Truncate digits count
    114114    $Value = $this->TruncateDigits($Value, $Digits);
    115115    if($Negative) $Value = -$Value;
    116116    return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
    117   } 
     117  }
    118118}
  • 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.