Changeset 92 for trunk/Modules/Measure/Measure.php
- Timestamp:
- Apr 7, 2020, 11:53:58 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Measure/Measure.php
r91 r92 83 83 function TimeSegment($Level) 84 84 { 85 return (pow($this->LevelReducing, $Level) * 60);85 return pow($this->LevelReducing, $Level) * 60; 86 86 } 87 87 88 88 function GetDataTable() 89 89 { 90 return ('data_'.$this->Data['Name']);90 return 'data_'.$this->Data['Name']; 91 91 } 92 92 93 93 function AlignTime($Time, $TimeSegment) 94 94 { 95 return (round(($Time - $this->ReferenceTime) / $TimeSegment) * $TimeSegment +96 $this->ReferenceTime );95 return round(($Time - $this->ReferenceTime) / $TimeSegment) * $TimeSegment + 96 $this->ReferenceTime; 97 97 } 98 98 … … 100 100 { 101 101 $Result = $this->Database->select('Measure', '*', '`Id`='.$Id); 102 if ($Result->num_rows > 0)102 if ($Result->num_rows > 0) 103 103 { 104 104 $this->Data = $Result->fetch_array(); 105 if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0; // non continuous105 if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0; // non continuous 106 106 else $this->Data['ContinuityEnabled'] = 2; // continuous graph 107 107 } else die('Měřená veličina '.$Id.' nenalezena.'); … … 112 112 $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '. 113 113 '(`Level`=0) ORDER BY `Time` DESC LIMIT 2'); 114 if ($Result->num_rows == 0) {114 if ($Result->num_rows == 0) { 115 115 // No measure value found. Simply insert new first value. 116 116 $this->Database->insert($this->Data['DataTable'], … … 118 118 'Measure' => $this->Data['Id'], 'Time' => TimeToMysqlDateTime($Time), 119 119 'Continuity' => 0)); 120 } else if ($Result->num_rows == 1) {120 } else if ($Result->num_rows == 1) { 121 121 // One value exists. Add second value. 122 122 $this->Database->insert($this->Data['DataTable'], … … 128 128 $LastValue = $Result->fetch_array(); 129 129 $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']) 131 131 { 132 132 // New value added too quickly. Need to wait for next measure period. … … 135 135 { 136 136 // 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']) { 138 138 // New value added near defined measure period inside tolerance. Keep continuity. 139 139 $Continuity = 1; … … 143 143 $Continuity = 0; 144 144 } 145 if (($LastValue['Avg'] == $NextToLastValue['Avg']) and ($LastValue['Avg'] == $Value) and145 if (($LastValue['Avg'] == $NextToLastValue['Avg']) and ($LastValue['Avg'] == $Value) and 146 146 ($LastValue['Continuity'] == 1) and ($Continuity == 1)) 147 147 { … … 165 165 function UpdateHigherLevels($Time) 166 166 { 167 for ($Level = 1; $Level <= $this->MaxLevel; $Level++)167 for ($Level = 1; $Level <= $this->MaxLevel; $Level++) 168 168 { 169 169 $TimeSegment = $this->TimeSegment($Level); 170 170 $EndTime = $this->AlignTime($Time, $TimeSegment); 171 //if ($EndTime < $Time) $EndTime = $EndTime + $TimeSegment;171 //if ($EndTime < $Time) $EndTime = $EndTime + $TimeSegment; 172 172 $StartTime = $EndTime - $TimeSegment; 173 173 … … 178 178 '(`Time` < "'.TimeToMysqlDateTime($EndTime).'") AND '. 179 179 '(`Measure`='.$this->Data['Id'].') AND (`Level`='.($Level - 1).') ORDER BY `Time`'); 180 while ($Row = $Result->fetch_array())180 while ($Row = $Result->fetch_array()) 181 181 { 182 182 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); … … 211 211 212 212 // Trim outside parts 213 foreach ($this->ValueTypes as $ValueType)213 foreach ($this->ValueTypes as $ValueType) 214 214 { 215 215 $Values[0][$ValueType] = Interpolation( … … 218 218 } 219 219 $Values[0]['Time'] = $LeftTime; 220 foreach ($this->ValueTypes as $ValueType)220 foreach ($this->ValueTypes as $ValueType) 221 221 { 222 222 $Values[count($Values) - 1][$ValueType] = Interpolation( … … 228 228 229 229 // Perform computation 230 foreach ($this->ValueTypes as $ValueType)230 foreach ($this->ValueTypes as $ValueType) 231 231 { 232 232 // 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') 236 236 { 237 237 if ($this->Data['Cumulative']) … … 240 240 } else 241 241 { 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) 244 244 { 245 245 $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I + 1]['Time'] - $Values[$I]['Time']) * … … 251 251 } 252 252 } 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']) 256 256 { 257 if (0 > $NewValue[$ValueType]) $NewValue[$ValueType] = 0;257 if (0 > $NewValue[$ValueType]) $NewValue[$ValueType] = 0; 258 258 } 259 259 else 260 260 { 261 if ($this->Differential == 0)261 if ($this->Differential == 0) 262 262 { 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]; 264 264 } else { 265 265 $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType]; 266 if ($Difference > $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;266 if ($Difference > $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference; 267 267 } 268 268 } 269 269 } 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']) 273 273 { 274 if (0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0;274 if (0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0; 275 275 } else { 276 if ($this->Differential == 0)276 if ($this->Differential == 0) 277 277 { 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]; 279 279 } else { 280 280 $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType]; 281 if ($Difference < $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;281 if ($Difference < $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference; 282 282 } 283 283 } … … 286 286 $NewValue[$ValueType] = $NewValue[$ValueType]; 287 287 } 288 //if (($RightTime - $LeftTime) > 0)289 if ($this->Data['Cumulative'] == 0)288 //if (($RightTime - $LeftTime) > 0) 289 if ($this->Data['Cumulative'] == 0) 290 290 { 291 291 $NewValue['Avg'] = $NewValue['Avg'] / ($RightTime - $LeftTime); 292 292 } 293 return ($NewValue);293 return $NewValue; 294 294 } 295 295 … … 299 299 $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '. 300 300 '(`Level`='.$Level.') ORDER BY `Time` LIMIT 1'); 301 if ($Result->num_rows > 0)301 if ($Result->num_rows > 0) 302 302 { 303 303 $Row = $Result->fetch_array(); … … 307 307 $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '. 308 308 '(`Level`='.$Level.') ORDER BY `Time` DESC LIMIT 1'); 309 if ($Result->num_rows > 0)309 if ($Result->num_rows > 0) 310 310 { 311 311 $Row = $Result->fetch_array(); … … 313 313 } else $AbsoluteRightTime = 0; 314 314 315 return (array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime));315 return array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime); 316 316 } 317 317 … … 323 323 '(`Time` > "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='. 324 324 $this->Data['Id'].') AND (`Level`='.$Level.') ORDER BY `Time` ASC LIMIT 1'); 325 if ($DbResult->num_rows > 0)325 if ($DbResult->num_rows > 0) 326 326 { 327 327 // Found one value, simply return it 328 328 $Row = $DbResult->fetch_array(); 329 329 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 330 return (array($Row));330 return array($Row); 331 331 } else 332 332 { … … 339 339 '(`Time` < "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.$this->Data['Id'].') '. 340 340 'AND (`Level`='.$Level.') ORDER BY `Time` DESC LIMIT 1'); 341 if ($DbResult->num_rows > 0)341 if ($DbResult->num_rows > 0) 342 342 { 343 343 $Row = $DbResult->fetch_array(); … … 345 345 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 346 346 } 347 return ($Result);347 return $Result; 348 348 } 349 349 } … … 356 356 '(`Time` < "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.$this->Data['Id'].') '. 357 357 'AND (`Level`='.$Level.') ORDER BY `Time` DESC LIMIT 1'); 358 if ($DbResult->num_rows > 0)358 if ($DbResult->num_rows > 0) 359 359 { 360 360 // Found one value, simply return it 361 361 $Row = $DbResult->fetch_array(); 362 362 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 363 return (array($Row));363 return array($Row); 364 364 } else { 365 365 // Not found any value. Calculate it … … 372 372 '(`Time` > "'.TimeToMysqlDateTime($Time).'") AND (`Measure`='.$this->Data['Id'].') '. 373 373 'AND (`Level`='.$Level.') ORDER BY `Time` ASC LIMIT 1'); 374 if ($DbResult->num_rows > 0)374 if ($DbResult->num_rows > 0) 375 375 { 376 376 $Row = $DbResult->fetch_array(); … … 378 378 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 379 379 } 380 return ($Result);380 return $Result; 381 381 } 382 382 } … … 386 386 //$AbsoluteTime = GetTimeRange($this->DataId); 387 387 388 // if (($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and388 // if (($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 389 389 // ($TimeTo > $AbsoluteLeftTime) and ($TimeTo < $AbsoluteRightTime)) 390 390 // { … … 397 397 '(`Measure`='.$this->Data['Id'].') AND (`Level`='.$Level.') ORDER BY `Time`'); 398 398 $Values = array(); 399 while ($Row = $Result->fetch_array())399 while ($Row = $Result->fetch_array()) 400 400 { 401 401 $Values[] = array('Time' => MysqlDateTimeToTime($Row['Time']), … … 406 406 407 407 $Points = array(); 408 if (count($Values) > 0)408 if (count($Values) > 0) 409 409 { 410 410 $Values = array_merge( … … 415 415 $StartIndex = 0; 416 416 $Points = array(); 417 for ($I = 0; $I < $this->DivisionCount; $I++)417 for ($I = 0; $I < $this->DivisionCount; $I++) 418 418 { 419 419 $TimeStart = $TimeFrom + (($TimeTo - $TimeFrom) / $this->DivisionCount) * $I; … … 421 421 422 422 $EndIndex = $StartIndex; 423 while ($Values[$EndIndex]['Time'] < $TimeEnd) $EndIndex = $EndIndex + 1;423 while ($Values[$EndIndex]['Time'] < $TimeEnd) $EndIndex = $EndIndex + 1; 424 424 $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1); 425 425 $Points[] = $this->ComputeOneValue($TimeStart, $TimeEnd, $SubValues, $Level); … … 427 427 } 428 428 } else $Points[] = array('Min' => 0, 'Avg' => 0, 'Max' => 0); 429 return ($Points);429 return $Points; 430 430 } 431 431 … … 433 433 { 434 434 echo('Velicina '.$this->Data['Name']."<br>\n"); 435 if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0; // non continuous435 if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0; // non continuous 436 436 else $this->Data['ContinuityEnabled'] = 2; // continuous graph 437 437 … … 443 443 echo("<br>\n"); 444 444 445 for ($Level = 1; $Level <= $this->MaxLevel; $Level++)445 for ($Level = 1; $Level <= $this->MaxLevel; $Level++) 446 446 { 447 447 echo('Uroven '.$Level."<br>\n"); … … 453 453 $Count = round(($EndTime - $StartTime) / $TimeSegment / $BurstCount); 454 454 echo('For 0 to '.$Count."<br>\n"); 455 for ($I = 0; $I <= $Count; $I++)455 for ($I = 0; $I <= $Count; $I++) 456 456 { 457 457 echo($I.' '); … … 463 463 TimeToMysqlDateTime($EndTime2).'") AND (`Measure`='.$this->Data['Id']. 464 464 ') AND (`Level`='.($Level - 1).') ORDER BY `Time`'); 465 while ($Row = $DbResult->fetch_array())465 while ($Row = $DbResult->fetch_array()) 466 466 { 467 467 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); … … 469 469 } 470 470 471 if (count($Values) > 0)471 if (count($Values) > 0) 472 472 { 473 473 $Values = array_merge( … … 477 477 478 478 $StartIndex = 0; 479 for ($B = 0; $B < $BurstCount; $B++)479 for ($B = 0; $B < $BurstCount; $B++) 480 480 { 481 481 echo('.'); … … 484 484 485 485 $EndIndex = $StartIndex; 486 while ($Values[$EndIndex]['Time'] < $EndTime3) $EndIndex = $EndIndex + 1;486 while ($Values[$EndIndex]['Time'] < $EndTime3) $EndIndex = $EndIndex + 1; 487 487 $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1); 488 if (count($SubValues) > 2)488 if (count($SubValues) > 2) 489 489 { 490 490 $Point = $this->ComputeOneValue($StartTime3, $EndTime3, $SubValues, $Level); … … 511 511 { 512 512 $Result = $this->Database->select('Measure', 'Id'); 513 while ($Row = $Result->fetch_array())513 while ($Row = $Result->fetch_array()) 514 514 { 515 515 $Measure = new Measure();
Note:
See TracChangeset
for help on using the changeset viewer.