Changeset 84


Ignore:
Timestamp:
Jan 20, 2018, 11:33:54 AM (6 years ago)
Author:
chronos
Message:
  • Added: Ability to move view to the left and right by one period and also to the left and right most measured value.
  • Added: New period "All" to show all measured values.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Core.php

    r80 r84  
    3636    $ErrorHandler = new ErrorHandler();
    3737    $ErrorHandler->ShowError = $Config['Web']['ShowError'];
    38     $ErrorHandler->Start();
     38    //$ErrorHandler->Start();
    3939
    4040    try {
  • trunk/Application/Version.php

    r80 r84  
    66// and system will need database update.
    77
    8 $Revision = 79;
     8$Revision = 84;
    99$DatabaseRevision = 79;
    10 $ReleaseTime = strtotime('2016-12-31');
     10$ReleaseTime = strtotime('2018-01-20');
  • trunk/Modules/Measure/Page.php

    r72 r84  
    44{
    55  var $Months;
    6   var $GrafTimeRanges;
     6  var $GraphTimeRanges;
    77
    88  function __construct(System $System)
     
    1212      'Říjen', 'Listopad', 'Prosinec');
    1313
    14     $this->GrafTimeRanges = array(
     14    $this->GraphTimeRanges = array(
    1515      'hour' => array(
    1616        'caption' => 'Hodina',
     
    3737        'period' => 3600 * 24 * 365 * 10,
    3838      ),
     39      'all' => array(
     40        'caption' => 'Vše',
     41        'period' => -1,
     42      ),
    3943    );
     44    $this->Time = time();
     45  }
     46 
     47  function GetTimeRange()
     48  {
     49    $Result = $this->GraphTimeRanges[$_SESSION['Period']]['period'];
     50    if ($Result == -1)
     51    {
     52      $Measure = $this->LoadMeasure($_SESSION['Measure']);
     53      $FirstValue = $this->GetFirstMeasure($Measure);
     54      $LastValue = $this->GetLastMeasure($Measure);
     55      $Result = $LastValue['Time'] - $FirstValue['Time'];
     56    }
     57    return $Result;
    4058  }
    4159
     
    98116    return($Output);
    99117  }
    100 
     118 
     119  function GetFirstMeasure($Measure)
     120  {
     121    $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.$Measure['Id'].') AND (`Level`=0) ORDER BY `Time` ASC LIMIT 1');
     122    if($Result2->num_rows > 0)
     123    {
     124      $Row = $Result2->fetch_array();
     125      $LastMeasureTime = MysqlDateTimeToTime($Row['Time']);
     126      $LastMeasureValue = $Row['Avg'];
     127    } else {
     128      $LastMeasureTime = $this->Time - $this->GetTimeRange();
     129      $LastMeasureValue = 0;
     130    }
     131    return(array('Time' => $LastMeasureTime, 'Value' => $LastMeasureValue));
     132  }
     133
     134  function GetLastMeasure($Measure)
     135  {
     136    $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.$Measure['Id'].') AND (`Level`=0) ORDER BY `Time` DESC LIMIT 1');
     137    if($Result2->num_rows > 0)
     138    {
     139      $Row = $Result2->fetch_array();
     140      $LastMeasureTime = MysqlDateTimeToTime($Row['Time']);
     141      $LastMeasureValue = $Row['Avg'];
     142    } else {
     143      $LastMeasureTime = $this->Time;
     144      $LastMeasureValue = 0;
     145    }
     146    return(array('Time' => $LastMeasureTime, 'Value' => $LastMeasureValue));
     147  }
     148 
     149  function LoadMeasure($Id)
     150  {
     151    $DbResult = $this->Database->select('Measure', '*', '( `Enabled`=1) AND (`Id`='.$Id.') AND ((`PermissionView`="all") OR (`PermissionView`="'.
     152      gethostbyaddr($_SERVER['REMOTE_ADDR']).'"))');   
     153    $DbRow = $DbResult->fetch_array();
     154    return $DbRow;
     155  }
     156 
    101157  /* Produce table with available measures */
    102158  function ShowMeasureTable()
     
    107163    if(array_key_exists('Debug', $_GET)) $Output .= '<th>Počet položek</th><th>Čas vykonání</th>';
    108164    $Output .= '</tr>';
    109     $Result = $this->Database->select('Measure', '*', '( `Enabled`=1) AND ((`PermissionView`="all") OR (`PermissionView`="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) ORDER BY `Description`');
     165    $Result = $this->Database->select('Measure', '*', '( `Enabled`=1) AND ((`PermissionView`="all") OR (`PermissionView`="'.
     166      gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) ORDER BY `Description`');
    110167    while($Measure = $Result->fetch_array())
    111168    {
     
    113170      if(array_key_exists('Debug', $_GET))
    114171      {
    115         $DbResult = $this->Database->select($Measure['DataTable'], 'COUNT(*)', '`measure`='.$Measure['Id']);
     172        $DbResult = $this->Database->select($Measure['DataTable'], 'COUNT(*)', '`Measure`='.$Measure['Id']);
    116173        $RowCount = $DbResult->fetch_array();
    117174        $RowCount = $RowCount[0];
    118175      }
    119       $Result2 = $this->Database->select($Measure['DataTable'], 'time, avg', '(`measure`='.$Measure['Id'].') AND (`level`=0) ORDER BY time DESC LIMIT 1');
     176      $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.
     177        $Measure['Id'].') AND (`Level`=0) ORDER BY `Time` DESC LIMIT 1');
    120178      if($Result2->num_rows > 0)
    121179      {
    122180        $Row = $Result2->fetch_array();
    123         $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['time']));
    124         $LastMeasureValue = $PrefixMultiplier->Add($Row['avg'], $Measure['Unit']);
     181        $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['Time']));
     182        $LastMeasureValue = $PrefixMultiplier->Add($Row['Avg'], $Measure['Unit']);
    125183      } else {
    126184        $LastMeasureTime = '&nbsp;';
     
    130188      if($Measure['Info'] == '') $Measure['Info'] = '&nbsp;';
    131189      $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
    132       $Output .= '<tr><td style="text-align: left"><a href="?Measure='.$Measure['Id'].'&amp;Differential=0">'.$Measure['Description'].'</a></td><td align="center">'.$LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'.$Interpolate.'</td><td>'.$Measure['Info'].'</td>';
    133       if(array_key_exists('Debug', $_GET)) $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>';
     190      $Output .= '<tr><td style="text-align: left"><a href="?Measure='.$Measure['Id'].
     191        '&amp;Differential=0">'.$Measure['Description'].'</a></td><td align="center">'.
     192        $LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'.
     193        $Interpolate.'</td><td>'.$Measure['Info'].'</td>';
     194      if(array_key_exists('Debug', $_GET))
     195        $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>';
    134196      $Output .= '</tr>';
    135197    }
     
    155217  {
    156218    $Output = '';
    157     if($_SESSION['TimeSpecify'] == 0)
    158     {
    159       $_SESSION['TimeEnd'] = time() - 60;
    160       $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GrafTimeRanges[$_SESSION['Period']]['period'];
    161     }
    162219
    163220    if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = '';
     
    180237          if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
    181238          {
    182             $_SESSION[$_GET['Time']] = time();
     239            $_SESSION[$_GET['Time']] = $this->Time;
    183240          }
    184241        }
     
    192249    {
    193250      $Output .= 'Délka úseku: ';
    194       foreach($this->GrafTimeRanges as $Index => $Item)
     251      foreach($this->GraphTimeRanges as $Index => $Item)
    195252        $Output .= '<a href="?Period='.$Index.'">'.$Item['caption'].'</a>&nbsp;';
    196253      $Output .= '<br>';
     
    203260      $Output .= '<a href="?TimeSpecify=0">Jednoduché nastavení...</a><br>';
    204261    }
     262    $Output .= 'Posun: <a href="?Move=LeftEnd">|&lt;</a> <a href="?Move=Left">&lt;</a> '.
     263      '<a href="?Move=Right">&gt;</a> <a href="?Move=RightEnd">&gt;|</a> <a href="?Move=Now">Nyní</a><br>';
    205264    $Output .= '<br/>';
    206265    return($Output);
    207266
    208267  }
     268 
     269  function HandleURL()
     270  {
     271    global $Config;
     272   
     273    foreach ($Config['DefaultVariables'] as $Index => $Variable)
     274    {
     275      if (!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable;
     276      //if(array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index];
     277      //if(array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index];
     278      //$$Index = $_SESSION[$Index];
     279    }
     280    if (array_key_exists('Period', $_GET))
     281    {
     282      $_SESSION['Period'] = $_GET['Period'];
     283      // Update time start according time period
     284      if ($_SESSION['Period'] == 'all')
     285      {
     286        $Measure = $this->LoadMeasure($_SESSION['Measure']);
     287        $FirstValue = $this->GetFirstMeasure($Measure);
     288        $LastValue = $this->GetLastMeasure($Measure);
     289        $_SESSION['TimeStart'] = $FirstValue['Time'];
     290        $_SESSION['TimeEnd'] = $LastValue['Time'];
     291      } else
     292      {
     293        $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
     294      }
     295    }
     296    if (array_key_exists('TimeStart', $_GET))
     297    {
     298      $_SESSION['TimeStart'] = $_GET['TimeStart'];
     299    }
     300    if (array_key_exists('TimeEnd', $_GET))
     301    {
     302      $_SESSION['TimeStart'] = $_GET['TimeEnd'];
     303    }
     304    if (array_key_exists('Differential', $_GET))
     305    {
     306      $_SESSION['Differential'] = $_GET['Differential'];
     307    }
     308    if (array_key_exists('Measure', $_GET))
     309    {
     310      $_SESSION['Measure'] = $_GET['Measure'];
     311    }
     312    if (array_key_exists('TimeSpecify', $_GET))
     313    {
     314      if (($_SESSION['TimeSpecify'] == 1) and ($_GET['TimeSpecify'] == 0))
     315      {
     316        $_SESSION['TimeEnd'] = $this->Time - 60;
     317        $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
     318      }
     319      $_SESSION['TimeSpecify'] = $_GET['TimeSpecify'];
     320    }
     321   
     322    if (array_key_exists('Move', $_GET))
     323    {
     324      $Move = $_GET['Move'];
     325      if ($Move == 'Left')
     326      {
     327        $_SESSION['TimeStart'] = $_SESSION['TimeStart'] - $this->GetTimeRange();
     328        $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
     329      } else
     330      if ($Move == 'Right')
     331      {
     332        $_SESSION['TimeStart'] = $_SESSION['TimeStart'] + $this->GetTimeRange();
     333        $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] + $this->GetTimeRange();
     334      } else
     335      if ($Move == 'Now')
     336      {
     337        $_SESSION['TimeEnd'] = $this->Time - 60;
     338        $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
     339      } else
     340      if ($Move == 'LeftEnd')
     341      {
     342        $Measure = $this->LoadMeasure($_SESSION['Measure']);
     343        $FirstValue = $this->GetFirstMeasure($Measure);
     344        $_SESSION['TimeStart'] = $FirstValue['Time'];
     345        $_SESSION['TimeEnd'] = $_SESSION['TimeStart'] + $this->GetTimeRange();
     346      } else
     347      if ($Move == 'RightEnd')
     348      {
     349        $Measure = $this->LoadMeasure($_SESSION['Measure']);
     350        $LastValue = $this->GetLastMeasure($Measure);
     351        $_SESSION['TimeEnd'] = $LastValue['Time'];
     352        $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
     353      }
     354    }
     355  }
    209356
    210357  function Show()
     
    213360
    214361    $Debug = 0;
    215     foreach($Config['DefaultVariables'] as $Index => $Variable)
    216     {
    217       if(!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable;
    218       if(array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index];
    219       if(array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index];
    220       //$$Index = $_SESSION[$Index];
    221     }
    222 
     362    $this->HandleURL();
     363   
    223364    $Output = '<div style="text-align: center"><div class="Title">'.$Config['Web']['Title'].'</div>';
    224365
    225366    $Result = $this->Database->select('Measure', 'Id', '(`Enabled`=1) AND '.
    226         '((`PermissionView`="all") OR (`PermissionView`="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) '.
    227         'AND (`Id`='.($_SESSION['Measure'] * 1).')');
     367      '((`PermissionView`="all") OR (`PermissionView`="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) '.
     368      'AND (`Id`='.($_SESSION['Measure'] * 1).')');
    228369    if($Result->num_rows == 0)
    229370      $_SESSION['Measure'] = $Config['DefaultVariables']['Measure'];
Note: See TracChangeset for help on using the changeset viewer.