Changeset 59


Ignore:
Timestamp:
Mar 1, 2015, 12:43:56 PM (10 years ago)
Author:
chronos
Message:
  • Moved trunk as mvc branch.
Location:
branches
Files:
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/mvc/Application/CustomOutput.php

    r47 r59  
    3535      $Tag->SubElements[] = $ExecutionTimeTag;
    3636      $UsedMemoryTag = new XMLTag('li');
    37       $UsedMemoryTag->SubElements = 'Použitá paměť: '.$this->System->AddPrefixMultipliers(memory_get_peak_usage(FALSE), 'B').' / '.ini_get('memory_limit').'B';
     37      $PrefixMultiplier = new PrefixMultiplier();
     38      $UsedMemoryTag->SubElements = 'Použitá paměť: '.$PrefixMultiplier->Add(memory_get_peak_usage(FALSE), 'B').' / '.ini_get('memory_limit').'B';
    3839      $Tag->SubElements[] = $UsedMemoryTag;
    3940    }
  • branches/mvc/Application/Model/Measure.php

    r47 r59  
    4141  }
    4242
    43 
    4443  function AddValue($Value = array('Min' => 0, 'Avg' => 0, 'Max' => 0), $Level = 0, $Time = 0)
    4544  {
     
    4847    //echo(TimeToMysqlDateTime($Time).'|'.$Level."\n");
    4948
    50     $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2');
     49    $Result = $this->Database->select($this->Data['DataTable'], '*', '(Measure='.$this->Data['Id'].') AND '.
     50      '(Level='.$Level.') ORDER BY Time DESC LIMIT 2');
    5151    //echo($Database->LastQuery."\n");
    5252    if($Result->num_rows == 0)
    5353    {
    54        $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));
     54       $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'],
     55         'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level,
     56         'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => 0));
    5557       //echo($Database->LastQuery."\n");
    5658    } else if($Result->num_rows == 1)
    5759    {
    58       $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' => 1));
     60      $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'],
     61        'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level,
     62        'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => 1));
    5963      //echo($Database->LastQuery."\n");
    6064    } else
     
    7175          else $Continuity = 0;
    7276        echo('('.$LastValue['Avg'].'=='.$NextToLastValue['Avg'].') and ('.$LastValue['Avg'].' == '.$Value.') and ('.$LastValue['Continuity'].' == 1) and ('.$Continuity.' == 1))'."\n");
    73         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))
    74         {
    75           $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$this->Data['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time)));
     77        if(($LastValue['Min'] == $NextToLastValue['Min']) and ($LastValue['Min'] == $Value['Min']) and
     78        ($LastValue['Avg'] == $NextToLastValue['Avg']) and ($LastValue['Avg'] == $Value['Avg']) and
     79        ($LastValue['Max'] == $NextToLastValue['Max']) and ($LastValue['Max'] == $Value['Max']) and
     80        ($LastValue['Continuity'] == 1) and ($Continuity == 1))
     81        {
     82          $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") '.
     83            'AND (Level='.$Level.') AND (Measure='.$this->Data['Id'].')', array(
     84            'Time' => $this->Database->TimeToMysqlDateTime($Time)));
    7685          //echo($this->Database->LastQuery."\n");
    7786        } else
    7887        {
    79           $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));
     88          $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'],
     89            'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level,
     90            'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time),
     91            'Continuity' => $Continuity));
    8092        }
    8193      }
  • branches/mvc/Application/Style/Basic/Style.css

    r43 r59  
    33  font-family :  Arial, sans-serif;
    44}
     5
     6.Main
     7{
     8  text-align: center;
     9}
     10
    511.BasicTable
    612{
     
    2531  padding: 2px;
    2632}
     33
     34.WideTable
     35{
     36  border-color: #A0A0A0;
     37  border-style: solid;
     38  border-width: 1px 1px 0px 0px;
     39  border-spacing: 0px;
     40  text-align: center;
     41  margin-left: auto;
     42  margin-right: auto; 
     43}
     44
     45.WideTable th
     46{
     47  border-color: #A0A0A0;
     48  border-style: solid;
     49  border-width: 0px 0px 1px 1px;
     50  padding: 1px 5px 1px 5px;
     51  background-color: #F0F0FF
     52}
     53
     54.WideTable td
     55{
     56  border-color: #A0A0A0;
     57  border-style: solid;
     58  border-width: 0px 0px 1px 1px;
     59  padding: 1px 5px 1px 5px;
     60  text-align: center;
     61}
     62
    2763h3
    2864{
  • branches/mvc/Application/View/Graph.php

    r47 r59  
    66class GraphView extends View
    77{
     8  var $FontSize;
     9  var $FontFileName;
     10  var $ValueToImageHeigthCoefficient;
    811  var $DefaultWidth;
    912  var $DefaultHeight;
     
    1417    $this->DefaultWidth = 800;
    1518    $this->DefaultHeight = 200;
     19    $this->FontSize = 10;
     20    $this->FontFileName = 'Arial.ttf';
     21    $this->ValueToImageHeigthCoefficient = 0.9;
    1622  }
    1723
     
    3541    if(!array_key_exists('Differential', $_GET)) $Differential = $this->Config['Application']['DefaultVariables']['Differential'];
    3642      else $Differential = addslashes($_GET['Differential']);
    37     $VerticalLinesCount = round($Height / ($this->Config['Application']['FontSize'] + 4));
    38 
     43    $VerticalLinesCount = round($Height / ($this->FontSize + 4));
     44
     45    $PrefixMultiplier = new PrefixMultiplier();
    3946    $StopWatchStart = $this->System->GetMicrotime();
    4047
     
    5057    $MeasureMethod = $DbResult2->fetch_assoc();
    5158
    52     $FontSize = $this->Config['Application']['FontSize'];
    53     $FontFile = dirname(__FILE__).'/../Style/'.$this->Config['System']['Style'].'/'.$this->Config['Application']['FontFileName'];
     59    $FontSize = $this->FontSize;
     60    $FontFile = dirname(__FILE__).'/../Style/'.$this->Config['System']['Style'].'/'.$this->FontFileName;
    5461
    5562    $Level = floor(log(($EndTime - $StartTime) / $Measure->DivisionCount / 60) / log($Measure->LevelReducing)) - 1;
     
    9299      {
    93100        $PointsMin[] = $Index * $Width / $Measure->DivisionCount;
    94         $PointsMin[] = $Height - 1 - ($Points[$Index]['Min'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->Config['Application']['ValueToImageHeigthCoefficient'];
     101        $PointsMin[] = $Height - 1 - ($Points[$Index]['Min'] - $MinValue) /
     102          ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient;
    95103        $PointsAvg[] = $Index * $Width / $Measure->DivisionCount;
    96         $PointsAvg[] = $Height - 1 - ($Points[$Index]['Avg'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->Config['Application']['ValueToImageHeigthCoefficient'];
     104        $PointsAvg[] = $Height - 1 - ($Points[$Index]['Avg'] - $MinValue) /
     105          ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient;
    97106        $PointsMax[] = $Index * $Width / $Measure->DivisionCount;
    98         $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->Config['Application']['ValueToImageHeigthCoefficient'];
     107        $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) /
     108          ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient;
    99109        //echo($Index.' - '.$Item.' '.$Points[$Index].'<br/>');
    100110      }
     
    113123    $PointsMax[] = $Height - 1;
    114124
    115 
    116125    //array_unshift($Points, $Height - 1);
    117126    //array_unshift($Points, 0);
    118127    //$Points[] = $Width - 1;
    119128    //$Points[] = $Height - 1;      echo('sds');
    120 
    121 
    122129    //print_r($PointsMax);
    123130
     
    179186        {
    180187          for($Y = 0; $Y < $Height; $Y = $Y + 1) imagesetpixel($Image, $X, $Y, $Gray);
    181           imagettftext($Image, $FontSize, 0, $X - ($BoundBox[2] - $BoundBox[0]) / 2,  $Height - 2, $Black, $FontFile, $Text);
     188          imagettftext($Image, $FontSize, 0, $X - ($BoundBox[2] - $BoundBox[0]) / 2,
     189            $Height - 2, $Black, $FontFile, $Text);
    182190          $LastTextEnd = $X + ($BoundBox[2] - $BoundBox[0]) / 2;
    183191        }
     
    190198        $Y = $Height - 1 - ($VerticalLinesDistance * $I);
    191199        //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) * $this->Config['Application']['ValueToImageHeigthCoefficient'] * $Height);
    192         $Text = $this->System->AddPrefixMultipliers(round(($I * $VerticalLinesDistance / $Height / $this->Config['Application']['ValueToImageHeigthCoefficient'] * ($MaxValue - $MinValue) + $MinValue)), $MeasureMethod['Unit'], 3);
     200        $Text = $PrefixMultiplier->Add(round(($I * $VerticalLinesDistance /
     201          $Height / $this->ValueToImageHeigthCoefficient * ($MaxValue - $MinValue) + $MinValue)), $MeasureMethod['Unit'], 3);
    193202        $BoundBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    194203        if(($Y - ($BoundBox[5] - $BoundBox[1]) / 2) > 10)
     
    198207
    199208      $Left = $Width - 10;
    200       $Text = '    Max. '.$this->System->AddPrefixMultipliers($MaxValue, $MeasureMethod['Unit']);
     209      $Text = '    Max. '.$PrefixMultiplier->Add($MaxValue, $MeasureMethod['Unit']);
    201210      $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    202211      $Left -= ($BoundingBox[2] - $BoundingBox[0]);
    203212      imagettftext($Image, $FontSize, 0, $Left, 14, $Red, $FontFile, $Text);
    204213
    205       $Text = '    Avg.  '.$this->System->AddPrefixMultipliers($AvgValue, $MeasureMethod['Unit']);
     214      $Text = '    Avg.  '.$PrefixMultiplier->Add($AvgValue, $MeasureMethod['Unit']);
    206215      $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    207216      $Left -= ($BoundingBox[2] - $BoundingBox[0]);
    208217      imagettftext($Image, $FontSize, 0, $Left, 14, $Green, $FontFile, $Text);
    209218
    210       $Text = '    Min.  '.$this->System->AddPrefixMultipliers($MinValue, $MeasureMethod['Unit']);
     219      $Text = '    Min.  '.$PrefixMultiplier->Add($MinValue, $MeasureMethod['Unit']);
    211220      $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    212221      $Left -= ($BoundingBox[2] - $BoundingBox[0]);
  • branches/mvc/Application/View/Main.php

    r47 r59  
    113113    }
    114114
    115     $Output = '<div class="Title">Statistiky</div>';
     115    $Output = '<div class="Main">';
     116    $Output .= '<div class="Title">Statistiky</div>';
    116117
    117118    if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = '';
     
    160161
    161162    $Output .= '<br/>'.$this->MeasureTable();
     163    $Output .= '</div>';
    162164    return($Output);
    163165  }
     
    178180  function MeasureTable()
    179181  {
    180     $Output = '<table border="1" cellspacing="0" cellpadding="2" style="font-size: small;">';
     182    $Output = '<table class="WideTable">';
    181183    $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>';
    182184    if(array_key_exists('Debug', $_GET)) $Output .= '<th>Počet položek</th><th>Čas vykonání</th>';
    183185    $Output .= '</tr>';
     186    $PrefixMultiplier = new PrefixMultiplier();
    184187    $Result = $this->Database->select('Measure', '*', 'Enabled=1 ORDER BY Description');
    185188    while($Measure = $Result->fetch_array())
     
    199202        $Row = $Result2->fetch_array();
    200203        $LastMeasureTime = date('j.n.Y G:i:s', $this->Database->MysqlDateTimeToTime($Row['Time']));
    201         $LastMeasureValue = $this->System->AddPrefixMultipliers($Row['Avg'], $MeasureMethod['Unit']);
     204        $LastMeasureValue = $PrefixMultiplier->Add($Row['Avg'], $MeasureMethod['Unit']);
    202205      } else
    203206      {
     
    219222
    220223    //ShowPage($Output);
    221     //echo(AddPrefixMultipliers('-0.000000071112345', 'B'));
    222224    return($Output);
    223225  }
  • branches/mvc/Base/Config/ConfigSample.php

    r47 r59  
    3333    'PageRefreshPeriod' => 5000,
    3434  ),
     35  'SystemPassword' => sha1('test'),
    3536);
  • branches/mvc/Base/Controller.php

    r47 r59  
    77  function OnAccessDenied($Action, $Id)
    88  {
    9     return($this->System->Output->SystemMessage('Nemáte oprávnění provést akci "'.$Action.'" modulu "'.substr(get_class($this), 0, -10).'" na položce "'.$Id.'"'));
     9    return($this->System->Output->SystemMessage('Nemáte oprávnění provést akci "'.
     10      $Action.'" modulu "'.substr(get_class($this), 0, -10).'" na položce "'.$Id.'"'));
    1011  }
    1112
  • branches/mvc/Base/Database.php

    r47 r59  
    22
    33// Extended database class
    4 // Date: 2009-02-16
    5 
    6 class Database extends mysqli
     4// Date: 2011-11-25
     5
     6class DatabaseResult
     7{
     8  var $PDOStatement;
     9  var $num_rows = 0;
     10
     11  function fetch_assoc()
     12  {
     13    return($this->PDOStatement->fetch(PDO::FETCH_ASSOC));
     14  }
     15
     16  function fetch_array()
     17  {
     18    return($this->PDOStatement->fetch(PDO::FETCH_BOTH));
     19  }
     20
     21  function fetch_row()
     22  {
     23    return($this->PDOStatement->fetch(PDO::FETCH_NUM));
     24  }
     25}
     26
     27class Database
    728{
    829  var $Prefix = '';
    9   var $Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()');
    10   var $ShowSQLQuery = false;
    11   var $ShowSQLError = false;
     30  var $Functions;
     31  var $Type;
     32  var $PDO;
     33  var $Error = '';
     34  var $insert_id;
     35  var $LastQuery = '';
     36  var $ShowSQLError;
     37  var $ShowSQLQuery;
     38
     39  function __construct()
     40  {
     41    $this->Type = 'mysql';  // mysql, pgsql
     42    $this->ShowSQLError = false;
     43    $this->ShowSQLQuery = false;
     44    $this->Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()');
     45  }
     46
     47  function Connect($Host, $User, $Password, $Database)
     48  {
     49    if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
     50      else if($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;
     51      else $ConnectionString = '';
     52    try {
     53      $this->PDO = new PDO($ConnectionString, $User, $Password);
     54
     55    } catch (Exception $E)
     56    {
     57      unset($this->PDO);
     58      throw new Exception($E->getMessage());
     59    }
     60  }
     61
     62  function Disconnect()
     63  {
     64    unset($this->PDO);
     65  }
     66
     67  function Connected()
     68  {
     69    return(isset($this->PDO));
     70  }
     71
     72  function select_db($Database)
     73  {
     74    $this->query('USE `'.$Database.'`');
     75  }
    1276
    1377  function query($Query)
    1478  {
    15     if($this->ShowSQLQuery)
    16     {
    17       if(isset($_SERVER['REMOTE_ADDR'])) echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>');
    18       else echo($Query."\n");
    19     }
    20     $Result = parent::query($Query);
    21     if(($this->error != '') and ($this->ShowSQLError))
    22     {
    23       if(isset($_SERVER['REMOTE_ADDR'])) echo('<div><strong>SQL Error: </strong>'.$this->error.'<br />'.$Query.'</div>');
    24       echo('SQL Error: '.$this->error.' '.$Query."\n");
    25     }
    26 
     79    if(!$this->Connected()) throw new Exception('Not connected to database');
     80    $this->LastQuery = $Query;
     81    if($this->ShowSQLQuery == true)
     82      echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>'."\n");
     83    $Result = new DatabaseResult();
     84    $Result->PDOStatement = $this->PDO->query($Query);
     85    if($Result->PDOStatement)
     86    {
     87      $Result->num_rows = $Result->PDOStatement->rowCount();
     88      $this->insert_id = $this->PDO->lastInsertId();
     89    } else
     90    {
     91      $this->Error = $this->PDO->errorInfo();
     92      $this->Error = $this->Error[2];
     93      if(($this->Error != '') and ($this->ShowSQLError == true))
     94        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     95        throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query);
     96    }
    2797    return($Result);
    2898  }
     
    45115    {
    46116      $Name .= ',`'.$Key.'`';
    47       if(!in_array($Value, $this->Functions)) $Value = '"'.$this->real_escape_string($Value).'"';
     117      if(!in_array($Value, $this->Functions))
     118      {
     119        if(is_null($Value)) $Value = 'NULL';
     120        else $Value = $this->PDO->quote($Value);
     121      }
    48122      $Values .= ','.$Value;
    49123    }
     
    51125    $Values = substr($Values, 1);
    52126    $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
     127    $this->insert_id = $this->PDO->lastInsertId();
    53128  }
    54129
     
    58133    foreach($Data as $Key => $Value)
    59134    {
    60       if(!in_array($Value, $this->Functions)) $Value = '"'.$this->real_escape_string($Value).'"';
     135      if(!in_array($Value, $this->Functions))
     136      {
     137        if(is_null($Value)) $Value = 'NULL';
     138        else $Value = $this->PDO->quote($Value);
     139      }
    61140      $Values .= ', `'.$Key.'`='.$Value;
    62141    }
     
    71150    foreach($Data as $Key => $Value)
    72151    {
    73       if(!in_array($Value, $this->Functions)) $Value = '"'.$this->real_escape_string($Value).'"';
     152      if(!in_array($Value, $this->Functions))
     153      {
     154        if(is_null($Value)) $Value = 'NULL';
     155        else $Value = $this->PDO->quote($Value);
     156      }
    74157      $Name .= ',`'.$Key.'`';
    75158      $Values .= ','.$Value;
     
    79162    //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br />');
    80163    $this->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
    81     //echo($this->error().'<br/>');
     164    //echo($this->error().'<br>');
    82165  }
    83166
     
    87170  }
    88171
    89   function TimeToMysqlDateTime($Time)
    90   {
    91     return(date('Y-m-d H:i:s', $Time));
    92   }
    93 
    94   function MysqlDateTimeToTime($Time)
    95   {
    96     $Parts = explode(' ', $Time);
    97     $DateParts = explode('-', $Parts[0]);
    98     $TimeParts = explode(':', $Parts[1]);
    99     $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]);
    100     return($Result);
    101   }
    102 
    103   function MysqlDateToTime($Time)
    104   {
    105     return(MysqlDateTimeToTime($Time.' 0:0:0'));
    106   }
    107 }
     172  function real_escape_string($Text)
     173  {
     174    return(addslashes($Text));
     175  }
     176
     177  public function __sleep()
     178  {
     179    return array('LastQuery');
     180  }
     181
     182  public function __wakeup()
     183  {
     184  }
     185
     186  function MysqlDateTimeToTime($DateTime)
     187  {
     188        return(MysqlDateTimeToTime($DateTime));
     189  }
     190
     191  function TimeToMysqlDateTime($DateTime)
     192  {
     193    return(TimeToMysqlDateTime($DateTime));
     194  }
     195}
     196
     197function TimeToMysqlDateTime($Time)
     198{
     199  if($Time == NULL) return(NULL);
     200    else return(date('Y-m-d H:i:s', $Time));
     201}
     202
     203function TimeToMysqlDate($Time)
     204{
     205  if($Time == NULL) return(NULL);
     206    else return(date('Y-m-d', $Time));
     207}
     208
     209function TimeToMysqlTime($Time)
     210{
     211  if($Time == NULL) return(NULL);
     212    else return(date('H:i:s', $Time));
     213}
     214
     215function MysqlDateTimeToTime($DateTime)
     216{
     217  if($DateTime == '') return(NULL);
     218  $Parts = explode(' ', $DateTime);
     219  $DateParts = explode('-', $Parts[0]);
     220  $TimeParts = explode(':', $Parts[1]);
     221  $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]);
     222  return($Result);
     223}
     224
     225function MysqlDateToTime($Date)
     226{
     227  if($Date == '') return(NULL);
     228  return(MysqlDateTimeToTime($Date.' 0:0:0'));
     229}
     230
     231function MysqlTimeToTime($Time)
     232{
     233  if($Time == '') return(NULL);
     234  return(MysqlDateTimeToTime('0000-00-00 '.$Time));
     235}
  • branches/mvc/Base/System.php

    r47 r59  
    11<?php
    22
     3include_once(dirname(__FILE__).'/Version.php');
    34include_once(dirname(__FILE__).'/Database.php');
    45include_once(dirname(__FILE__).'/Error.php');
     
    910include_once(dirname(__FILE__).'/Output.php');
    1011include_once(dirname(__FILE__).'/Permission.php');
     12include_once(dirname(__FILE__).'/PrefixMultiplier.php');
     13include_once(dirname(__FILE__).'/Setup.php');
    1114
    1215$MonthNames = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
    13 
    14 $PrefixMultipliers = array
    15 (
    16   'Binary' => array
    17   (
    18     'BaseIndex' => 0,
    19     'Definition' => array
    20     (
    21       array('', '', pow(2, 0)),
    22       array('Ki', 'kibi', pow(2, 10)),
    23       array('Mi', 'mebi', pow(2, 20)),
    24       array('Gi', 'gibi', pow(2, 30)),
    25       array('Ti', 'tebi', pow(2, 40)),
    26       array('Pi', 'pebi', pow(2, 50)),
    27       array('Ei', 'exbi', pow(2, 60)),
    28       array('Zi', 'zebi', pow(2, 70)),
    29       array('Yi', 'yobi', pow(2, 80)),
    30     ),
    31   ),
    32   'Decimal' => array
    33   (
    34     'BaseIndex' => 8,
    35     'Definition' => array
    36     (
    37       array('y', 'yocto', pow(10, -24)),
    38       array('z', 'zepto', pow(10, -21)),
    39       array('a', 'atto', pow(10, -18)),
    40       array('f', 'femto', pow(10, -15)),
    41       array('p', 'piko', pow(10, -12)),
    42       array('n', 'nano', pow(10, -9)),
    43       array('u', 'mikro', pow(10, -6)),
    44       array('m', 'mili', pow(10, -3)),
    45       array('', '', pow(10, 0)),
    46       array('k', 'kilo', pow(10, 3)),
    47       array('M', 'mega', pow(10, 6)),
    48       array('G', 'giga', pow(10, 9)),
    49       array('T', 'tera', pow(10, 12)),
    50       array('P', 'peta', pow(10, 15)),
    51       array('E', 'exa', pow(10, 18)),
    52       array('Z', 'zetta', pow(10, 21)),
    53       array('Y', 'yotta', pow(10, 24)),
    54     ),
    55   ),
    56   'Time' => array
    57   (
    58     'BaseIndex' => 8,
    59     'Definition' => array
    60     (
    61       array('ys', 'yoctosekunda', pow(10, -24)),
    62       array('zs', 'zeptosekunda', pow(10, -21)),
    63       array('as', 'attosekunda', pow(10, -18)),
    64       array('fs', 'femtosekunda', pow(10, -15)),
    65       array('ps', 'pikosekunda', pow(10, -12)),
    66       array('ns', 'nanosekunda', pow(10, -9)),
    67       array('us', 'mikrosekunda', pow(10, -6)),
    68       array('ms', 'milisekunda', pow(10, -3)),
    69       array('s', 'sekund', 1),
    70       array('minut', 'minuta', 60),
    71       array('hodin', 'hodina', 60 * 60) ,
    72       array('dnů', 'den', 24 * 60 * 60),
    73       array('týdnů', 'týden', 7 * 24 * 60 * 60),
    74       array('měsíců', 'měsíc', 30 * 24 * 60 * 60),
    75       array('roků', 'rok', 364 * 24 * 60 * 60),
    76       array('desitiletí', 'desetiletí', 10 * 364 * 24 * 60 * 60),
    77       array('staletí', 'staletí', 100 * 364 * 24 * 60 * 60),
    78       array('tisíciletí', 'tisiciletí', 10000 * 364 * 24 * 60 * 60),
    79     ),
    80   ),
    81 );
    8216
    8317function ErrorHandler()
     
    11246    $this->Output = new Output($this);
    11347
     48    $Config = array();
     49
    11450    $FileName = dirname(__FILE__).'/Config/Config.php';
    11551    if(file_exists($FileName)) include($FileName);
     
    11854        exit;
    11955      }
    120 
    121     $Config = array();
    12256
    12357    $FileName = dirname(__FILE__).'/../Application/Config/Config.php';
     
    13872
    13973    if(isset($_SERVER['REMOTE_ADDR'])) session_start();
    140     $this->Database = new Database($this->Config['Database']['Host'],
    141     $this->Config['Database']['User'], $this->Config['Database']['Password'],
    142     $this->Config['Database']['Database']);
     74    $this->Database = new Database();
     75    $this->Database->Connect($this->Config['Database']['Host'],
     76      $this->Config['Database']['User'], $this->Config['Database']['Password'],
     77      $this->Config['Database']['Database']);
    14378    $this->Database->ShowSQLQuery = $this->Config['System']['ShowSQLQuery'];
    14479    $this->Database->ShowSQLError = $this->Config['System']['ShowSQLError'];
     
    16095    foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
    16196
     97    // Register and start existing modules
     98    $this->Setup = new Setup($this);
     99    $this->Setup->Start();
     100
    162101    if(array_key_exists('M', $_GET)) $Module = $_GET['M'];
    163102      else $Module = $this->DefaultModule;
    164103
    165104    $ControllerName = $Module.'Controller';
    166     $FileName = dirname(__FILE__).'/../Application/Controller/'.$Module.'.php';
    167     if(!file_exists($FileName))
     105    if(!class_exists($ControllerName))
    168106    {
    169       $this->Output->Show($this->Output->SystemMessage('Soubor '.$FileName.' nenalezen.'));
    170       exit;
    171     } else include($FileName);
     107        // Try to load controller class
     108      $FileName = dirname(__FILE__).'/../Application/Controller/'.$Module.'.php';
     109      if(!file_exists($FileName))
     110      {
     111        $this->Output->Show($this->Output->SystemMessage('Soubor '.$FileName.' nenalezen.'));
     112        exit;
     113      } else include($FileName);
     114    }
    172115    if(class_exists($ControllerName))
    173116    {
     
    190133  {
    191134    return(date('j.n.Y', $Time));
    192   }
    193 
    194   function TruncateDigits($Value, $Digits = 4)
    195   {
    196     for($II = 2; $II > -6; $II--)
    197     {
    198       if($Value >= pow(10, $II))
    199       {
    200         if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits;
    201         $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1);
    202         break;
    203       }
    204     }
    205     return($Value);
    206   }
    207 
    208   function AddPrefixMultipliers($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal')
    209   {
    210     global $PrefixMultipliers;
    211 
    212     $Negative = ($Value < 0);
    213     $Value = abs($Value);
    214     if(($Unit == '') and ($PrefixType != 'Time'))
    215       return($this->TruncateDigits($Value, $Digits));
    216 
    217     $I = $PrefixMultipliers[$PrefixType]['BaseIndex'];
    218     if($Value == 0) return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
    219 
    220     if($Value > 1)
    221     {
    222       while((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1))
    223         $I = $I + 1;
    224     } else
    225     if($Value < 1)
    226     {
    227       while((($I - 1) >= 0) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]) < 1))
    228         $I = $I - 1;
    229     }
    230     $Value = $Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2];
    231 
    232     // Truncate digits count
    233     $Value = $this->TruncateDigits($Value, $Digits);
    234     if($Negative) $Value = -$Value;
    235     return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
    236135  }
    237136
  • branches/mvc/Readme.txt

    r46 r59  
    66
    77* Pro správnou funkci je požadován webový server (např. Apache), MySQL databáze a PHP interpretr. Dále pro vykreslení grafů také knihovna php-gd.
     8* Zkopírujte ukázkový soubor Base/Config/ConfigSample.php jako Config.php do stejné složky a upravte v něm nastavení.
    89* Zkopírujte ukázkový soubor Application/Config/ConfigSample.php jako Config.php do stejné složky a upravte v něm nastavení.
    910* Vytvořete v databázi uživatele statistic a tabulku statistic a doplňte přístupové údaje do Config.php.
    10 * Proveďte import ukázkových dat ze souboru Full.sql s nejvyšším číslem revize umístěným ve složce SQL. Samotná struktura tabulky measure je v Measure.sql a ukázková struktura datové tabulky je v Data.sql.
    11 * Ve složce measure_scripts je ukázkový soubor monitor.sample.php, který zajišťuje získávání informací o různých veličinách v počítači a jejich plnění do systému. Zkopírujte jej jako monitor.php a upravte dle potřeb.
     11* Proveďte import ukázkových dat ze souboru Full.sql s nejvyšším číslem revize umístěným ve složce SQL.
     12Samotná struktura tabulky measure je v Measure.sql a ukázková struktura datové tabulky je v Data.sql.
     13* Ve složce measure_scripts je ukázkový soubor monitor.sample.php, který zajišťuje získávání informací o různých veličinách v počítači a jejich plnění do systému.
     14Zkopírujte jej jako monitor.php a upravte dle potřeb.
    1215
    1316
  • branches/old/stat_functions.php

    r56 r59  
    7979
    8080    // Update levels
    81     //echo($Time."<br>\n");
    8281    for($Level = 1; $Level <= $MaxLevel; $Level++)
    8382    {
    84       //echo('Level '.$Level."<br>\n");
    8583      $TimeSegment = TimeSegment($Level);
    8684      $EndTime = AlignTime($Time, $TimeSegment);
    8785      //if($EndTime < $Time) $EndTime = $EndTime + $TimeSegment;
    8886      $StartTime = $EndTime - $TimeSegment;
    89      
    90       //echo(" ".$TimeSegment." ".$StartTime.'-'.$EndTime."<br>\n");
    91       //flush();
    92  
     87
    9388      // Load values in time range
    9489      $Values = array();
     
    10095        $Values[] = $Row;
    10196      }
    102       //print_r($Values);
    10397      //array_pop($Values);     
    10498
     
    107101
    108102      $Point = ComputeOneValue($StartTime, $EndTime, $Values, $Measure, $Level);
    109       //print_r($Point);
    110103
    111104      $Database->delete($Measure['DataTable'], '(time > "'.TimeToMysqlDateTime($StartTime).'") AND
     
    121114{
    122115  $Y = ($Y2 - $Y1) / ($X2 - $X1) * ($X - $X1) + $Y1;
    123   //echo($Y1.'-'.$Y.'-'.$Y2.' '.$X1.'-'.$X.'-'.$X2.'<br>');
    124116  return($Y);
    125117}
    126118
     119/* Compute one value for upper time level from multiple values */
    127120function ComputeOneValue($LeftTime, $RightTime, $Values, $Measure, $Level)
    128121{
    129122  global $ValueTypes, $Differential;
    130  
     123
    131124  $NewValue = array('min' => +1000000000000000000, 'avg' => 0, 'max' => -1000000000000000000);
    132  
     125
    133126  // Trim outside parts
    134127  foreach($ValueTypes as $ValueType)
    135128  {
    136     $Values[0][$ValueType] = Interpolation($Values[0]['time'], $Values[0][$ValueType], $Values[1]['time'], $Values[1][$ValueType], $LeftTime);
     129    $Values[0][$ValueType] = Interpolation($Values[0]['time'], $Values[0][$ValueType],
     130      $Values[1]['time'], $Values[1][$ValueType], $LeftTime);
    137131  }
    138132  $Values[0]['time'] = $LeftTime;
    139133  foreach($ValueTypes as $ValueType)
    140   {   
    141     $Values[count($Values)-1][$ValueType] = Interpolation($Values[count($Values)-2]['time'], $Values[count($Values)-2][$ValueType],
    142       $Values[count($Values)-1]['time'], $Values[count($Values)-1][$ValueType], $RightTime);
    143   }
    144   $Values[count($Values)-1]['time'] = $RightTime;
    145  
    146   // Perform computation
     134  {
     135    $Values[count($Values) - 1][$ValueType] = Interpolation($Values[count($Values) - 2]['time'],
     136      $Values[count($Values) - 2][$ValueType],
     137      $Values[count($Values) - 1]['time'], $Values[count($Values) - 1][$ValueType], $RightTime);
     138  }
     139  $Values[count($Values) - 1]['time'] = $RightTime;
     140
     141  // Perform computation
    147142  foreach($ValueTypes as $ValueType)
    148   { 
     143  {
    149144    // Compute new value
    150145    for($I = 0; $I < (count($Values) - 1); $I++)
    151     {     
     146    {
    152147      if($ValueType == 'avg')
    153148      {
    154         if($Values[$I+1]['continuity'] == $Measure['ContinuityEnabled']);
     149        if($Values[$I + 1]['continuity'] == $Measure['ContinuityEnabled']);
    155150          else if($Differential == 0)
    156151          {
    157             $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I+1]['time'] - $Values[$I]['time']) *
    158               (($Values[$I+1][$ValueType] - $Values[$I][$ValueType]) / 2 + $Values[$I][$ValueType]);
     152            $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I + 1]['time'] - $Values[$I]['time']) *
     153              (($Values[$I + 1][$ValueType] - $Values[$I][$ValueType]) / 2 + $Values[$I][$ValueType]);
    159154          } else {
    160             $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I+1]['time'] - $Values[$I]['time']) *
    161              (($Values[$I+1][$ValueType] - $Values[$I][$ValueType]) / 2);
     155            $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I + 1]['time'] - $Values[$I]['time']) *
     156             (($Values[$I + 1][$ValueType] - $Values[$I][$ValueType]) / 2);
    162157          }
    163158      }
    164       else if($ValueType == 'max') 
    165       {
    166         if($Values[$I+1]['continuity'] == $Measure['ContinuityEnabled'])
     159      else if($ValueType == 'max')
     160      {
     161        if($Values[$I + 1]['continuity'] == $Measure['ContinuityEnabled'])
    167162        {
    168163          if(0 > $NewValue[$ValueType]) $NewValue[$ValueType] = 0;
    169164        }
    170         else 
     165        else
    171166        {
    172167          if($Differential == 0)
    173168          {
    174             if($Values[$I+1][$ValueType] > $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I+1][$ValueType];
     169            if($Values[$I + 1][$ValueType] > $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType];
    175170          } else {
    176             $Difference = $Values[$I+1][$ValueType] - $Values[$I][$ValueType];
     171            $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType];
    177172            if($Difference > $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;
    178           } 
     173          }
    179174        }
    180175      }
    181176      else if($ValueType == 'min')
    182177      {
    183         //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>');
    184         if($Values[$I+1]['continuity'] == $Measure['ContinuityEnabled'])
     178        if($Values[$I + 1]['continuity'] == $Measure['ContinuityEnabled'])
    185179        {
    186180          if(0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0;
     
    188182          if($Differential == 0)
    189183          {
    190             if($Values[$I+1][$ValueType] < $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I+1][$ValueType];
     184            if($Values[$I + 1][$ValueType] < $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType];
    191185          } else {
    192             $Difference = $Values[$I+1][$ValueType] - $Values[$I][$ValueType];
     186            $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType];
    193187            if($Difference < $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;
    194188          }
     
    196190      }
    197191    }
    198     $NewValue[$ValueType] = $NewValue[$ValueType]; 
     192    $NewValue[$ValueType] = $NewValue[$ValueType];
    199193  }
    200194  //if(($RightTime - $LeftTime) > 0)
    201   if($Measure['Cumulative'] == 0) 
     195  if($Measure['Cumulative'] == 0)
    202196  {
    203197    $NewValue['avg'] = $NewValue['avg'] / ($RightTime - $LeftTime);
    204   } 
     198  }
    205199  return($NewValue);
    206   //echo($NewValue['avg'].'<br>');
    207   //return(array('min' => rand(0,1), 'avg' => $NewValue['avg'], 'max' => rand(0,1)));
    208200}
    209201
     
    213205
    214206  // Get first and last time
    215   //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n");
    216207  $Result = $Database->select($Measure['DataTable'], '*', 'measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time LIMIT 1');
    217208  if($Result->num_rows > 0)
     
    239230{
    240231  global $Debug, $Database;
     232 
    241233  $Result = array();
    242   $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time ASC LIMIT 1');
     234  $DbResult = $Database->select($Measure['DataTable'], '*', '(time > "'.TimeToMysqlDateTime($Time).'") AND (measure='.$Measure['Id'].') AND (level='.$Level.') ORDER BY time ASC LIMIT 1');
    243235  if($DbResult->num_rows > 0)
    244236  {
     
    252244    //array_push($Values, array('time' => $Time, 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0));
    253245    $Result[] = array('time' => ($Time + TimeSegment($Level)), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0);
    254     $DbResult = $Database->select($Measure['DataTable'], '*', 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1');
     246    $DbResult = $Database->select($Measure['DataTable'], '*', '(time < "'.TimeToMysqlDateTime($Time).'") AND (measure='.$Measure['Id'].') AND (level='.$Level.') ORDER BY time DESC LIMIT 1');
    255247    if($DbResult->num_rows > 0)
    256248    {
     
    266258{
    267259  global $Debug, $Database;
     260
    268261  $Result = array();
    269   //echo('SELECT * FROM '.StatTableName($Level). ' WHERE '. 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1'."<br>\n");
    270   $DbResult = $Database->select($Measure['DataTable'], '*', 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1');
     262  $DbResult = $Database->select($Measure['DataTable'], '*', '(time < "'.TimeToMysqlDateTime($Time).'") AND (measure='.$Measure['Id'].') AND (level='.$Level.') ORDER BY time DESC LIMIT 1');
    271263  if($DbResult->num_rows > 0)
    272264  {
     
    279271    $Result[] = array('time' => ($Time - TimeSegment($Level)), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0);
    280272
    281     $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time ASC LIMIT 1');
     273    $DbResult = $Database->select($Measure['DataTable'], '*', '(time > "'.TimeToMysqlDateTime($Time).'") AND (measure='.$Measure['Id'].') AND (level='.$Level.') ORDER BY time ASC LIMIT 1');
    282274    if($DbResult->num_rows > 0)
    283275    {
    284276      $Row = $DbResult->fetch_array();
    285       array_push($Result, array('time' => (MysqlDateTimeToTime($Row['time'])-10), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0));
    286     }
    287 //    if($Debug) print_r($Result);
     277      array_push($Result, array('time' => (MysqlDateTimeToTime($Row['time']) - 10),
     278        'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0));
     279    }
    288280    return($Result);
    289281  }
     
    306298  $Result = $Database->select($Measure['DataTable'], 'time, min, avg, max, continuity', 'time > "'.TimeToMysqlDateTime($TimeFrom).'" AND time < "'.
    307299    TimeToMysqlDateTime($TimeTo).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time');
    308 //  echo($Level.' '.TimeToMysqlDateTime($TimeFrom).' '.TimeToMysqlDateTime($TimeTo));
    309300  $Values = array();
    310 //  echo(DB_NumRows());
    311 //  $III = 0;
    312301  while($Row = $Result->fetch_array())
    313302  {
    314 //    echo($III.' '.$Row['time'].' '.memory_get_usage().',');
    315 //    $III++;
    316303    $Values[] = array('time' => MysqlDateTimeToTime($Row['time']), 'min' => $Row['min'], 'avg' => $Row['avg'], 'max' => $Row['max'], 'continuity' => $Row['continuity']);
    317304  }
    318305 // array_pop($Values);
    319 //  echo('abc');
    320 //  die();
    321306  if($Debug) echo('Item count: '.count($Values));
    322  
     307
    323308  $Points = array();
    324309  if(count($Values) > 0)
     
    326311    $Values = array_merge(LoadLeftSideValue($Level, $Measure, $TimeFrom), $Values, LoadRightSideValue($Level, $Measure, $TimeTo));
    327312
    328     //echo(count($Values).'<br>');
    329     //echo($TimeFrom.','.$TimeTo.'<br>');
    330     //echo($Values[0]['time'].'<br>');
    331313    $StartIndex = 0;
    332314    $Points = array();
    333     //echo($DivisionCount.'<br>');
    334315    for($I = 0; $I < $DivisionCount; $I++)
    335316    {
     
    338319      $TimeEnd = $TimeFrom + (($TimeTo - $TimeFrom) / $DivisionCount) * ($I+1);
    339320      //if($Debug) echo('TimeEnd '.$I.': '.$TimeEnd.'('.TimeToMysqlDateTime($TimeEnd).')<br>');
    340       //echo($TimeStart.','.$TimeEnd.'<br>');
    341321
    342322      $EndIndex = $StartIndex;
    343323      while($Values[$EndIndex]['time'] < $TimeEnd) $EndIndex = $EndIndex + 1;
    344324      $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1);
    345       //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br>');
    346       //print_r($SubValues);
    347325      $Points[] = ComputeOneValue($TimeStart, $TimeEnd, $SubValues, $Measure, $Level);
    348326      $StartIndex = $EndIndex - 1; 
     
    371349    echo('Uroven '.$Level."<br>\n");
    372350    $TimeRange = GetTimeRange($Measure, $Level-1);
    373     //echo($Measure['Id'].','.($Level-1)."\n");
    374     //echo(TimeToMysqlDateTime($TimeRange['left']).'-'.TimeToMysqlDateTime($TimeRange['right'])."\n");
    375351    $TimeSegment = TimeSegment($Level);
    376352    $StartTime = AlignTime($TimeRange['left'], $TimeSegment) - $TimeSegment;
     
    382358      echo($I.' ');
    383359      $StartTime2 = $StartTime + $I * $BurstCount * $TimeSegment;
    384       $EndTime2 = $StartTime + ($I+1) * $BurstCount * $TimeSegment;
     360      $EndTime2 = $StartTime + ($I + 1) * $BurstCount * $TimeSegment;
    385361      $Values = array();
    386       $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($StartTime2).'" AND time < "'.
    387         TimeToMysqlDateTime($EndTime2).'" AND measure='.$Measure['Id'].' AND level='.($Level-1).' ORDER BY time');
     362      $DbResult = $Database->select($Measure['DataTable'], '*', '(time > "'.TimeToMysqlDateTime($StartTime2).'") AND (time < "'.
     363        TimeToMysqlDateTime($EndTime2).'") AND (measure='.$Measure['Id'].') AND (level='.($Level - 1).') ORDER BY time');
    388364      while($Row = $DbResult->fetch_array())
    389365      {
     
    394370      if(count($Values) > 0)
    395371      {
    396         $Values = array_merge(LoadLeftSideValue($Level-1, $Measure, $StartTime2), $Values, LoadRightSideValue($Level-1, $Measure, $EndTime2));
     372        $Values = array_merge(LoadLeftSideValue($Level - 1, $Measure, $StartTime2), $Values, LoadRightSideValue($Level - 1, $Measure, $EndTime2));
    397373
    398374        $StartIndex = 0;
     
    401377          echo('.');
    402378          $StartTime3 = $StartTime2 + (($EndTime2 - $StartTime2) / $BurstCount) * $B;
    403           $EndTime3 = $StartTime2 + (($EndTime2 - $StartTime2) / $BurstCount) * ($B+1);
     379          $EndTime3 = $StartTime2 + (($EndTime2 - $StartTime2) / $BurstCount) * ($B + 1);
    404380
    405381          $EndIndex = $StartIndex;
    406382          while($Values[$EndIndex]['time'] < $EndTime3) $EndIndex = $EndIndex + 1;
    407383          $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1);
    408           //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br>');
    409           //print_r($SubValues);
    410           if(count($SubValues) > 2)
     384         if(count($SubValues) > 2)
    411385          {
    412386            $Point = ComputeOneValue($StartTime3, $EndTime3, $SubValues, $Measure, $Level);
    413             $Continuity = $SubValues[1]['continuity'];   
    414             $Database->insert($Measure['DataTable'], array('level' => $Level, 'measure' => $Measure['Id'], 'min' => $Point['min'],
    415               'avg' => $Point['avg'], 'max' => $Point['max'], 'continuity' => $Continuity, 'time' => TimeToMysqlDateTime($StartTime3+($EndTime3-$StartTime3)/2)));
     387            $Continuity = $SubValues[1]['continuity'];
     388            $Database->insert($Measure['DataTable'], array('level' => $Level, 'measure' => $Measure['Id'],
     389              'min' => $Point['min'], 'avg' => $Point['avg'], 'max' => $Point['max'],
     390              'continuity' => $Continuity, 'time' => TimeToMysqlDateTime($StartTime3 + ($EndTime3 - $StartTime3) / 2)));
    416391          }
    417392          $StartIndex = $EndIndex - 1;
     
    425400    $Row = $DbResult->fetch_array();
    426401    echo("Vlozeno ".$Row[0]." polozek.<br>\n");
    427   } 
    428 }   
     402  }
     403}
    429404
    430405function RebuildAllMeasuresCache()
     
    432407  global $Database;
    433408
    434 //  echo("Vytvarim novou cache...\n");
    435     // Load measures
     409  // Load measures
    436410  $Measures = array();
    437411  $Result = $Database->select('measure', '*');
Note: See TracChangeset for help on using the changeset viewer.