Changeset 6 for stat_functions.php
- Timestamp:
- Oct 16, 2007, 10:12:26 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
stat_functions.php
r2 r6 1 1 <?php 2 3 $DivisionCount = 500;4 $ReferenceTime = 0;5 $LevelReducing = 5;6 $MaxLevel = 4;7 2 8 3 $ValueTypes = array('min', 'avg', 'max'); … … 36 31 function StatTableName($Level) 37 32 { 38 if($Level == 0) return(' stat_data');39 else return(' stat_data_cache');33 if($Level == 0) return('data'); 34 else return('data_cache'); 40 35 } 41 36 … … 49 44 { 50 45 global $Database; 51 $Result = $Database->select(' stat_measure', '*', 'id='.$Id);46 $Result = $Database->select('measure', '*', 'Id='.$Id); 52 47 if($Result->num_rows > 0) 53 48 { 54 49 $Measure = $Result->fetch_array(); 55 if($Measure[' continuity'] == 0) $Measure['ContinuityEnabled'] = 0; // non continuous50 if($Measure['Continuity'] == 0) $Measure['ContinuityEnabled'] = 0; // non continuous 56 51 else $Measure['ContinuityEnabled'] = 2; // continuous graph 57 52 } else die('Mìøená velièina nenalezena'); … … 64 59 65 60 $Time = time(); 66 $Value = round($Measure['divider']*$Value);67 68 $Result = $Databse->select( 'stat_data', '*', 'measure='.$Measure['id'].' AND level=0 ORDER BY time DESC LIMIT 2');69 if($Result->num_rows == 0) $Database->insert('stat_data', array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure[' id'], 'time' => TimeToMysqlDateTime($Time),61 //$Value = round($Measure['divider'] * $Value); 62 63 $Result = $Databse->select($Measure['DataTable'], '*', 'measure='.$Measure['Id'].' AND level=0 ORDER BY time DESC LIMIT 2'); 64 if($Result->num_rows == 0) $Database->insert('stat_data', array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 70 65 'continuity' => 0)); 71 else if($Result->num_rows == 1) $Database->insert( 'stat_data', array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['id'], 'time' => TimeToMysqlDateTime($Time),66 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), 72 67 'continuity' => 1)); 73 68 else { … … 85 80 { 86 81 echo('s'); 87 $Database->update( 'stat_data', 'time="'.$LastValue['time'].'" AND level=0 AND measure='.$Measure['id'], array('time' => 'NOW()'));82 $Database->update($Measure['DataTable'], 'time="'.$LastValue['time'].'" AND level=0 AND measure='.$Measure['Id'], array('time' => 'NOW()')); 88 83 } else 89 84 { 90 $Database->insert( 'stat_data', array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['id'], 'time' => TimeToMysqlDateTime($Time),85 $Database->insert($Measure['DataTable'], array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 91 86 'continuity' => $Continuity)); 92 87 } … … 109 104 // Load values in time range 110 105 $Values = array(); 111 $Result = $Database->select( StatTableName($Level-1), '*', 'time > "'.TimeToMysqlDateTime($StartTime).'" AND time < "'.112 TimeToMysqlDateTime($EndTime).'" AND measure='.$Measure[' id'].' AND level='.($Level-1).' ORDER BY time');106 $Result = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($StartTime).'" AND time < "'. 107 TimeToMysqlDateTime($EndTime).'" AND measure='.$Measure['Id'].' AND level='.($Level-1).' ORDER BY time'); 113 108 while($Row = $Result->fetch_array()) 114 109 { … … 126 121 //print_r($Point); 127 122 128 $Database->delete( StatTableName($Level), '(time > "'.TimeToMysqlDateTime($StartTime).'") AND129 (time < "'.TimeToMysqlDateTime($EndTime).'") AND measure='.$Measure[' id'].' AND level='.$Level);123 $Database->delete($Measure['DataTable'], '(time > "'.TimeToMysqlDateTime($StartTime).'") AND 124 (time < "'.TimeToMysqlDateTime($EndTime).'") AND measure='.$Measure['Id'].' AND level='.$Level); 130 125 $Continuity = $Values[1]['continuity']; 131 $Database->insert( StatTableName($Level), array('level' => $Level, 'measure' => $Measure['id'], 'min' => $Point['min'],126 $Database->insert($DataTable, array('level' => $Level, 'measure' => $Measure['Id'], 'min' => $Point['min'], 132 127 'avg' => $Point['avg'], 'max' => $Point['max'], 'continuity' => $Continuity, 'time' => TimeToMysqlDateTime($StartTime+($EndTime-$StartTime)/2))); 133 128 … … 203 198 } 204 199 //if(($RightTime - $LeftTime) > 0) 205 if($Measure[' cumulative'] == 0) $NewValue['avg'] = $NewValue['avg'] / ($RightTime - $LeftTime);200 if($Measure['Cumulative'] == 0) $NewValue['avg'] = $NewValue['avg'] / ($RightTime - $LeftTime); 206 201 return($NewValue); 207 202 //echo($NewValue['avg'].'<br>'); … … 214 209 215 210 // Get first and last time 216 echo($Measure[' id'].','.$Level.','.StatTableName($Level)."\n");217 $Result = $Database->select( StatTableName($Level), '*', 'measure='.$Measure['id'].' AND level='.$Level.' ORDER BY time LIMIT 1');211 echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n"); 212 $Result = $Database->select($Measure['DataTable'], '*', 'measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time LIMIT 1'); 218 213 if($Result->num_rows > 0) 219 214 { … … 222 217 } else $AbsoluteLeftTime = 0; 223 218 224 $Result = $Database->select( StatTableName($Level), '*', 'measure='.$Measure['id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1');219 $Result = $Database->select($Measure['DataTable'], '*', 'measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1'); 225 220 if($Result->num_rows > 0) 226 221 { … … 239 234 function LoadRightSideValue($Level, $Measure, $Time) 240 235 { 241 global $Debug ;236 global $Debug, $Database; 242 237 $Result = array(); 243 $ Result = $Database->select(StatTableName($Level), '*', 'time > "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['id'].' AND level='.$Level.' ORDER BY time ASC LIMIT 1');244 if($ Result->num_rows > 0)245 { 246 $Row = $ Result->fetch_array();238 $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time ASC LIMIT 1'); 239 if($DbResult->num_rows > 0) 240 { 241 $Row = $DbResult->fetch_array(); 247 242 $Row['time'] = MysqlDateTimeToTime($Row['time']); 248 243 return(array($Row)); … … 253 248 //array_push($Values, array('time' => $Time, 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 254 249 $Result[] = array('time' => ($Time + TimeSegment($Level)), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0); 255 $ Result = $Database->select(StatTableName($Level), '*', 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1');256 if($ Result->num_rows > 0)257 { 258 $Row = $ Result->fetch_array();250 $DbResult = $Database->select($Measure['DataTable'], '*', 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1'); 251 if($DbResult->num_rows > 0) 252 { 253 $Row = $DbResult->fetch_array(); 259 254 array_unshift($Result, array('time' => (MysqlDateTimeToTime($Row['time'])+10), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 260 255 } … … 266 261 function LoadLeftSideValue($Level, $Measure, $Time) 267 262 { 268 global $Debug ;263 global $Debug, $Database; 269 264 $Result = array(); 270 //echo('SELECT * FROM '.StatTableName($Level). ' WHERE '. 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure[' id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1'."<br>\n");271 $ Result = $Database->select(StatTableName($Level), '*', 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1');272 if($ Result->num_rows > 0)273 { 274 $Row = $ Result->fetch_array();265 //echo('SELECT * FROM '.StatTableName($Level). ' WHERE '. 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1'."<br>\n"); 266 $DbResult = $Database->select($Measure['DataTable'], '*', 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1'); 267 if($DbResult->num_rows > 0) 268 { 269 $Row = $DbResult->fetch_array(); 275 270 $Row['time'] = MysqlDateTimeToTime($Row['time']); 276 271 return(array($Row)); … … 282 277 $Result[] = array('time' => ($Time - TimeSegment($Level)), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0); 283 278 284 $ Result = $Database->select(StatTableName($Level), '*', 'time > "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['id'].' AND level='.$Level.' ORDER BY time ASC LIMIT 1');285 if($ Result->num_rows > 0)286 { 287 $Row = $ Result->fetch_array();279 $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time ASC LIMIT 1'); 280 if($DbResult->num_rows > 0) 281 { 282 $Row = $DbResult->fetch_array(); 288 283 array_push($Result, array('time' => (MysqlDateTimeToTime($Row['time'])-10), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 289 284 } … … 295 290 function GetValues($Measure, $TimeFrom, $TimeTo, $Level) 296 291 { 297 global $DivisionCount, $Debug ;292 global $DivisionCount, $Debug, $Database; 298 293 299 294 if($Debug) echo('TimeFrom: '.$TimeFrom.'('.TimeToMysqlDateTime($TimeFrom).')<br>'); … … 307 302 308 303 // Load values in time range 309 $Result = $Database->select( StatTableName($Level), 'time, min, avg, max, continuity', 'time > "'.TimeToMysqlDateTime($TimeFrom).'" AND time < "'.310 TimeToMysqlDateTime($TimeTo).'" AND measure='.$Measure[' id'].' AND level='.$Level.' ORDER BY time');304 $Result = $Database->select($Measure['DataTable'], 'time, min, avg, max, continuity', 'time > "'.TimeToMysqlDateTime($TimeFrom).'" AND time < "'. 305 TimeToMysqlDateTime($TimeTo).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time'); 311 306 // echo($Level.' '.TimeToMysqlDateTime($TimeFrom).' '.TimeToMysqlDateTime($TimeTo)); 312 307 $Values = array(); … … 334 329 $StartIndex = 0; 335 330 $Points = array(); 331 //echo($DivisionCount.'<br>'); 336 332 for($I = 0; $I < $DivisionCount; $I++) 337 333 { … … 358 354 global $MaxLevel, $LevelReducing; 359 355 360 echo('Velicina '.$Measure[' name']."\n");361 if($Measure[' continuity'] == 0) $Measure['ContinuityEnabled'] = 0; // non continuous356 echo('Velicina '.$Measure['Name']."\n"); 357 if($Measure['Continuity'] == 0) $Measure['ContinuityEnabled'] = 0; // non continuous 362 358 else $Measure['ContinuityEnabled'] = 2; // continuous graph 363 359 364 360 // Clear previous items 365 $Result = $Database->select( 'stat_data_cache', 'COUNT(*)', 'level>0 AND measure='.$Measure['id']);361 $Result = $Database->select($Measure['DataTable'], 'COUNT(*)', 'level>0 AND measure='.$Measure['Id']); 366 362 $Row = $Result->fetch_array(); 367 363 echo("Mazu starou cache (".$Row[0]." polozek)..."); 368 $Database->delete( 'stat_data_cache', 'level>0 AND measure='.$Measure['id']);364 $Database->delete($Measure['DataTable'], 'level>0 AND measure='.$Measure['Id']); 369 365 echo("\n"); 370 366 … … 373 369 echo('Uroven '.$Level."\n"); 374 370 $TimeRange = GetTimeRange($Measure, $Level-1); 375 //echo($Measure[' id'].','.($Level-1)."\n");371 //echo($Measure['Id'].','.($Level-1)."\n"); 376 372 //echo(TimeToMysqlDateTime($TimeRange['left']).'-'.TimeToMysqlDateTime($TimeRange['right'])."\n"); 377 373 $TimeSegment = TimeSegment($Level); … … 386 382 $EndTime2 = $StartTime + ($I+1) * $BurstCount * $TimeSegment; 387 383 $Values = array(); 388 DB_Select( StatTableName($Level-1), '*', 'time > "'.TimeToMysqlDateTime($StartTime2).'" AND time < "'.389 TimeToMysqlDateTime($EndTime2).'" AND measure='.$Measure[' id'].' AND level='.($Level-1).' ORDER BY time');384 DB_Select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($StartTime2).'" AND time < "'. 385 TimeToMysqlDateTime($EndTime2).'" AND measure='.$Measure['Id'].' AND level='.($Level-1).' ORDER BY time'); 390 386 while($Row = DB_Row()) 391 387 { … … 414 410 $Point = ComputeOneValue($StartTime3, $EndTime3, $SubValues, $Measure, $Level); 415 411 $Continuity = $SubValues[1]['continuity']; 416 DB_Insert( StatTableName($Level), array('level' => $Level, 'measure' => $Measure['id'], 'min' => $Point['min'],412 DB_Insert($Measure['DataTable'], array('level' => $Level, 'measure' => $Measure['Id'], 'min' => $Point['min'], 417 413 'avg' => $Point['avg'], 'max' => $Point['max'], 'continuity' => $Continuity, 'time' => TimeToMysqlDateTime($StartTime3+($EndTime3-$StartTime3)/2))); 418 414 } … … 424 420 } 425 421 echo("Uroven dokoncena\n"); 426 DB_Select( 'stat_data', 'COUNT(*)', 'level='.$Level.' AND measure='.$Measure['id']);422 DB_Select($Measure['DataTable'], 'COUNT(*)', 'level='.$Level.' AND measure='.$Measure['Id']); 427 423 $Row = DB_Row(); 428 424 echo("Vlozeno ".$Row[0]." polozek.\n"); … … 438 434 // Load measures 439 435 $Measures = array(); 440 $Result = $Database->select(' stat_measure', '*');436 $Result = $Database->select('measure', '*'); 441 437 while($Measures[] = $Result->fetch_array()); 442 438 array_pop($Measures);
Note:
See TracChangeset
for help on using the changeset viewer.