Changeset 45 for trunk/Application/Model/Measure.php
- Timestamp:
- Nov 24, 2009, 6:01:08 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Model/Measure.php
r43 r45 14 14 var $ValueTypes = array('Min', 'Avg', 'Max'); 15 15 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 25 16 function Load($Id) 26 17 { … … 57 48 //echo(TimeToMysqlDateTime($Time).'|'.$Level."\n"); 58 49 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'); 60 51 //echo($Database->LastQuery."\n"); 61 52 if($Result->num_rows == 0) 62 53 { 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)); 64 55 //echo($Database->LastQuery."\n"); 65 56 } else if($Result->num_rows == 1) 66 57 { 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)); 68 59 //echo($Database->LastQuery."\n"); 69 60 } else … … 77 68 } else 78 69 { 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; 80 71 else $Continuity = 0; 81 72 echo('('.$LastValue['Avg'].'=='.$NextToLastValue['Avg'].') and ('.$LastValue['Avg'].' == '.$Value.') and ('.$LastValue['Continuity'].' == 1) and ('.$Continuity.' == 1))'."\n"); … … 83 74 { 84 75 $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"); 86 77 } else 87 78 { 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)); 90 80 } 91 81 } 92 82 93 83 // Update next level 94 if($Level < $ MaxLevel)84 if($Level < $this->MaxLevel) 95 85 { 96 86 $Level = $Level + 1; … … 120 110 // Load subsidary values 121 111 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)); 123 113 print_r($Values); 124 114 125 $Point = $this->ComputeOneValue($StartTime, $EndTime, $Values, $ this->Data, $Level);115 $Point = $this->ComputeOneValue($StartTime, $EndTime, $Values, $Level); 126 116 //print_r($Point); 127 117 128 118 $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); 129 119 $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); 131 121 } 132 122 } … … 288 278 //$Time = $Values[0]['Time'] - 60; 289 279 //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)); 290 281 $Result[] = array('Time' => ($Time - $this->TimeSegment($this->Data['Period'], $Level)), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0); 291 282 … … 350 341 351 342 $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; 354 345 $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1); 355 346 //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br>');
Note:
See TracChangeset
for help on using the changeset viewer.