- Timestamp:
- Jul 8, 2016, 11:11:07 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Version.php
r69 r71 6 6 // and system will need database update. 7 7 8 $Revision = 67;8 $Revision = 71; 9 9 $DatabaseRevision = 67; 10 $ReleaseTime = strtotime('2016-0 2-28');10 $ReleaseTime = strtotime('2016-06-30'); -
trunk/Graph.php
r69 r71 65 65 foreach($Points as $Index => $Item) 66 66 { 67 //$Points[$Index][' min'] = $Points[$Index]['min'] / $Measure['Divider'];68 //$Points[$Index][' avg'] = $Points[$Index]['avg'] / $Measure['Divider'];69 //$Points[$Index][' max'] = $Points[$Index]['max'] / $Measure['Divider'];70 if($Points[$Index][' avg'] > $MaxValue) $MaxValue = $Points[$Index]['avg'];71 if($Points[$Index][' avg'] < $MinValue) $MinValue = $Points[$Index]['avg'];72 if($Points[$Index][' max'] > $MaxValue) $MaxValue = $Points[$Index]['max'];73 if($Points[$Index][' min'] < $MinValue) $MinValue = $Points[$Index]['min'];74 $AvgValue = $AvgValue + $Points[$Index][' avg'];67 //$Points[$Index]['Min'] = $Points[$Index]['Min'] / $Measure['Divider']; 68 //$Points[$Index]['Avg'] = $Points[$Index]['Avg'] / $Measure['Divider']; 69 //$Points[$Index]['Max'] = $Points[$Index]['Max'] / $Measure['Divider']; 70 if($Points[$Index]['Avg'] > $MaxValue) $MaxValue = $Points[$Index]['Avg']; 71 if($Points[$Index]['Avg'] < $MinValue) $MinValue = $Points[$Index]['Avg']; 72 if($Points[$Index]['Max'] > $MaxValue) $MaxValue = $Points[$Index]['Max']; 73 if($Points[$Index]['Min'] < $MinValue) $MinValue = $Points[$Index]['Min']; 74 $AvgValue = $AvgValue + $Points[$Index]['Avg']; 75 75 } 76 76 //$MinValue = round($MinValue * $Measure['Divider']) / $Measure['Divider']; … … 87 87 { 88 88 $PointsMin[] = $Index * $Width / $Measure->DivisionCount; 89 $PointsMin[] = $Height - 1 - ($Points[$Index][' min'] - $MinValue) /89 $PointsMin[] = $Height - 1 - ($Points[$Index]['Min'] - $MinValue) / 90 90 ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 91 91 $PointsAvg[] = $Index * $Width / $Measure->DivisionCount; 92 $PointsAvg[] = $Height - 1 - ($Points[$Index][' avg'] - $MinValue) /92 $PointsAvg[] = $Height - 1 - ($Points[$Index]['Avg'] - $MinValue) / 93 93 ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 94 94 $PointsMax[] = $Index * $Width / $Measure->DivisionCount; 95 $PointsMax[] = $Height - 1 - ($Points[$Index][' max'] - $MinValue) /95 $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / 96 96 ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 97 97 } -
trunk/Modules/Measure/Measure.php
r70 r71 20 20 $this->System->RegisterPage('', 'PageMain'); 21 21 } 22 22 23 23 function DoInstall() 24 24 { … … 31 31 `Continuity` tinyint(1) NOT NULL default 0, 32 32 `Period` int(11) NOT NULL default 60, 33 `OldName` varchar(32) collate utf8_general_ci NOT NULL,34 33 `PermissionView` varchar(255) collate utf8_general_ci NOT NULL default "all", 35 34 `PermissionAdd` varchar(255) collate utf8_general_ci NOT NULL default "localhost.localdomain", … … 42 41 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 43 42 } 44 43 45 44 function DoUninstall() 46 45 { 47 46 $this->Database->query('DROP TABLE IF EXISTS `Measure`'); 48 47 } 49 48 50 49 function DoUpgrade() 51 50 { 52 51 53 52 } 54 53 } … … 71 70 { 72 71 $this->Id = 0; 73 $this->ValueTypes = array(' min', 'avg', 'max');72 $this->ValueTypes = array('Min', 'Avg', 'Max'); 74 73 $this->Database = &$Database; 75 74 $this->LevelReducing = 5; … … 79 78 $this->DivisionCount = 500; 80 79 $this->PeriodTolerance = 0.25; // 25% 80 $this->Data = array('Name' => '', 'Description' => '', 'Unit' => '', 'Info' => ''); 81 81 } 82 82 … … 86 86 } 87 87 88 function StatTableName($Level) 89 { 90 if($Level == 0) return('data'); 91 else return('data_cache'); 88 function GetDataTable() 89 { 90 return('data_'.$this->Data['Name']); 92 91 } 93 92 … … 109 108 } 110 109 111 function AddValue($Value) 112 { 113 $Time = time(); 114 110 function AddValue($Value, $Time) 111 { 115 112 $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '. 116 '(` level`=0) ORDER BY `time` DESC LIMIT 2');113 '(`Level`=0) ORDER BY `Time` DESC LIMIT 2'); 117 114 if($Result->num_rows == 0) { 118 115 // No measure value found. Simply insert new first value. 119 116 $this->Database->insert($this->Data['DataTable'], 120 array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0,121 'measure' => $this->Data['Id'], 'time' => TimeToMysqlDateTime($Time),122 'continuity' => 0));117 array('Min' => $Value, 'Avg' => $Value, 'Max' => $Value, 'Level' => 0, 118 'Measure' => $this->Data['Id'], 'Time' => TimeToMysqlDateTime($Time), 119 'Continuity' => 0)); 123 120 } else if($Result->num_rows == 1) { 124 121 // One value exists. Add second value. 125 122 $this->Database->insert($this->Data['DataTable'], 126 array(' min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0,127 ' measure' => $this->Data['Id'], 'time' => TimeToMysqlDateTime($Time),128 ' continuity' => 1));123 array('Min' => $Value, 'Avg' => $Value, 'Max' => $Value, 'Level' => 0, 124 'Measure' => $this->Data['Id'], 'Time' => TimeToMysqlDateTime($Time), 125 'Continuity' => 1)); 129 126 } else { 130 127 // Two values already exist in measure table 131 128 $LastValue = $Result->fetch_array(); 132 129 $NextToLastValue = $Result->fetch_array(); 133 if(($Time - MysqlDateTimeToTime($LastValue[' time'])) < (1 - $this->PeriodTolerance) * $this->Data['Period'])130 if(($Time - MysqlDateTimeToTime($LastValue['Time'])) < (1 - $this->PeriodTolerance) * $this->Data['Period']) 134 131 { 135 132 // New value added too quickly. Need to wait for next measure period. … … 138 135 { 139 136 // We are near defined period and can add new value. 140 if(($Time - MysqlDateTimeToTime($LastValue[' time'])) < (1 + $this->PeriodTolerance) * $this->Data['Period']) {137 if(($Time - MysqlDateTimeToTime($LastValue['Time'])) < (1 + $this->PeriodTolerance) * $this->Data['Period']) { 141 138 // New value added near defined measure period inside tolerance. Keep continuity. 142 139 $Continuity = 1; … … 146 143 $Continuity = 0; 147 144 } 148 if(($LastValue[' avg'] == $NextToLastValue['avg']) and ($LastValue['avg'] == $Value) and149 ($LastValue[' continuity'] == 1) and ($Continuity == 1))145 if(($LastValue['Avg'] == $NextToLastValue['Avg']) and ($LastValue['Avg'] == $Value) and 146 ($LastValue['Continuity'] == 1) and ($Continuity == 1)) 150 147 { 151 148 // New value is same as last value and continuity mode is enabled and 152 149 // continuity flag is present. Just shift forward time for last value. 153 $this->Database->update($this->Data['DataTable'], '(` time`="'.$LastValue['time'].'") AND '.154 '(` level`=0) AND (`measure`='.$this->Data['Id'].')', array('time' => TimeToMysqlDateTime($Time)));150 $this->Database->update($this->Data['DataTable'], '(`Time`="'.$LastValue['Time'].'") AND '. 151 '(`Level`=0) AND (`Measure`='.$this->Data['Id'].')', array('Time' => TimeToMysqlDateTime($Time))); 155 152 } else 156 153 { 157 154 // Last value is different or not with continuity flag. Need to add new value. 158 $this->Database->insert($this->Data['DataTable'], array('min' => $Value, 159 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $this->Data['Id'], 'time' => TimeToMysqlDateTime($Time), 160 'continuity' => $Continuity)); 161 } 162 } 163 } 164 165 // Update higher levels 155 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value, 156 'Avg' => $Value, 'max' => $Value, 'Level' => 0, 'Measure' => $this->Data['Id'], 157 'Time' => TimeToMysqlDateTime($Time), 158 'Continuity' => $Continuity)); 159 } 160 } 161 } 162 $this->UpdateHigherLevels($Time); 163 } 164 165 function UpdateHigherLevels($Time) 166 { 166 167 for($Level = 1; $Level <= $this->MaxLevel; $Level++) 167 168 { … … 173 174 // Load values in time range 174 175 $Values = array(); 175 $Result = $this->Database->select($this->Data['DataTable'], '*', '(` time` > "'.176 $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Time` > "'. 176 177 TimeToMysqlDateTime($StartTime).'") AND '. 177 '(` time` < "'.TimeToMysqlDateTime($EndTime).'") AND '.178 '(` measure`='.$this->Data['Id'].') AND (`level`='.($Level - 1).') ORDER BY `time`');178 '(`Time` < "'.TimeToMysqlDateTime($EndTime).'") AND '. 179 '(`Measure`='.$this->Data['Id'].') AND (`Level`='.($Level - 1).') ORDER BY `Time`'); 179 180 while($Row = $Result->fetch_array()) 180 181 { 181 $Row[' time'] = MysqlDateTimeToTime($Row['time']);182 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 182 183 $Values[] = $Row; 183 184 } … … 193 194 $Point = $this->ComputeOneValue($StartTime, $EndTime, $Values, $Level); 194 195 195 $this->Database->delete($this->Data['DataTable'], '(` time` > "'.TimeToMysqlDateTime($StartTime).'") AND196 (` time` < "'.TimeToMysqlDateTime($EndTime).'") AND (`measure`='.$this->Data['Id'].') '.197 'AND (` level`='.$Level.')');198 $Continuity = $Values[1][' continuity'];199 $this->Database->insert($this->Data['DataTable'], array(' level' => $Level,200 ' measure' => $this->Data['Id'], 'min' => $Point['min'],201 ' avg' => $Point['avg'], 'max' => $Point['max'], 'continuity' => $Continuity,202 ' time' => TimeToMysqlDateTime($StartTime + ($EndTime - $StartTime) / 2)));196 $this->Database->delete($this->Data['DataTable'], '(`Time` > "'.TimeToMysqlDateTime($StartTime).'") AND 197 (`Time` < "'.TimeToMysqlDateTime($EndTime).'") AND (`Measure`='.$this->Data['Id'].') '. 198 'AND (`Level`='.$Level.')'); 199 $Continuity = $Values[1]['Continuity']; 200 $this->Database->insert($this->Data['DataTable'], array('Level' => $Level, 201 'Measure' => $this->Data['Id'], 'Min' => $Point['Min'], 202 'Avg' => $Point['Avg'], 'Max' => $Point['Max'], 'Continuity' => $Continuity, 203 'Time' => TimeToMysqlDateTime($StartTime + ($EndTime - $StartTime) / 2))); 203 204 } 204 205 } … … 207 208 function ComputeOneValue($LeftTime, $RightTime, $Values, $Level) 208 209 { 209 $NewValue = array(' min' => +1000000000000000000, 'avg' => 0, 'max' => -1000000000000000000);210 $NewValue = array('Min' => +1000000000000000000, 'Avg' => 0, 'Max' => -1000000000000000000); 210 211 211 212 // Trim outside parts … … 213 214 { 214 215 $Values[0][$ValueType] = Interpolation( 215 NewPoint($Values[0][' time'], $Values[0][$ValueType]),216 NewPoint($Values[1][' time'], $Values[1][$ValueType]), $LeftTime);217 } 218 $Values[0][' time'] = $LeftTime;216 NewPoint($Values[0]['Time'], $Values[0][$ValueType]), 217 NewPoint($Values[1]['Time'], $Values[1][$ValueType]), $LeftTime); 218 } 219 $Values[0]['Time'] = $LeftTime; 219 220 foreach($this->ValueTypes as $ValueType) 220 221 { 221 222 $Values[count($Values) - 1][$ValueType] = Interpolation( 222 NewPoint($Values[count($Values) - 2][' time'], $Values[count($Values) - 2][$ValueType]),223 NewPoint($Values[count($Values) - 1][' time'], $Values[count($Values) - 1][$ValueType]),223 NewPoint($Values[count($Values) - 2]['Time'], $Values[count($Values) - 2][$ValueType]), 224 NewPoint($Values[count($Values) - 1]['Time'], $Values[count($Values) - 1][$ValueType]), 224 225 $RightTime); 225 226 } 226 $Values[count($Values) - 1][' time'] = $RightTime;227 $Values[count($Values) - 1]['Time'] = $RightTime; 227 228 228 229 // Perform computation … … 232 233 for($I = 0; $I < (count($Values) - 1); $I++) 233 234 { 234 if($ValueType == ' avg')235 { 236 if($Values[$I + 1][' continuity'] == $this->Data['ContinuityEnabled']);235 if($ValueType == 'Avg') 236 { 237 if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']); 237 238 else if($this->Differential == 0) 238 239 { 239 $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I + 1][' time'] - $Values[$I]['time']) *240 $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I + 1]['Time'] - $Values[$I]['Time']) * 240 241 (($Values[$I + 1][$ValueType] - $Values[$I][$ValueType]) / 2 + $Values[$I][$ValueType]); 241 242 } else { 242 $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I + 1][' time'] - $Values[$I]['time']) *243 $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I + 1]['Time'] - $Values[$I]['Time']) * 243 244 (($Values[$I + 1][$ValueType] - $Values[$I][$ValueType]) / 2); 244 245 } 245 246 } 246 else if($ValueType == ' max')247 { 248 if($Values[$I + 1][' continuity'] == $this->Data['ContinuityEnabled'])247 else if($ValueType == 'Max') 248 { 249 if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']) 249 250 { 250 251 if(0 > $NewValue[$ValueType]) $NewValue[$ValueType] = 0; … … 261 262 } 262 263 } 263 else if($ValueType == ' min')264 { 265 if($Values[$I + 1][' continuity'] == $this->Data['ContinuityEnabled'])264 else if($ValueType == 'Min') 265 { 266 if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']) 266 267 { 267 268 if(0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0; … … 282 283 if($this->Data['Cumulative'] == 0) 283 284 { 284 $NewValue[' avg'] = $NewValue['avg'] / ($RightTime - $LeftTime);285 $NewValue['Avg'] = $NewValue['Avg'] / ($RightTime - $LeftTime); 285 286 } 286 287 return($NewValue); … … 290 291 { 291 292 // Get first and last time 292 $Result = $this->Database->select($this->Data['DataTable'], '*', '(` measure`='.$this->Data['Id'].') AND '.293 '(` level`='.$Level.') ORDER BY `time` LIMIT 1');293 $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '. 294 '(`Level`='.$Level.') ORDER BY `Time` LIMIT 1'); 294 295 if($Result->num_rows > 0) 295 296 { … … 298 299 } else $AbsoluteLeftTime = 0; 299 300 300 $Result = $this->Database->select($this->Data['DataTable'], '*', '(` measure`='.$this->Data['Id'].') AND '.301 '(` level`='.$Level.') ORDER BY `time` DESC LIMIT 1');301 $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '. 302 '(`Level`='.$Level.') ORDER BY `Time` DESC LIMIT 1'); 302 303 if($Result->num_rows > 0) 303 304 { 304 305 $Row = $Result->fetch_array(); 305 $AbsoluteRightTime = MysqlDateTimeToTime($Row[' time']);306 $AbsoluteRightTime = MysqlDateTimeToTime($Row['Time']); 306 307 } else $AbsoluteRightTime = 0; 307 308 308 return(array(' left' => $AbsoluteLeftTime, 'right' => $AbsoluteRightTime));309 return(array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime)); 309 310 } 310 311 … … 314 315 $Result = array(); 315 316 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 316 '(` time` > "'.TimeToMysqlDateTime($Time).'") AND (`measure`='.317 $this->Data['Id'].') AND (` level`='.$Level.') ORDER BY `time` ASC LIMIT 1');317 '(`Time` > "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='. 318 $this->Data['Id'].') AND (`Level`='.$Level.') ORDER BY `Time` ASC LIMIT 1'); 318 319 if($DbResult->num_rows > 0) 319 320 { 320 321 // Found one value, simply return it 321 322 $Row = $DbResult->fetch_array(); 322 $Row[' time'] = MysqlDateTimeToTime($Row['time']);323 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 323 324 return(array($Row)); 324 325 } else … … 327 328 //$Time = $Values[count($Values) - 1]['time'] + 60; 328 329 //array_push($Values, array('time' => $Time, 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 329 $Result[] = array(' time' => ($Time + $this->TimeSegment($Level)), 'min' => 0,330 ' avg' => 0, 'max' => 0, 'continuity' => 0);330 $Result[] = array('Time' => ($Time + $this->TimeSegment($Level)), 'Min' => 0, 331 'Avg' => 0, 'Max' => 0, 'Continuity' => 0); 331 332 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 332 '(` time` < "'.TimeToMysqlDateTime($Time).'") AND (`measure`='.$this->Data['Id'].') '.333 'AND (` level`='.$Level.') ORDER BY `time` DESC LIMIT 1');333 '(`Time` < "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.$this->Data['Id'].') '. 334 'AND (`Level`='.$Level.') ORDER BY `Time` DESC LIMIT 1'); 334 335 if($DbResult->num_rows > 0) 335 336 { 336 337 $Row = $DbResult->fetch_array(); 337 array_unshift($Result, array(' time' => (MysqlDateTimeToTime($Row['time']) + 10),338 ' min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0));338 array_unshift($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) + 10), 339 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 339 340 } 340 341 return($Result); … … 347 348 $Result = array(); 348 349 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 349 '(` time` < "'.TimeToMysqlDateTime($Time).'") AND (`measure`='.$this->Data['Id'].') '.350 'AND (` level`='.$Level.') ORDER BY `time` DESC LIMIT 1');350 '(`Time` < "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.$this->Data['Id'].') '. 351 'AND (`Level`='.$Level.') ORDER BY `Time` DESC LIMIT 1'); 351 352 if($DbResult->num_rows > 0) 352 353 { 353 354 // Found one value, simply return it 354 355 $Row = $DbResult->fetch_array(); 355 $Row[' time'] = MysqlDateTimeToTime($Row['time']);356 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 356 357 return(array($Row)); 357 358 } else { … … 359 360 //$Time = $Values[0]['time'] - 60; 360 361 //array_unshift($Values, array('time' => $Time, 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 361 $Result[] = array(' time' => ($Time - $this->TimeSegment($Level)), 'min' => 0,362 ' avg' => 0, 'max' => 0, 'continuity' => 0);362 $Result[] = array('Time' => ($Time - $this->TimeSegment($Level)), 'Min' => 0, 363 'Avg' => 0, 'Max' => 0, 'Continuity' => 0); 363 364 364 365 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 365 '(` time` > "'.TimeToMysqlDateTime($Time).'") AND (`measure`='.$this->Data['Id'].') '.366 'AND (` level`='.$Level.') ORDER BY `time` ASC LIMIT 1');366 '(`Time` > "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.$this->Data['Id'].') '. 367 'AND (`Level`='.$Level.') ORDER BY `Time` ASC LIMIT 1'); 367 368 if($DbResult->num_rows > 0) 368 369 { 369 370 $Row = $DbResult->fetch_array(); 370 array_push($Result, array(' time' => (MysqlDateTimeToTime($Row['time']) - 10),371 ' min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0));371 array_push($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) - 10), 372 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 372 373 } 373 374 return($Result); … … 384 385 385 386 // Load values in time range 386 $Result = $this->Database->select($this->Data['DataTable'], '` time`, `min`, '.387 '` avg`, `max`, `continuity`',388 '(` time` > "'.TimeToMysqlDateTime($TimeFrom).'") AND '.389 '(` time` < "'.TimeToMysqlDateTime($TimeTo).'") AND '.390 '(` measure`='.$this->Data['Id'].') AND (`level`='.$Level.') ORDER BY `time`');387 $Result = $this->Database->select($this->Data['DataTable'], '`Time`, `Min`, '. 388 '`Avg`, `Max`, `Continuity`', 389 '(`Time` > "'.TimeToMysqlDateTime($TimeFrom).'") AND '. 390 '(`Time` < "'.TimeToMysqlDateTime($TimeTo).'") AND '. 391 '(`Measure`='.$this->Data['Id'].') AND (`Level`='.$Level.') ORDER BY `Time`'); 391 392 $Values = array(); 392 393 while($Row = $Result->fetch_array()) 393 394 { 394 $Values[] = array(' time' => MysqlDateTimeToTime($Row['time']),395 ' min' => $Row['min'], 'avg' => $Row['avg'], 'max' => $Row['max'],396 ' continuity' => $Row['continuity']);395 $Values[] = array('Time' => MysqlDateTimeToTime($Row['Time']), 396 'Min' => $Row['Min'], 'Avg' => $Row['Avg'], 'Max' => $Row['Max'], 397 'Continuity' => $Row['Continuity']); 397 398 } 398 399 // array_pop($Values); … … 414 415 415 416 $EndIndex = $StartIndex; 416 while($Values[$EndIndex][' time'] < $TimeEnd) $EndIndex = $EndIndex + 1;417 while($Values[$EndIndex]['Time'] < $TimeEnd) $EndIndex = $EndIndex + 1; 417 418 $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1); 418 419 $Points[] = $this->ComputeOneValue($TimeStart, $TimeEnd, $SubValues, $Level); 419 420 $StartIndex = $EndIndex - 1; 420 421 } 421 } else $Points[] = array(' min' => 0, 'avg' => 0, 'max' => 0);422 } else $Points[] = array('Min' => 0, 'Avg' => 0, 'Max' => 0); 422 423 return($Points); 423 424 } … … 430 431 431 432 // Clear previous items 432 $DbResult = $this->Database->select($this->Data['DataTable'], 'COUNT(*)', '(` level`>0) AND (`measure`='.$this->Data['Id'].')');433 $DbResult = $this->Database->select($this->Data['DataTable'], 'COUNT(*)', '(`Level`>0) AND (`Measure`='.$this->Data['Id'].')'); 433 434 $Row = $DbResult->fetch_array(); 434 435 echo("Mazu starou cache (".$Row[0]." polozek)..."); 435 $this->Database->delete($this->Data['DataTable'], '(` level`>0) AND (`measure`='.$this->Data['Id'].')');436 $this->Database->delete($this->Data['DataTable'], '(`Level`>0) AND (`Measure`='.$this->Data['Id'].')'); 436 437 echo("<br>\n"); 437 438 … … 441 442 $TimeRange = $this->GetTimeRange($Level - 1); 442 443 $TimeSegment = $this->TimeSegment($Level); 443 $StartTime = $this->AlignTime($TimeRange[' left'], $TimeSegment) - $TimeSegment;444 $EndTime = $this->AlignTime($TimeRange[' right'], $TimeSegment);444 $StartTime = $this->AlignTime($TimeRange['Left'], $TimeSegment) - $TimeSegment; 445 $EndTime = $this->AlignTime($TimeRange['Right'], $TimeSegment); 445 446 $BurstCount = 500; 446 447 echo('For 0 to '.round(($EndTime - $StartTime) / $TimeSegment / $BurstCount)."<br>\n"); … … 451 452 $EndTime2 = $StartTime + ($I + 1) * $BurstCount * $TimeSegment; 452 453 $Values = array(); 453 $DbResult = $this->Database->select($this->Data['DataTable'], '*', '(`time` > "'.TimeToMysqlDateTime($StartTime2).'") AND (`time` < "'. 454 TimeToMysqlDateTime($EndTime2).'") AND (`measure`='.$this->Data['Id'].') AND (`level`='.($Level - 1).') ORDER BY `time`'); 454 $DbResult = $this->Database->select($this->Data['DataTable'], '*', '(`Time` > "'. 455 TimeToMysqlDateTime($StartTime2).'") AND (`Time` < "'. 456 TimeToMysqlDateTime($EndTime2).'") AND (`Measure`='.$this->Data['Id']. 457 ') AND (`Level`='.($Level - 1).') ORDER BY `Time`'); 455 458 while($Row = $DbResult->fetch_array()) 456 459 { 457 $Row[' time'] = MysqlDateTimeToTime($Row['time']);460 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 458 461 $Values[] = $Row; 459 462 } … … 474 477 475 478 $EndIndex = $StartIndex; 476 while($Values[$EndIndex][' time'] < $EndTime3) $EndIndex = $EndIndex + 1;479 while($Values[$EndIndex]['Time'] < $EndTime3) $EndIndex = $EndIndex + 1; 477 480 $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1); 478 481 if(count($SubValues) > 2) 479 482 { 480 483 $Point = $this->ComputeOneValue($StartTime3, $EndTime3, $SubValues, $Level); 481 $Continuity = $SubValues[1][' continuity'];482 $this->Database->insert($this->Data['DataTable'], array(' level' => $Level, 'measure' => $this->Data['Id'],483 ' min' => $Point['min'], 'avg' => $Point['avg'], 'max' => $Point['max'],484 ' continuity' => $Continuity, 'time' => TimeToMysqlDateTime($StartTime3 + ($EndTime3 - $StartTime3) / 2)));484 $Continuity = $SubValues[1]['Continuity']; 485 $this->Database->insert($this->Data['DataTable'], array('Level' => $Level, 'Measure' => $this->Data['Id'], 486 'Min' => $Point['Min'], 'Avg' => $Point['Avg'], 'Max' => $Point['Max'], 487 'Continuity' => $Continuity, 'Time' => TimeToMysqlDateTime($StartTime3 + ($EndTime3 - $StartTime3) / 2))); 485 488 } 486 489 $StartIndex = $EndIndex - 1; … … 500 503 function RebuildAllMeasuresCache() 501 504 { 502 $Result = $this->Database->select(' measure', 'Id');505 $Result = $this->Database->select('Measure', 'Id'); 503 506 while($Row = $Result->fetch_array()) 504 507 { … … 509 512 } 510 513 } 511 512 function InitMeasureDataTable() 513 { 514 $this->Database->query('CREATE TABLE `data_'.$this->Data['Name'].'` ( 515 `Time` TIMESTAMP NOT NULL , 516 `Avg` '.$this->Data['DataType'].' NOT NULL , 517 `Continuity` BOOL NOT NULL 518 ) ENGINE = MYISAM ;'); 519 520 $this->Database->query('CREATE TABLE `data_'.$this->Data['Name'].'_cache` ( 514 } 515 516 class MeasureDataType 517 { 518 const Int8 = 0; 519 const Int16 = 1; 520 const Int32 = 2; 521 const Int64 = 3; 522 const Float = 4; 523 const Double = 5; 524 } 525 526 class MeasureList extends Model 527 { 528 function AddItem(Measure $Measure) 529 { 530 $this->Database->insert('Measure', array( 531 'Name' => $Measure->Data['Name'], 532 'Description' => $Measure->Data['Description'], 533 'Unit' => $Measure->Data['Unit'], 534 'Info' => $Measure->Data['Info'], 535 'DataType' => $Measure->Data['DataType'], 536 'DataTable' => $Measure->GetDataTable(), 537 )); 538 $Measure->Data['Id'] = $this->Database->insert_id; 539 540 $this->Database->query('CREATE TABLE `'.$Measure->GetDataTable().'` ( 521 541 `Time` TIMESTAMP NOT NULL , 542 `Measure` INT NOT NULL , 522 543 `Level` TINYINT NOT NULL , 523 `Min` '.$ this->Data['DataType'].' NOT NULL ,524 `Avg` '.$ this->Data['DataType'].' NOT NULL ,525 `Max` '.$ this->Data['DataType'].' NOT NULL ,544 `Min` '.$Measure->Data['DataType'].' NOT NULL , 545 `Avg` '.$Measure->Data['DataType'].' NOT NULL , 546 `Max` '.$Measure->Data['DataType'].' NOT NULL , 526 547 `Continuity` BOOL NOT NULL 527 ) ENGINE = MYISAM ;'); 528 } 548 ) ENGINE = InnoDb ;'); 549 } 550 551 function RemoveItem(Measure $Measure) 552 { 553 $this->Database->delete('Measure', '`Id`='.$Measure->Data['Id']); 554 $this->Database->query('DROP TABLE `'.$Measure->GetDataTable().'`'); 555 } 556 529 557 } -
trunk/add.php
r69 r71 12 12 $MeasureId = addslashes($_GET['MeasureId']); 13 13 $Value = addslashes($_GET['Value']); 14 if (array_key_exists('Time', $_GET)) $Time = $_GET['Time'] * 1; 15 else $Time = time(); 14 16 $Measure = new Measure($Core->Database); 15 17 $Measure->Load($MeasureId); … … 17 19 if(($HostName == $Measure->Data['PermissionAdd']) or ($_SERVER['REMOTE_ADDR'] == gethostbyname($Measure->Data['PermissionAdd']))) 18 20 { 19 $Measure->AddValue($Value );21 $Measure->AddValue($Value, $Time); 20 22 echo('Hodnota '.$Value.' uložena'); 21 23 } else echo('Nemáte oprávnění k aktualizaci zadané veličiny!<br>Vaše adresa: '.$HostName.'('.$_SERVER['REMOTE_ADDR'].')');
Note:
See TracChangeset
for help on using the changeset viewer.