Changeset 873 for trunk/Modules/TimeMeasure/Measure.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/TimeMeasure/Measure.php
r790 r873 15 15 { 16 16 $Result = $this->Database->select('Measure', '*', 'Id='.$Id); 17 if ($Result->num_rows > 0)17 if ($Result->num_rows > 0) 18 18 { 19 19 $this->Data = $Result->fetch_assoc(); 20 if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0; // non continuous20 if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0; // non continuous 21 21 else $this->Data['ContinuityEnabled'] = 2; // continuous graph 22 22 } else throw new Exception('Measure not found'); … … 25 25 function TimeSegment($Base, $Level) 26 26 { 27 return (pow($this->LevelReducing, $Level) * $Base);27 return (pow($this->LevelReducing, $Level) * $Base); 28 28 } 29 29 30 30 function StatTableName($Level) 31 31 { 32 if ($Level == 0) return('Data');33 else return ('DataCache');32 if ($Level == 0) return ('Data'); 33 else return ('DataCache'); 34 34 } 35 35 36 36 function AlignTime($Time, $TimeSegment) 37 37 { 38 return (round(($Time - $this->ReferenceTime) / $TimeSegment) * $TimeSegment + $this->ReferenceTime);38 return (round(($Time - $this->ReferenceTime) / $TimeSegment) * $TimeSegment + $this->ReferenceTime); 39 39 } 40 40 41 41 function AddValue($Value = array('Min' => 0, 'Avg' => 0, 'Max' => 0), $Level = 0, $Time = 0) 42 42 { 43 if ($Time == 0) $Time = time();43 if ($Time == 0) $Time = time(); 44 44 45 45 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='. 46 46 $this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2'); 47 if ($Result->num_rows == 0)47 if ($Result->num_rows == 0) 48 48 { 49 49 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 50 50 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 51 51 'Measure' => $this->Data['Id'], 'Time' => TimeToMysqlDateTime($Time), 'Continuity' => 0)); 52 } else if ($Result->num_rows == 1)52 } else if ($Result->num_rows == 1) 53 53 { 54 54 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], … … 59 59 $LastValue = $Result->fetch_assoc(); 60 60 $NextToLastValue = $Result->fetch_assoc(); 61 if ((($Time - MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0))61 if ((($Time - MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0)) 62 62 { 63 63 echo('Too short period. Minimal period is '.(0.75 * $this->Data['Period'])." seconds\n"); 64 64 } else 65 65 { 66 if (($Time - MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1;66 if (($Time - MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1; 67 67 else $Continuity = 0; 68 if (($LastValue['Min'] == $NextToLastValue['Min']) and ($LastValue['Min'] ==68 if (($LastValue['Min'] == $NextToLastValue['Min']) and ($LastValue['Min'] == 69 69 $Value['Min']) and ($LastValue['Avg'] == $NextToLastValue['Avg']) and 70 70 ($LastValue['Avg'] == $Value['Avg']) and ($LastValue['Max'] == $NextToLastValue['Max']) … … 82 82 83 83 // Update next level 84 if ($Level < $this->MaxLevel)84 if ($Level < $this->MaxLevel) 85 85 { 86 86 $Level = $Level + 1; 87 87 $TimeSegment = $this->TimeSegment($this->Data['Period'], 1); 88 88 $EndTime = $this->AlignTime($Time, $TimeSegment); 89 //if ($EndTime < $Time) $EndTime = $EndTime + $TimeSegment;89 //if ($EndTime < $Time) $EndTime = $EndTime + $TimeSegment; 90 90 $StartTime = $EndTime - $TimeSegment; 91 91 … … 96 96 TimeToMysqlDateTime($StartTime).'") AND (Time < "'.TimeToMysqlDateTime($EndTime). 97 97 '") AND (Measure='.$this->Data['Id'].') AND (Level='.($Level - 1).') ORDER BY Time'); 98 while ($Row = $Result->fetch_assoc())98 while ($Row = $Result->fetch_assoc()) 99 99 { 100 100 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 101 101 $Values[] = $Row; 102 102 } 103 //if (count($Values) > 2)103 //if (count($Values) > 2) 104 104 { 105 105 //array_pop($Values); … … 124 124 { 125 125 $Y = ($Y2 - $Y1) / ($X2 - $X1) * ($X - $X1) + $Y1; 126 return ($Y);126 return ($Y); 127 127 } 128 128 … … 132 132 133 133 // Trim outside parts 134 foreach ($this->ValueTypes as $ValueType)134 foreach ($this->ValueTypes as $ValueType) 135 135 { 136 136 $Values[0][$ValueType] = $this->Interpolation($Values[0]['Time'], $Values[0][$ValueType], $Values[1]['Time'], $Values[1][$ValueType], $LeftTime); 137 137 } 138 138 $Values[0]['Time'] = $LeftTime; 139 foreach ($this->ValueTypes as $ValueType)139 foreach ($this->ValueTypes as $ValueType) 140 140 { 141 141 $Values[count($Values) - 1][$ValueType] = $this->Interpolation($Values[count($Values) - 2]['Time'], $Values[count($Values) - 2][$ValueType], … … 145 145 146 146 // Perform computation 147 foreach ($this->ValueTypes as $ValueType)147 foreach ($this->ValueTypes as $ValueType) 148 148 { 149 149 // Compute new value 150 for ($I = 0; $I < (count($Values) - 1); $I++)151 { 152 if ($ValueType == 'Avg')153 { 154 if ($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']);155 else if ($this->Differential == 0)150 for ($I = 0; $I < (count($Values) - 1); $I++) 151 { 152 if ($ValueType == 'Avg') 153 { 154 if ($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']); 155 else if ($this->Differential == 0) 156 156 { 157 157 $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I + 1]['Time'] - $Values[$I]['Time']) * … … 163 163 } 164 164 } 165 else if ($ValueType == 'Max')166 { 167 if ($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled'])168 { 169 if (0 > $NewValue[$ValueType]) $NewValue[$ValueType] = 0;165 else if ($ValueType == 'Max') 166 { 167 if ($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']) 168 { 169 if (0 > $NewValue[$ValueType]) $NewValue[$ValueType] = 0; 170 170 } else 171 171 { 172 if ($this->Differential == 0)172 if ($this->Differential == 0) 173 173 { 174 if ($Values[$I + 1][$ValueType] > $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType];174 if ($Values[$I + 1][$ValueType] > $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType]; 175 175 } else { 176 176 $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType]; 177 if ($Difference > $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;177 if ($Difference > $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference; 178 178 } 179 179 } 180 180 } 181 else if ($ValueType == 'Min')182 { 183 if ($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled'])184 { 185 if (0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0;181 else if ($ValueType == 'Min') 182 { 183 if ($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']) 184 { 185 if (0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0; 186 186 } else 187 187 { 188 if ($this->Differential == 0)188 if ($this->Differential == 0) 189 189 { 190 if ($Values[$I + 1][$ValueType] < $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType];190 if ($Values[$I + 1][$ValueType] < $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType]; 191 191 } else { 192 192 $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType]; 193 if ($Difference < $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference;193 if ($Difference < $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference; 194 194 } 195 195 } … … 198 198 $NewValue[$ValueType] = $NewValue[$ValueType]; 199 199 } 200 //if (($RightTime - $LeftTime) > 0)201 if ($this->Data['Cumulative'] == 0)200 //if (($RightTime - $LeftTime) > 0) 201 if ($this->Data['Cumulative'] == 0) 202 202 { 203 203 $NewValue['Avg'] = $NewValue['Avg'] / ($RightTime - $LeftTime); 204 204 } 205 return ($NewValue);205 return ($NewValue); 206 206 } 207 207 … … 210 210 // Get first and last time 211 211 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time LIMIT 1'); 212 if ($Result->num_rows > 0)212 if ($Result->num_rows > 0) 213 213 { 214 214 $Row = $Result->fetch_assoc(); … … 217 217 218 218 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1'); 219 if ($Result->num_rows > 0)219 if ($Result->num_rows > 0) 220 220 { 221 221 $Row = $Result->fetch_assoc(); … … 223 223 } else $AbsoluteRightTime = 0; 224 224 225 if ($this->Debug)225 if ($this->Debug) 226 226 { 227 227 echo('AbsoluteLeftTime: '.$AbsoluteLeftTime.'('.TimeToMysqlDateTime($AbsoluteLeftTime).')<br>'); 228 228 echo('AbsoluteRightTime: '.$AbsoluteRightTime.'('.TimeToMysqlDateTime($AbsoluteRightTime).')<br>'); 229 229 } 230 return (array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime));230 return (array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime)); 231 231 } 232 232 … … 235 235 $Result = array(); 236 236 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1'); 237 if ($DbResult->num_rows > 0)237 if ($DbResult->num_rows > 0) 238 238 { 239 239 $Row = $DbResult->fetch_assoc(); 240 240 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 241 return (array($Row));241 return (array($Row)); 242 242 } else 243 243 { … … 247 247 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'. 248 248 TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1'); 249 if ($DbResult->num_rows > 0)249 if ($DbResult->num_rows > 0) 250 250 { 251 251 $Row = $DbResult->fetch_assoc(); 252 252 array_unshift($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) + 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 253 253 } 254 // if ($Debug) print_r($Result);255 return ($Result);254 // if ($Debug) print_r($Result); 255 return ($Result); 256 256 } 257 257 } … … 262 262 $DbResult = $this->Database->select($this->Data['DataTable'], '*', '(Time < "'. 263 263 TimeToMysqlDateTime($Time).'") AND (Measure='.$this->Data['Id'].') AND (Level='.$Level.') ORDER BY Time DESC LIMIT 1'); 264 if ($DbResult->num_rows > 0)264 if ($DbResult->num_rows > 0) 265 265 { 266 266 $Row = $DbResult->fetch_assoc(); 267 267 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 268 return (array($Row));268 return (array($Row)); 269 269 } else 270 270 { 271 271 //$Time = $Values[0]['Time'] - 60; 272 272 //array_unshift($Values, array('Time' => $Time, 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 273 if ($this->Debug) echo($this->TimeSegment($this->Data['Period'], $Level));273 if ($this->Debug) echo($this->TimeSegment($this->Data['Period'], $Level)); 274 274 $Result[] = array('Time' => ($Time - $this->TimeSegment($this->Data['Period'], $Level)), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0); 275 275 276 276 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1'); 277 if ($DbResult->num_rows > 0)277 if ($DbResult->num_rows > 0) 278 278 { 279 279 $Row = $DbResult->fetch_assoc(); 280 280 array_push($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) - 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 281 281 } 282 return ($Result);282 return ($Result); 283 283 } 284 284 } … … 286 286 function GetValues($TimeFrom, $TimeTo, $Level) 287 287 { 288 if ($this->Debug) echo('TimeFrom: '.$TimeFrom.'('.TimeToMysqlDateTime($TimeFrom).')<br>');289 if ($this->Debug) echo('TimeTo: '.$TimeTo.'('.TimeToMysqlDateTime($TimeTo).')<br>');288 if ($this->Debug) echo('TimeFrom: '.$TimeFrom.'('.TimeToMysqlDateTime($TimeFrom).')<br>'); 289 if ($this->Debug) echo('TimeTo: '.$TimeTo.'('.TimeToMysqlDateTime($TimeTo).')<br>'); 290 290 291 291 //$AbsoluteTime = GetTimeRange($MeasureId); 292 292 293 // if (($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and293 // if (($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 294 294 // ($TimeTo > $AbsoluteLeftTime) and ($TimeTo < $AbsoluteRightTime)) 295 295 // { … … 304 304 // echo(DB_NumRows()); 305 305 // $III = 0; 306 while ($Row = $Result->fetch_assoc())306 while ($Row = $Result->fetch_assoc()) 307 307 { 308 308 // echo($III.' '.$Row['Time'].' '.memory_get_usage().','); … … 314 314 // echo('abc'); 315 315 // die(); 316 if ($this->Debug) echo('Item count: '.count($Values));316 if ($this->Debug) echo('Item count: '.count($Values)); 317 317 318 318 $Points = array(); 319 if (count($Values) > 0)319 if (count($Values) > 0) 320 320 { 321 321 $Values = array_merge($this->LoadLeftSideValue($Level, $TimeFrom), $Values, $this->LoadRightSideValue($Level, $TimeTo)); 322 322 $StartIndex = 0; 323 323 $Points = array(); 324 if ($this->Debug) print_r($Values);325 for ($I = 0; $I < $this->DivisionCount; $I++)324 if ($this->Debug) print_r($Values); 325 for ($I = 0; $I < $this->DivisionCount; $I++) 326 326 { 327 327 $TimeStart = $TimeFrom + (($TimeTo - $TimeFrom) / $this->DivisionCount) * $I; 328 328 $TimeEnd = $TimeFrom + (($TimeTo - $TimeFrom) / $this->DivisionCount) * ($I + 1); 329 if ($this->Debug) echo('TimeEnd '.$I.': '.$TimeEnd.'('.TimeToMysqlDateTime($TimeEnd).')<br>');329 if ($this->Debug) echo('TimeEnd '.$I.': '.$TimeEnd.'('.TimeToMysqlDateTime($TimeEnd).')<br>'); 330 330 331 331 $EndIndex = $StartIndex; 332 while (($Values[$EndIndex]['Time'] < $TimeEnd) and ($EndIndex < count($Values))) $EndIndex = $EndIndex + 1;333 //while (($Values[$EndIndex]['Time'] < $TimeEnd)) $EndIndex = $EndIndex + 1;332 while (($Values[$EndIndex]['Time'] < $TimeEnd) and ($EndIndex < count($Values))) $EndIndex = $EndIndex + 1; 333 //while (($Values[$EndIndex]['Time'] < $TimeEnd)) $EndIndex = $EndIndex + 1; 334 334 $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1); 335 335 $Points[] = $this->ComputeOneValue($TimeStart, $TimeEnd, $SubValues, $Level); 336 336 $StartIndex = $EndIndex - 1; 337 337 } 338 if ($this->Debug) print_r($Points);338 if ($this->Debug) print_r($Points); 339 339 } else $Points[] = array('Min' => 0, 'Avg' => 0, 'Max' => 0); 340 return ($Points);340 return ($Points); 341 341 } 342 342 … … 344 344 { 345 345 echo('Veličina '.$this->Data['Name']."<br>\n"); 346 if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0; // non continuous346 if ($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0; // non continuous 347 347 else $this->Data['ContinuityEnabled'] = 2; // continuous graph 348 348 … … 354 354 echo("<br>\n"); 355 355 356 for ($Level = 1; $Level <= $this->MaxLevel; $Level++)356 for ($Level = 1; $Level <= $this->MaxLevel; $Level++) 357 357 { 358 358 echo('Uroven '.$Level."<br>\n"); … … 363 363 $BurstCount = 500; 364 364 echo('For 0 to '.round(($EndTime - $StartTime) / $TimeSegment / $BurstCount)."<br>\n"); 365 for ($I = 0; $I <= round(($EndTime - $StartTime) / $TimeSegment / $BurstCount); $I++)365 for ($I = 0; $I <= round(($EndTime - $StartTime) / $TimeSegment / $BurstCount); $I++) 366 366 { 367 367 echo($I.' '); … … 371 371 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'. 372 372 TimeToMysqlDateTime($StartTime2).'" AND Time < "'.TimeToMysqlDateTime($EndTime2).'" AND Measure='.$this->Data['Id'].' AND Level='.($Level - 1).' ORDER BY Time'); 373 while ($Row = $DbResult->fetch_assoc())373 while ($Row = $DbResult->fetch_assoc()) 374 374 { 375 375 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); … … 377 377 } 378 378 379 if (count($Values) > 0)379 if (count($Values) > 0) 380 380 { 381 381 $Values = array_merge($this->LoadLeftSideValue($Level - 1, $StartTime2), … … 383 383 384 384 $StartIndex = 0; 385 for ($B = 0; $B < $BurstCount; $B++)385 for ($B = 0; $B < $BurstCount; $B++) 386 386 { 387 387 echo('.'); … … 390 390 391 391 $EndIndex = $StartIndex; 392 while ($Values[$EndIndex]['Time'] < $EndTime3) $EndIndex = $EndIndex + 1;392 while ($Values[$EndIndex]['Time'] < $EndTime3) $EndIndex = $EndIndex + 1; 393 393 $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1); 394 if (count($SubValues) > 2)394 if (count($SubValues) > 2) 395 395 { 396 396 $Point = $this->ComputeOneValue($StartTime3, $EndTime3, $SubValues, $Level); … … 420 420 $Measures = array(); 421 421 $Result = $Database->select('Measure', '*'); 422 while ($Row = $Result->fetch_assoc())422 while ($Row = $Result->fetch_assoc()) 423 423 { 424 424 $Measures = new Measure(); … … 426 426 } 427 427 428 foreach ($Measures as $Measure)428 foreach ($Measures as $Measure) 429 429 { 430 430 $Measure->RebuildMeasureCache();
Note:
See TracChangeset
for help on using the changeset viewer.