Changeset 49 for branches/old/stat_functions.php
- Timestamp:
- Feb 20, 2015, 8:30:42 AM (10 years ago)
- Location:
- branches/old
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/old
- Property svn:ignore
-
old new 1 1 config.php 2 .buildpath 3 .project 4 .settings
-
- Property svn:ignore
-
branches/old/stat_functions.php
r28 r49 19 19 array('E', 'exa', pow(10, 18)), 20 20 array('Z', 'zetta', pow(10, 21)), 21 array('Y', 'yotta', pow(10, 24)), 21 array('Y', 'yotta', pow(10, 24)), 22 22 ); 23 23 … … 27 27 { 28 28 if($Value >= pow(10, $II)) 29 { 30 if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits; 29 { 30 if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits; 31 31 $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1); 32 break; 32 break; 33 33 } 34 34 } … … 42 42 if($Unit == '') return(TruncateDigits($Value, $Digits)); 43 43 $I = 8; 44 if($Value > 0) $II = 1; 44 if($Value > 0) $II = 1; 45 45 else if($Value < 0) $II = -1; 46 46 else $II = 0; 47 while((($Value / $PrefixMultipliers[$I + $II][2]) > $II) and (($I + $II) >= 0) and (($I + $II) <= count($PrefixMultipliers))) $I = $I + $II; 47 while((($Value / $PrefixMultipliers[$I + $II][2]) > $II) and (($I + $II) >= 0) 48 and (($I + $II) <= count($PrefixMultipliers))) $I = $I + $II; 48 49 $Value = $Value / $PrefixMultipliers[$I][2]; 49 50 50 51 // Truncate digits count 51 52 $Value = TruncateDigits($Value, $Digits); 52 53 53 54 return($Value.' '.$PrefixMultipliers[$I][0].$Unit); 54 55 } … … 63 64 { 64 65 $Parts = explode(' ', $Time); 65 $DateParts = explode('-', $Parts[0]); 66 $DateParts = explode('-', $Parts[0]); 66 67 $TimeParts = explode(':', $Parts[1]); 67 68 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 68 return($Result); 69 return($Result); 69 70 } 70 71 71 72 function TimeToMysqlDateTime($Time) 72 73 { 73 return(date('Y-m-d H:i:s', $Time)); 74 return(date('Y-m-d H:i:s', $Time)); 74 75 } 75 76 … … 95 96 { 96 97 global $Database; 98 97 99 $Result = $Database->select('measure', '*', 'Id='.$Id); 98 if($Result->num_rows > 0) 100 if($Result->num_rows > 0) 99 101 { 100 102 $Measure = $Result->fetch_array(); 101 103 if($Measure['Continuity'] == 0) $Measure['ContinuityEnabled'] = 0; // non continuous 102 else $Measure['ContinuityEnabled'] = 2; // continuous graph 103 } else die('M ��enďż˝ veliďż˝ina nenalezena');104 else $Measure['ContinuityEnabled'] = 2; // continuous graph 105 } else die('Měřená veličina nenalezena'); 104 106 return($Measure); 105 107 } … … 108 110 { 109 111 global $LevelReducing, $MaxLevel, $Database; 110 112 111 113 $Time = time(); 112 114 //$Value = round($Measure['divider'] * $Value); 113 115 114 116 $Result = $Database->select($Measure['DataTable'], '*', 'measure='.$Measure['Id'].' AND level=0 ORDER BY time DESC LIMIT 2'); 115 if($Result->num_rows == 0) $Database->insert($Measure['DataTable'], array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 116 'continuity' => 0)); 117 if($Result->num_rows == 0) $Database->insert($Measure['DataTable'], 118 array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 119 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 'continuity' => 0)); 117 120 else if($Result->num_rows == 1) $Database->insert($Measure['DataTable'], array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 118 121 'continuity' => 1)); … … 123 126 { 124 127 } 125 else 128 else 126 129 { 127 130 if(($Time - MysqlDateTimeToTime($LastValue['time'])) < 1.25 * $Measure['Period']) $Continuity = 1; … … 130 133 ($LastValue['continuity'] == 1) and ($Continuity == 1)) 131 134 { 132 //echo('s');133 $Database->update($Measure['DataTable'], 'time="'.$LastValue['time'].'" AND level=0 AND measure='.$Measure['Id'], array('time' => 'NOW()'));135 $Database->update($Measure['DataTable'], '(time="'.$LastValue['time'].'") AND '. 136 '(level=0) AND (measure='.$Measure['Id'].')', array('time' => TimeToMysqlDateTime($Time))); 134 137 } else 135 138 { 136 $Database->insert($Measure['DataTable'], array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 137 'continuity' => $Continuity)); 138 } 139 } 140 } 141 139 $Database->insert($Measure['DataTable'], array('min' => $Value, 140 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 141 'continuity' => $Continuity)); 142 } 143 } 144 } 145 142 146 // Update levels 143 147 //echo($Time."<br>\n"); … … 170 174 $Point = ComputeOneValue($StartTime, $EndTime, $Values, $Measure, $Level); 171 175 //print_r($Point); 172 176 173 177 $Database->delete($Measure['DataTable'], '(time > "'.TimeToMysqlDateTime($StartTime).'") AND 174 178 (time < "'.TimeToMysqlDateTime($EndTime).'") AND measure='.$Measure['Id'].' AND level='.$Level); … … 247 251 { 248 252 if(0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0; 249 } 250 else 251 { 253 } else { 252 254 if($Differential == 0) 253 255 { … … 256 258 $Difference = $Values[$I+1][$ValueType] - $Values[$I][$ValueType]; 257 259 if($Difference < $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference; 258 } 260 } 259 261 } 260 262 } 261 262 } 263 } 263 264 $NewValue[$ValueType] = $NewValue[$ValueType]; 264 265 } … … 276 277 { 277 278 global $Debug, $Database; 278 279 279 280 // Get first and last time 280 281 //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n"); … … 302 303 303 304 function LoadRightSideValue($Level, $Measure, $Time) 304 { 305 { 305 306 global $Debug, $Database; 306 307 $Result = array(); … … 326 327 return($Result); 327 328 } 328 } 329 } 329 330 330 331 function LoadLeftSideValue($Level, $Measure, $Time) … … 339 340 $Row['time'] = MysqlDateTimeToTime($Row['time']); 340 341 return(array($Row)); 341 } 342 else 343 { 342 } else { 344 343 //$Time = $Values[0]['time'] - 60; 345 344 //array_unshift($Values, array('time' => $Time, 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 346 345 $Result[] = array('time' => ($Time - TimeSegment($Level)), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0); 347 346 348 347 $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time ASC LIMIT 1'); 349 348 if($DbResult->num_rows > 0) … … 360 359 { 361 360 global $DivisionCount, $Debug, $Database; 362 361 363 362 if($Debug) echo('TimeFrom: '.$TimeFrom.'('.TimeToMysqlDateTime($TimeFrom).')<br>'); 364 363 if($Debug) echo('TimeTo: '.$TimeTo.'('.TimeToMysqlDateTime($TimeTo).')<br>'); 365 364 366 365 //$AbsoluteTime = GetTimeRange($MeasureId); 367 366 368 367 // if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 369 368 // ($TimeTo > $AbsoluteLeftTime) and ($TimeTo < $AbsoluteRightTime)) … … 392 391 { 393 392 $Values = array_merge(LoadLeftSideValue($Level, $Measure, $TimeFrom), $Values, LoadRightSideValue($Level, $Measure, $TimeTo)); 394 393 395 394 //echo(count($Values).'<br>'); 396 395 //echo($TimeFrom.','.$TimeTo.'<br>'); … … 458 457 $Values[] = $Row; 459 458 } 460 459 461 460 if(count($Values) > 0) 462 { 461 { 463 462 $Values = array_merge(LoadLeftSideValue($Level-1, $Measure, $StartTime2), $Values, LoadRightSideValue($Level-1, $Measure, $EndTime2)); 464 463 465 464 $StartIndex = 0; 466 465 for($B = 0; $B < $BurstCount; $B++) 467 { 466 { 468 467 echo('.'); 469 468 $StartTime3 = $StartTime2 + (($EndTime2 - $StartTime2) / $BurstCount) * $B; 470 469 $EndTime3 = $StartTime2 + (($EndTime2 - $StartTime2) / $BurstCount) * ($B+1); 471 470 472 471 $EndIndex = $StartIndex; 473 472 while($Values[$EndIndex]['time'] < $EndTime3) $EndIndex = $EndIndex + 1; … … 476 475 //print_r($SubValues); 477 476 if(count($SubValues) > 2) 478 { 477 { 479 478 $Point = ComputeOneValue($StartTime3, $EndTime3, $SubValues, $Measure, $Level); 480 479 $Continuity = $SubValues[1]['continuity']; 481 480 $Database->insert($Measure['DataTable'], array('level' => $Level, 'measure' => $Measure['Id'], 'min' => $Point['min'], 482 481 'avg' => $Point['avg'], 'max' => $Point['max'], 'continuity' => $Continuity, 'time' => TimeToMysqlDateTime($StartTime3+($EndTime3-$StartTime3)/2))); 483 } 484 $StartIndex = $EndIndex - 1; 482 } 483 $StartIndex = $EndIndex - 1; 485 484 } 486 485 } 487 486 // Load values in time range 488 487 //array_pop($NextValues); 489 } 490 echo("Uroven dokoncena<br>\n"); 488 } 489 echo("Uroven dokoncena<br>\n"); 491 490 $DbResult = $Database->select($Measure['DataTable'], 'COUNT(*)', 'level='.$Level.' AND measure='.$Measure['Id']); 492 491 $Row = $DbResult->fetch_array(); … … 498 497 { 499 498 global $Database; 500 501 499 502 500 // echo("Vytvarim novou cache...\n"); 503 501 // Load measures … … 509 507 foreach($Measures as $Measure) 510 508 { 511 RebuildMeasureCache($Measure); 512 echo('Velicina dokoncena<br >');509 RebuildMeasureCache($Measure); 510 echo('Velicina dokoncena<br/>'); 513 511 } 514 512 } … … 517 515 { 518 516 global $Database; 517 519 518 $Database->query('CREATE TABLE `data_'.$Measure['Name'].'` ( 520 519 `Time` TIMESTAMP NOT NULL , … … 532 531 ) ENGINE = MYISAM ;'); 533 532 } 534 535 ?>
Note:
See TracChangeset
for help on using the changeset viewer.