Ignore:
Timestamp:
Apr 7, 2020, 11:53:58 AM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Measure/Measure.php

    r91 r92  
    8383  function TimeSegment($Level)
    8484  {
    85     return(pow($this->LevelReducing, $Level) * 60);
     85    return pow($this->LevelReducing, $Level) * 60;
    8686  }
    8787
    8888  function GetDataTable()
    8989  {
    90     return('data_'.$this->Data['Name']);
     90    return 'data_'.$this->Data['Name'];
    9191  }
    9292
    9393  function AlignTime($Time, $TimeSegment)
    9494  {
    95     return(round(($Time - $this->ReferenceTime) / $TimeSegment) * $TimeSegment +
    96       $this->ReferenceTime);
     95    return round(($Time - $this->ReferenceTime) / $TimeSegment) * $TimeSegment +
     96      $this->ReferenceTime;
    9797  }
    9898
     
    100100  {
    101101    $Result = $this->Database->select('Measure', '*', '`Id`='.$Id);
    102     if($Result->num_rows > 0)
     102    if ($Result->num_rows > 0)
    103103    {
    104104      $this->Data = $Result->fetch_array();
    105       if($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0;  // non continuous
     105      if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0;  // non continuous
    106106        else $this->Data['ContinuityEnabled'] = 2;    // continuous graph
    107107    } else die('Měřená veličina '.$Id.' nenalezena.');
     
    112112    $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '.
    113113      '(`Level`=0) ORDER BY `Time` DESC LIMIT 2');
    114     if($Result->num_rows == 0) {
     114    if ($Result->num_rows == 0) {
    115115      // No measure value found. Simply insert new first value.
    116116      $this->Database->insert($this->Data['DataTable'],
     
    118118        'Measure' => $this->Data['Id'], 'Time' => TimeToMysqlDateTime($Time),
    119119        'Continuity' => 0));
    120     } else if($Result->num_rows == 1) {
     120    } else if ($Result->num_rows == 1) {
    121121      // One value exists. Add second value.
    122122      $this->Database->insert($this->Data['DataTable'],
     
    128128      $LastValue = $Result->fetch_array();
    129129      $NextToLastValue = $Result->fetch_array();
    130       if(($Time - MysqlDateTimeToTime($LastValue['Time'])) < (1 - $this->PeriodTolerance) * $this->Data['Period'])
     130      if (($Time - MysqlDateTimeToTime($LastValue['Time'])) < (1 - $this->PeriodTolerance) * $this->Data['Period'])
    131131      {
    132132        // New value added too quickly. Need to wait for next measure period.
     
    135135      {
    136136        // We are near defined period and can add new value.
    137         if(($Time - MysqlDateTimeToTime($LastValue['Time'])) < (1 + $this->PeriodTolerance) * $this->Data['Period']) {
     137        if (($Time - MysqlDateTimeToTime($LastValue['Time'])) < (1 + $this->PeriodTolerance) * $this->Data['Period']) {
    138138          // New value added near defined measure period inside tolerance. Keep continuity.
    139139          $Continuity = 1;
     
    143143          $Continuity = 0;
    144144        }
    145         if(($LastValue['Avg'] == $NextToLastValue['Avg']) and ($LastValue['Avg'] == $Value) and
     145        if (($LastValue['Avg'] == $NextToLastValue['Avg']) and ($LastValue['Avg'] == $Value) and
    146146          ($LastValue['Continuity'] == 1) and ($Continuity == 1))
    147147        {
     
    165165  function UpdateHigherLevels($Time)
    166166  {
    167     for($Level = 1; $Level <= $this->MaxLevel; $Level++)
     167    for ($Level = 1; $Level <= $this->MaxLevel; $Level++)
    168168    {
    169169      $TimeSegment = $this->TimeSegment($Level);
    170170      $EndTime = $this->AlignTime($Time, $TimeSegment);
    171       //if($EndTime < $Time) $EndTime = $EndTime + $TimeSegment;
     171      //if ($EndTime < $Time) $EndTime = $EndTime + $TimeSegment;
    172172      $StartTime = $EndTime - $TimeSegment;
    173173
     
    178178        '(`Time` < "'.TimeToMysqlDateTime($EndTime).'") AND '.
    179179        '(`Measure`='.$this->Data['Id'].') AND (`Level`='.($Level - 1).') ORDER BY `Time`');
    180       while($Row = $Result->fetch_array())
     180      while ($Row = $Result->fetch_array())
    181181      {
    182182        $Row['Time'] = MysqlDateTimeToTime($Row['Time']);
     
    211211
    212212    // Trim outside parts
    213     foreach($this->ValueTypes as $ValueType)
     213    foreach ($this->ValueTypes as $ValueType)
    214214    {
    215215      $Values[0][$ValueType] = Interpolation(
     
    218218    }
    219219    $Values[0]['Time'] = $LeftTime;
    220     foreach($this->ValueTypes as $ValueType)
     220    foreach ($this->ValueTypes as $ValueType)
    221221    {
    222222      $Values[count($Values) - 1][$ValueType] = Interpolation(
     
    228228
    229229    // Perform computation
    230     foreach($this->ValueTypes as $ValueType)
     230    foreach ($this->ValueTypes as $ValueType)
    231231    {
    232232      // Compute new value
    233       for($I = 0; $I < (count($Values) - 1); $I++)
    234       {
    235         if($ValueType == 'Avg')
     233      for ($I = 0; $I < (count($Values) - 1); $I++)
     234      {
     235        if ($ValueType == 'Avg')
    236236        {
    237237          if ($this->Data['Cumulative'])
     
    240240          } else
    241241          {
    242             if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']);
    243             else if($this->Differential == 0)
     242            if ($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']);
     243            else if ($this->Differential == 0)
    244244            {
    245245              $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I + 1]['Time'] - $Values[$I]['Time']) *
     
    251251          }
    252252        }
    253         else if($ValueType == 'Max')
    254         {
    255           if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled'])
     253        else if ($ValueType == 'Max')
     254        {
     255          if ($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled'])
    256256          {
    257             if(0 > $NewValue[$ValueType]) $NewValue[$ValueType] = 0;
     257            if (0 > $NewValue[$ValueType]) $NewValue[$ValueType] = 0;
    258258          }
    259259          else
    260260          {
    261             if($this->Differential == 0)
     261            if ($this->Differential == 0)
    262262            {
    263               if($Values[$I + 1][$ValueType] > $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType];
     263              if ($Values[$I + 1][$ValueType] > $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType];
    264264            } else {
    265265              $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType];
    266               if($Difference > $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;
     266              if ($Difference > $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;
    267267            }
    268268          }
    269269        }
    270         else if($ValueType == 'Min')
    271         {
    272           if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled'])
     270        else if ($ValueType == 'Min')
     271        {
     272          if ($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled'])
    273273          {
    274             if(0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0;
     274            if (0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0;
    275275          } else {
    276             if($this->Differential == 0)
     276            if ($this->Differential == 0)
    277277            {
    278               if($Values[$I + 1][$ValueType] < $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType];
     278              if ($Values[$I + 1][$ValueType] < $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType];
    279279            } else {
    280280              $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType];
    281               if($Difference < $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;
     281              if ($Difference < $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;
    282282            }
    283283          }
     
    286286      $NewValue[$ValueType] = $NewValue[$ValueType];
    287287    }
    288     //if(($RightTime - $LeftTime) > 0)
    289     if($this->Data['Cumulative'] == 0)
     288    //if (($RightTime - $LeftTime) > 0)
     289    if ($this->Data['Cumulative'] == 0)
    290290    {
    291291      $NewValue['Avg'] = $NewValue['Avg'] / ($RightTime - $LeftTime);
    292292    }
    293     return($NewValue);
     293    return $NewValue;
    294294  }
    295295
     
    299299    $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '.
    300300      '(`Level`='.$Level.') ORDER BY `Time` LIMIT 1');
    301     if($Result->num_rows > 0)
     301    if ($Result->num_rows > 0)
    302302    {
    303303      $Row = $Result->fetch_array();
     
    307307    $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '.
    308308      '(`Level`='.$Level.') ORDER BY `Time` DESC LIMIT 1');
    309     if($Result->num_rows > 0)
     309    if ($Result->num_rows > 0)
    310310    {
    311311      $Row = $Result->fetch_array();
     
    313313    } else $AbsoluteRightTime = 0;
    314314
    315     return(array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime));
     315    return array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime);
    316316  }
    317317
     
    323323      '(`Time` > "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.
    324324      $this->Data['Id'].') AND (`Level`='.$Level.') ORDER BY `Time` ASC LIMIT 1');
    325     if($DbResult->num_rows > 0)
     325    if ($DbResult->num_rows > 0)
    326326    {
    327327      // Found one value, simply return it
    328328      $Row = $DbResult->fetch_array();
    329329      $Row['Time'] = MysqlDateTimeToTime($Row['Time']);
    330       return(array($Row));
     330      return array($Row);
    331331    } else
    332332    {
     
    339339        '(`Time` < "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.$this->Data['Id'].') '.
    340340        'AND (`Level`='.$Level.') ORDER BY `Time` DESC LIMIT 1');
    341       if($DbResult->num_rows > 0)
     341      if ($DbResult->num_rows > 0)
    342342      {
    343343        $Row = $DbResult->fetch_array();
     
    345345          'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));
    346346      }
    347       return($Result);
     347      return $Result;
    348348    }
    349349  }
     
    356356      '(`Time` < "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.$this->Data['Id'].') '.
    357357      'AND (`Level`='.$Level.') ORDER BY `Time` DESC LIMIT 1');
    358     if($DbResult->num_rows > 0)
     358    if ($DbResult->num_rows > 0)
    359359    {
    360360      // Found one value, simply return it
    361361      $Row = $DbResult->fetch_array();
    362362      $Row['Time'] = MysqlDateTimeToTime($Row['Time']);
    363       return(array($Row));
     363      return array($Row);
    364364    } else {
    365365      // Not found any value. Calculate it
     
    372372        '(`Time` > "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.$this->Data['Id'].') '.
    373373        'AND (`Level`='.$Level.') ORDER BY `Time` ASC LIMIT 1');
    374       if($DbResult->num_rows > 0)
     374      if ($DbResult->num_rows > 0)
    375375      {
    376376        $Row = $DbResult->fetch_array();
     
    378378          'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));
    379379      }
    380       return($Result);
     380      return $Result;
    381381    }
    382382  }
     
    386386  //$AbsoluteTime = GetTimeRange($this->DataId);
    387387
    388 //  if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and
     388//  if (($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and
    389389//    ($TimeTo > $AbsoluteLeftTime) and ($TimeTo < $AbsoluteRightTime))
    390390//  {
     
    397397      '(`Measure`='.$this->Data['Id'].') AND (`Level`='.$Level.') ORDER BY `Time`');
    398398    $Values = array();
    399     while($Row = $Result->fetch_array())
     399    while ($Row = $Result->fetch_array())
    400400    {
    401401      $Values[] = array('Time' => MysqlDateTimeToTime($Row['Time']),
     
    406406
    407407    $Points = array();
    408     if(count($Values) > 0)
     408    if (count($Values) > 0)
    409409    {
    410410      $Values = array_merge(
     
    415415      $StartIndex = 0;
    416416      $Points = array();
    417       for($I = 0; $I < $this->DivisionCount; $I++)
     417      for ($I = 0; $I < $this->DivisionCount; $I++)
    418418      {
    419419        $TimeStart = $TimeFrom + (($TimeTo - $TimeFrom) / $this->DivisionCount) * $I;
     
    421421
    422422        $EndIndex = $StartIndex;
    423         while($Values[$EndIndex]['Time'] < $TimeEnd) $EndIndex = $EndIndex + 1;
     423        while ($Values[$EndIndex]['Time'] < $TimeEnd) $EndIndex = $EndIndex + 1;
    424424        $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1);
    425425        $Points[] = $this->ComputeOneValue($TimeStart, $TimeEnd, $SubValues, $Level);
     
    427427      }
    428428    } else $Points[] = array('Min' => 0, 'Avg' => 0, 'Max' => 0);
    429     return($Points);
     429    return $Points;
    430430  }
    431431
     
    433433  {
    434434    echo('Velicina '.$this->Data['Name']."<br>\n");
    435     if($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0;  // non continuous
     435    if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0;  // non continuous
    436436      else $this->Data['ContinuityEnabled'] = 2;    // continuous graph
    437437
     
    443443    echo("<br>\n");
    444444
    445     for($Level = 1; $Level <= $this->MaxLevel; $Level++)
     445    for ($Level = 1; $Level <= $this->MaxLevel; $Level++)
    446446    {
    447447      echo('Uroven '.$Level."<br>\n");
     
    453453      $Count = round(($EndTime - $StartTime) / $TimeSegment / $BurstCount);
    454454      echo('For 0 to '.$Count."<br>\n");
    455       for($I = 0; $I <= $Count; $I++)
     455      for ($I = 0; $I <= $Count; $I++)
    456456      {
    457457        echo($I.' ');
     
    463463          TimeToMysqlDateTime($EndTime2).'") AND (`Measure`='.$this->Data['Id'].
    464464          ') AND (`Level`='.($Level - 1).') ORDER BY `Time`');
    465         while($Row = $DbResult->fetch_array())
     465        while ($Row = $DbResult->fetch_array())
    466466        {
    467467          $Row['Time'] = MysqlDateTimeToTime($Row['Time']);
     
    469469        }
    470470
    471         if(count($Values) > 0)
     471        if (count($Values) > 0)
    472472        {
    473473          $Values = array_merge(
     
    477477
    478478          $StartIndex = 0;
    479           for($B = 0; $B < $BurstCount; $B++)
     479          for ($B = 0; $B < $BurstCount; $B++)
    480480          {
    481481            echo('.');
     
    484484
    485485            $EndIndex = $StartIndex;
    486             while($Values[$EndIndex]['Time'] < $EndTime3) $EndIndex = $EndIndex + 1;
     486            while ($Values[$EndIndex]['Time'] < $EndTime3) $EndIndex = $EndIndex + 1;
    487487            $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1);
    488             if(count($SubValues) > 2)
     488            if (count($SubValues) > 2)
    489489            {
    490490              $Point = $this->ComputeOneValue($StartTime3, $EndTime3, $SubValues, $Level);
     
    511511  {
    512512    $Result = $this->Database->select('Measure', 'Id');
    513     while($Row = $Result->fetch_array())
     513    while ($Row = $Result->fetch_array())
    514514    {
    515515      $Measure = new Measure();
Note: See TracChangeset for help on using the changeset viewer.