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

Legend:

Unmodified
Added
Removed
  • 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']);
Note: See TracChangeset for help on using the changeset viewer.