Ignore:
Timestamp:
Nov 24, 2009, 6:01:08 PM (14 years ago)
Author:
george
Message:
  • Přidáno: Kontrolér pro přidávání nových hodnot.
  • Opraveno: Informace o použité jednotce načítat z tabulky MeasureMethod.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Model/Measure.php

    r43 r45  
    1414  var $ValueTypes = array('Min', 'Avg', 'Max');
    1515 
    16   function Add($Value)
    17   {
    18     if(gethostbyaddr($_SERVER['REMOTE_ADDR']) == $this->Data['PermissionAdd'])
    19     {
    20       $this->AddValue(array('Min' => $Value, 'Avg' => $Value, 'Max' => $Value));
    21       $Output = 'Hodnota '.$Value.' uložena';
    22     } else throw new Exception('Access denied');
    23   }
    24  
    2516  function Load($Id)
    2617  {
     
    5748    //echo(TimeToMysqlDateTime($Time).'|'.$Level."\n");
    5849
    59     $Result = $Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2');
     50    $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2');
    6051    //echo($Database->LastQuery."\n");
    6152    if($Result->num_rows == 0)
    6253    {
    63        $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'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => 0));
    6455       //echo($Database->LastQuery."\n");
    6556    } else if($Result->num_rows == 1)
    6657    {
    67       $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));
     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));
    6859      //echo($Database->LastQuery."\n");
    6960    } else
     
    7768      } else
    7869      {
    79         if(($Time - MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1;
     70        if(($Time - $this->Database->MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1;
    8071          else $Continuity = 0;
    8172        echo('('.$LastValue['Avg'].'=='.$NextToLastValue['Avg'].') and ('.$LastValue['Avg'].' == '.$Value.') and ('.$LastValue['Continuity'].' == 1) and ('.$Continuity.' == 1))'."\n");
     
    8374        {
    8475          $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$Measure['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time)));
    85           echo($this->Database->LastQuery."\n");
     76          //echo($this->Database->LastQuery."\n");
    8677        } else
    8778        {
    88           $Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $Measure['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => $Continuity));
    89           echo($this->Database->LastQuery."\n");
     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));
    9080        }
    9181      } 
    9282
    9383      // Update next level
    94       if($Level < $MaxLevel)
     84      if($Level < $this->MaxLevel)
    9585      {
    9686        $Level = $Level + 1;
     
    120110          // Load subsidary values
    121111          print_r($Values);
    122           $Values = array_merge($this->LoadLeftSideValue($Level - 1, $this->Data, $StartTime), $Values, $this->LoadRightSideValue($Level - 1, $Measure, $EndTime));
     112          $Values = array_merge($this->LoadLeftSideValue($Level - 1, $this->Data, $StartTime), $Values, $this->LoadRightSideValue($Level - 1, $EndTime));
    123113          print_r($Values);
    124114
    125           $Point = $this->ComputeOneValue($StartTime, $EndTime, $Values, $this->Data, $Level);
     115          $Point = $this->ComputeOneValue($StartTime, $EndTime, $Values, $Level);
    126116        //print_r($Point);
    127117
    128118          $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);
    129119          $this->Data['Period'] = $TimeSegment;
    130           $this->AddValue($this->Data, 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'], 'Max' => $Point['Max']), $Level, $StartTime + ($EndTime - $StartTime) / 2);
    131121        }
    132122      }
     
    288278      //$Time = $Values[0]['Time'] - 60;
    289279      //array_unshift($Values, array('Time' => $Time, 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));
     280      if($this->Debug) echo($this->TimeSegment($this->Data['Period'], $Level));
    290281      $Result[] = array('Time' => ($Time - $this->TimeSegment($this->Data['Period'], $Level)), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0);
    291282
     
    350341
    351342        $EndIndex = $StartIndex;
    352         //while(($Values[$EndIndex]['Time'] < $TimeEnd) and ($EndIndex < count($Values))) $EndIndex = $EndIndex + 1;
    353         while(($Values[$EndIndex]['Time'] < $TimeEnd)) $EndIndex = $EndIndex + 1;
     343        while(($Values[$EndIndex]['Time'] < $TimeEnd) and ($EndIndex < count($Values))) $EndIndex = $EndIndex + 1;
     344        //while(($Values[$EndIndex]['Time'] < $TimeEnd)) $EndIndex = $EndIndex + 1;
    354345        $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1);
    355346        //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br>');
Note: See TracChangeset for help on using the changeset viewer.