Changeset 36
- Timestamp:
- Nov 11, 2008, 1:52:03 PM (16 years ago)
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Readme.txt
r28 r36 2 2 ================= 3 3 4 Je potøeba zkopírovat soubor config.sample.php jako config.php a upravit v nìm nastavení. 5 Ve sloce SQL jsou uloeny definice tabulek measure (struktura i ukázkové data) a tabulky data, kterou je potøeba vytvoøit pro jednotlivá mìøení. 6 Ve sloce measure_scripts je ukázkový soubor monitor.sample.php, který zajiuje získávání informací o rùzných velièinách v poèítaèi. 7 4 Instalace 5 ========= 6 7 * Pro správnou funkci je poadován webový server (napø. apache), MySql databáze a PHP interpretr. Dále pro vykreslení grafù také knihovna php-gd. 8 * Zkopírujte soubor ukázkový config.sample.php jako config.php do stejné sloky a upravte v nìm nastavení. 9 * Vytvoøete v databázi uivatele statistic a tabulku statistic a doplòte pøístupové údaje do config.php. 10 * Proveïtì import ukázkových dat ze souboru full.sql s nejvyím èíslem revize umístìným ve sloce sql. Samotná struktura tabulky measure je v measure.sql a ukázková struktura datové tabulky je v data.sql. 11 * Ve sloce measure_scripts je ukázkový soubor monitor.sample.php, který zajiuje získávání informací o rùzných velièinách v poèítaèi a jejich plnìní do systému. Zkopírujte jej jako monitor.php a upravte dle potøeb. 12 13 Poznámky k vydání 14 ================= 15 8 16 Verze 3.1 (13.2.2008) 9 17 -
add.php
r28 r36 1 <? 1 <?php 2 2 include('global.php'); 3 3 … … 9 9 if(gethostbyaddr($_SERVER['REMOTE_ADDR']) == $Measure['PermissionAdd']) 10 10 { 11 AddValue($Measure, $Value);12 echo('Hodnota '.$Value.' ulo ena');13 } else echo('Nemáte oprávnění k aktualizaci zadané veličiny!<br>Va e adresa: '.gethostbyaddr($_SERVER['REMOTE_ADDR']).'('.$_SERVER['REMOTE_ADDR'].')');11 AddValue($Measure, array('min' => $Value, 'avg' => $Value, 'max' => $Value)); 12 echo('Hodnota '.$Value.' uložena'); 13 } else echo('Nemáte oprávnění k aktualizaci zadané veličiny!<br>Vaše adresa: '.gethostbyaddr($_SERVER['REMOTE_ADDR']).'('.$_SERVER['REMOTE_ADDR'].')'); 14 14 } else echo('Nebyly zadány potřebné parametry'); 15 15 -
stat_functions.php
r35 r36 2 2 3 3 $ValueTypes = array('min', 'avg', 'max'); 4 $PrefixMultipliers = array( 4 $PrefixMultipliers = array 5 ( 5 6 array('y', 'yocto', pow(10, -24)), 6 7 array('z', 'zepto', pow(10, -21)), … … 19 20 array('E', 'exa', pow(10, 18)), 20 21 array('Z', 'zetta', pow(10, 21)), 21 array('Y', 'yotta', pow(10, 24)), 22 array('Y', 'yotta', pow(10, 24)), 22 23 ); 23 24 … … 27 28 { 28 29 if($Value >= pow(10, $II)) 29 { 30 if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits; 30 { 31 if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits; 31 32 $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1); 32 break; 33 break; 33 34 } 34 35 } … … 47 48 while((($Value / $PrefixMultipliers[$I + $II][2]) > $II) and (($I + $II) >= 0) 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 } … … 56 57 function GetMicrotime() 57 58 { 58 list($Usec, $Sec) = explode(" ",microtime());59 59 list($Usec, $Sec) = explode(" ", microtime()); 60 return ((float)$Usec + (float)$Sec); 60 61 } 61 62 … … 63 64 { 64 65 $Parts = explode(' ', $Time); 65 $DateParts = explode('-', $Parts[0]); 66 $DateParts = explode('-', $Parts[0]); 66 67 $TimeParts = explode(':', $Parts[1]); 67 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 68 return($Result); 68 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 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 } 75 76 function TimeSegment($ Level)74 return(date('Y-m-d H:i:s', $Time)); 75 } 76 77 function TimeSegment($Base, $Level) 77 78 { 78 79 global $LevelReducing; 79 return(pow($LevelReducing, $Level) * 60); 80 81 return(pow($LevelReducing, $Level) * $Base); 80 82 } 81 83 … … 95 97 { 96 98 global $Database; 99 97 100 $Result = $Database->select('measure', '*', 'Id='.$Id); 98 if($Result->num_rows > 0) 99 { 100 $Measure = $Result->fetch_a rray();101 if($Result->num_rows > 0) 102 { 103 $Measure = $Result->fetch_assoc(); 101 104 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 return($Measure); 105 } 106 107 function AddValue($Measure, $Value = 0, $Time = 0)105 else $Measure['ContinuityEnabled'] = 2; // continuous graph 106 } else die('Měřená veličina nenalezena'); 107 return($Measure); 108 } 109 110 function AddValue($Measure, $Value = array('min' => 0, 'avg' => 0, 'max' => 0), $Level = 0, $Time = 0) 108 111 { 109 112 global $LevelReducing, $MaxLevel, $Database; … … 111 114 if($Time == 0) $Time = time(); 112 115 //$Value = round($Measure['divider'] * $Value); 113 114 echo(TimeToMysqlDateTime($Time)."\n"); 115 116 $Result = $Database->select($Measure['DataTable'], '*', 'measure='.$Measure['Id'].' AND level=0 ORDER BY time DESC LIMIT 2'); 117 echo($Database->LastQuery."\n"); 118 if($Result->num_rows == 0) $Database->insert($Measure['DataTable'], array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 119 'continuity' => 0)); 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), 121 'continuity' => 1)); 122 else { 116 //echo(TimeToMysqlDateTime($Time).'|'.$Level."\n"); 117 118 $Result = $Database->select($Measure['DataTable'], '*', 'measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 2'); 119 //echo($Database->LastQuery."\n"); 120 if($Result->num_rows == 0) 121 { 122 $Database->insert($Measure['DataTable'], array('min' => $Value['min'], 'avg' => $Value['avg'], 'max' => $Value['max'], 'level' => $Level, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 'continuity' => 0)); 123 //echo($Database->LastQuery."\n"); 124 } else if($Result->num_rows == 1) 125 { 126 $Database->insert($Measure['DataTable'], array('min' => $Value['min'], 'avg' => $Value['avg'], 'max' => $Value['max'], 'level' => $Level, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 'continuity' => 1)); 127 //echo($Database->LastQuery."\n"); 128 } else 129 { 123 130 $LastValue = $Result->fetch_array(); 124 131 $NextToLastValue = $Result->fetch_array(); 125 echo($Time.' - '.MysqlDateTimeToTime($LastValue['time']).' '.($Time - MysqlDateTimeToTime($LastValue['time'])).' = '.$Measure['Period']);126 if(( $Time - MysqlDateTimeToTime($LastValue['time'])) < 0.75 * $Measure['Period'])127 { 128 echo( 'Too short period');129 } 130 else 132 //echo($Level.': '.$Time.' - '.MysqlDateTimeToTime($LastValue['time']).' '.($Time - MysqlDateTimeToTime($LastValue['time'])).' = '.$Measure['Period']."\n"); 133 if((($Time - MysqlDateTimeToTime($LastValue['time'])) < 0.75 * $Measure['Period']) and ($Level == 0)) 134 { 135 echo("Too short period\n"); 136 } 137 else 131 138 { 132 139 if(($Time - MysqlDateTimeToTime($LastValue['time'])) < 1.25 * $Measure['Period']) $Continuity = 1; … … 134 141 //echo('('.$LastValue['avg'].'=='.$NextToLastValue['avg'].') and ('.$LastValue['avg'].' == '.$Value.') and 135 142 //('.$LastValue['continuity'].' == 1) and ('.$Continuity.' == 1))'."\n"); 136 if(($LastValue['avg'] == $NextToLastValue['avg']) and ($LastValue['avg'] == $Value) and 137 ($LastValue['continuity'] == 1) and ($Continuity == 1)) 138 { 139 $Database->update($Measure['DataTable'], 'time="'.$LastValue['time'].'" AND level=0 AND measure='.$Measure['Id'], array('time' => 'NOW()')); 140 echo($Database->LastQuery."\n"); 143 if(($LastValue['min'] == $NextToLastValue['min']) and ($LastValue['min'] == $Value['min']) and ($LastValue['avg'] == $NextToLastValue['avg']) and ($LastValue['avg'] == $Value['avg']) and ($LastValue['max'] == $NextToLastValue['max']) and ($LastValue['max'] == $Value['max']) and ($LastValue['continuity'] == 1) and ($Continuity == 1)) 144 { 145 $Database->update($Measure['DataTable'], 'time="'.$LastValue['time'].'" AND level='.$Level.' AND measure='.$Measure['Id'], array('time' => TimeToMysqlDateTime($Time))); 146 //echo($Database->LastQuery."\n"); 141 147 } else 142 148 { 143 $Database->insert($Measure['DataTable'], array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 144 'continuity' => $Continuity)); 145 echo($Database->LastQuery."\n"); 149 $Database->insert($Measure['DataTable'], array('min' => $Value['min'], 'avg' => $Value['avg'], 'max' => $Value['max'], 'level' => $Level, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 'continuity' => $Continuity)); 150 //echo($Database->LastQuery."\n"); 146 151 } 147 152 } 148 153 } 149 154 150 // Update levels 151 //echo($Time."<br>\n"); 152 for($Level = 1; $Level <= $MaxLevel; $Level++) 153 { 154 //echo('Level '.$Level."<br>\n"); 155 $TimeSegment = TimeSegment($Level); 156 $EndTime = AlignTime($Time, $TimeSegment); 157 //if($EndTime < $Time) $EndTime = $EndTime + $TimeSegment; 158 $StartTime = $EndTime - $TimeSegment; 159 160 //echo(" ".$TimeSegment." ".$StartTime.'-'.$EndTime."<br>\n"); 161 //flush(); 162 163 // Load values in time range 164 $Values = array(); 165 $Result = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($StartTime).'" AND time < "'. 166 TimeToMysqlDateTime($EndTime).'" AND measure='.$Measure['Id'].' AND level='.($Level-1).' ORDER BY time'); 167 while($Row = $Result->fetch_array()) 168 { 169 $Row['time'] = MysqlDateTimeToTime($Row['time']); 170 $Values[] = $Row; 171 } 172 //print_r($Values); 173 //array_pop($Values); 174 175 // Load subsidary values 176 $Values = array_merge(LoadLeftSideValue($Level-1, $Measure, $StartTime), $Values, LoadRightSideValue($Level-1, $Measure, $EndTime)); 177 178 $Point = ComputeOneValue($StartTime, $EndTime, $Values, $Measure, $Level); 179 //print_r($Point); 180 181 $Database->delete($Measure['DataTable'], '(time > "'.TimeToMysqlDateTime($StartTime).'") AND 182 (time < "'.TimeToMysqlDateTime($EndTime).'") AND measure='.$Measure['Id'].' AND level='.$Level); 183 $Continuity = $Values[1]['continuity']; 184 $Database->insert($Measure['DataTable'], array('level' => $Level, 'measure' => $Measure['Id'], 'min' => $Point['min'], 185 'avg' => $Point['avg'], 'max' => $Point['max'], 'continuity' => $Continuity, 'time' => TimeToMysqlDateTime($StartTime+($EndTime-$StartTime)/2))); 186 187 } 155 // Update next level 156 if($Level < $MaxLevel) 157 { 158 $Level = $Level + 1; 159 //echo('Level '.$Level."<br>\n"); 160 $TimeSegment = TimeSegment($Measure['Period'], 1); 161 $EndTime = AlignTime($Time, $TimeSegment); 162 //if($EndTime < $Time) $EndTime = $EndTime + $TimeSegment; 163 $StartTime = $EndTime - $TimeSegment; 164 165 //echo(" ".$TimeSegment." ".$StartTime.'-'.$EndTime."<br>\n"); 166 //flush(); 167 168 // Load values in time range 169 $Values = array(); 170 //.'" AND time < "'.TimeToMysqlDateTime($EndTime).'" AND measure='.$Measure['Id'].' AND level='.($Level - 1).' ORDER BY time'); 171 $Result = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($StartTime).'" AND time < "'.TimeToMysqlDateTime($EndTime).'" AND measure='.$Measure['Id'].' AND level='.($Level - 1).' ORDER BY time'); 172 while($Row = $Result->fetch_array()) 173 { 174 $Row['time'] = MysqlDateTimeToTime($Row['time']); 175 $Values[] = $Row; 176 } 177 //print_r($Values); 178 //array_pop($Values); 179 180 // Load subsidary values 181 $Values = array_merge(LoadLeftSideValue($Level - 1, $Measure, $StartTime), $Values, LoadRightSideValue($Level - 1, $Measure, $EndTime)); 182 183 $Point = ComputeOneValue($StartTime, $EndTime, $Values, $Measure, $Level); 184 //print_r($Point); 185 186 $Database->delete($Measure['DataTable'], '(time > "'.TimeToMysqlDateTime($StartTime).'") AND (time < "'.TimeToMysqlDateTime($EndTime).'") AND measure='.$Measure['Id'].' AND level='.$Level); 187 $Measure['Period'] = $TimeSegment; 188 AddValue($Measure, array('min' => $Point['min'], 'avg' => $Point['avg'], 'max' => $Point['max']), $Level, $StartTime + ($EndTime - $StartTime) / 2); 189 } 188 190 } 189 191 … … 198 200 { 199 201 global $ValueTypes, $Differential; 200 201 $NewValue = array('min' => +1000000000000000000, 'avg' => 0, 'max' => -1000000000000000000); 202 202 203 $NewValue = array('min' => +1000000000000000000, 'avg' => 0, 'max' => -1000000000000000000); 204 203 205 // Trim outside parts 204 206 foreach($ValueTypes as $ValueType) … … 208 210 $Values[0]['time'] = $LeftTime; 209 211 foreach($ValueTypes as $ValueType) 210 { 211 $Values[count($Values) -1][$ValueType] = Interpolation($Values[count($Values)-2]['time'], $Values[count($Values)-2][$ValueType],212 $Values[count($Values) -1]['time'], $Values[count($Values)-1][$ValueType], $RightTime);213 } 214 $Values[count($Values) -1]['time'] = $RightTime;215 216 // Perform computation 212 { 213 $Values[count($Values) - 1][$ValueType] = Interpolation($Values[count($Values) - 2]['time'], $Values[count($Values) - 2][$ValueType], 214 $Values[count($Values) - 1]['time'], $Values[count($Values) - 1][$ValueType], $RightTime); 215 } 216 $Values[count($Values) - 1]['time'] = $RightTime; 217 218 // Perform computation 217 219 foreach($ValueTypes as $ValueType) 218 { 220 { 219 221 // Compute new value 220 222 for($I = 0; $I < (count($Values) - 1); $I++) 221 { 222 if($ValueType == 'avg') 223 { 224 if($Values[$I +1]['continuity'] == $Measure['ContinuityEnabled']);223 { 224 if($ValueType == 'avg') 225 { 226 if($Values[$I + 1]['continuity'] == $Measure['ContinuityEnabled']); 225 227 else if($Differential == 0) 226 228 { 227 229 $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I+1]['time'] - $Values[$I]['time']) * 228 230 (($Values[$I+1][$ValueType] - $Values[$I][$ValueType]) / 2 + $Values[$I][$ValueType]); 229 } else { 231 } else 232 { 230 233 $NewValue[$ValueType] = $NewValue[$ValueType] + ($Values[$I+1]['time'] - $Values[$I]['time']) * 231 234 (($Values[$I+1][$ValueType] - $Values[$I][$ValueType]) / 2); 232 235 } 233 236 } 234 else if($ValueType == 'max') 235 { 236 if($Values[$I +1]['continuity'] == $Measure['ContinuityEnabled'])237 else if($ValueType == 'max') 238 { 239 if($Values[$I + 1]['continuity'] == $Measure['ContinuityEnabled']) 237 240 { 238 241 if(0 > $NewValue[$ValueType]) $NewValue[$ValueType] = 0; 239 242 } 240 else 243 else 241 244 { 242 245 if($Differential == 0) 243 246 { 244 if($Values[$I +1][$ValueType] > $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I+1][$ValueType];247 if($Values[$I + 1][$ValueType] > $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType]; 245 248 } else { 246 $Difference = $Values[$I +1][$ValueType] - $Values[$I][$ValueType];249 $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType]; 247 250 if($Difference > $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference; 248 } 251 } 249 252 } 250 253 } … … 252 255 { 253 256 //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>'); 254 if($Values[$I +1]['continuity'] == $Measure['ContinuityEnabled'])257 if($Values[$I + 1]['continuity'] == $Measure['ContinuityEnabled']) 255 258 { 256 259 if(0 < $NewValue[$ValueType]) $NewValue[$ValueType] = 0; 257 260 } 258 else 261 else 259 262 { 260 263 if($Differential == 0) 261 264 { 262 if($Values[$I +1][$ValueType] < $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I+1][$ValueType];265 if($Values[$I + 1][$ValueType] < $NewValue[$ValueType]) $NewValue[$ValueType] = $Values[$I + 1][$ValueType]; 263 266 } else { 264 $Difference = $Values[$I +1][$ValueType] - $Values[$I][$ValueType];267 $Difference = $Values[$I + 1][$ValueType] - $Values[$I][$ValueType]; 265 268 if($Difference < $NewValue[$ValueType]) $NewValue[$ValueType] = $Difference; 266 } 269 } 267 270 } 268 271 } 269 270 } 271 $NewValue[$ValueType] = $NewValue[$ValueType]; 272 } 273 $NewValue[$ValueType] = $NewValue[$ValueType]; 272 274 } 273 275 //if(($RightTime - $LeftTime) > 0) … … 275 277 { 276 278 $NewValue['avg'] = $NewValue['avg'] / ($RightTime - $LeftTime); 277 } 279 } 278 280 return($NewValue); 279 281 //echo($NewValue['avg'].'<br>'); … … 284 286 { 285 287 global $Debug, $Database; 286 288 287 289 // Get first and last time 288 290 //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n"); … … 314 316 $Result = array(); 315 317 $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time ASC LIMIT 1'); 316 if($DbResult->num_rows > 0) 318 if($DbResult->num_rows > 0) 317 319 { 318 320 $Row = $DbResult->fetch_array(); 319 321 $Row['time'] = MysqlDateTimeToTime($Row['time']); 320 322 return(array($Row)); 321 } 322 else 323 } 324 else 323 325 { 324 326 //$Time = $Values[count($Values)-1]['time'] + 60; 325 327 //array_push($Values, array('time' => $Time, 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 326 $Result[] = array('time' => ($Time + TimeSegment($ Level)), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0);328 $Result[] = array('time' => ($Time + TimeSegment($Measure['Period'], $Level)), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0); 327 329 $DbResult = $Database->select($Measure['DataTable'], '*', 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1'); 328 330 if($DbResult->num_rows > 0) 329 331 { 330 332 $Row = $DbResult->fetch_array(); 331 array_unshift($Result, array('time' => (MysqlDateTimeToTime($Row['time']) +10), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0));332 } 333 array_unshift($Result, array('time' => (MysqlDateTimeToTime($Row['time']) + 10), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 334 } 333 335 // if($Debug) print_r($Result); 334 336 return($Result); 335 337 } 336 } 338 } 337 339 338 340 function LoadLeftSideValue($Level, $Measure, $Time) 339 341 { 340 342 global $Debug, $Database; 343 341 344 $Result = array(); 342 345 //echo('SELECT * FROM '.StatTableName($Level). ' WHERE '. 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1'."<br>\n"); 343 346 $DbResult = $Database->select($Measure['DataTable'], '*', 'time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time DESC LIMIT 1'); 344 if($DbResult->num_rows > 0) 347 if($DbResult->num_rows > 0) 345 348 { 346 349 $Row = $DbResult->fetch_array(); 347 350 $Row['time'] = MysqlDateTimeToTime($Row['time']); 348 351 return(array($Row)); 349 } 350 else 352 } 353 else 351 354 { 352 355 //$Time = $Values[0]['time'] - 60; 353 356 //array_unshift($Values, array('time' => $Time, 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 354 $Result[] = array('time' => ($Time - TimeSegment($ Level)), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0);355 357 $Result[] = array('time' => ($Time - TimeSegment($Measure['Period'], $Level)), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0); 358 356 359 $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time ASC LIMIT 1'); 357 360 if($DbResult->num_rows > 0) 358 361 { 359 362 $Row = $DbResult->fetch_array(); 360 array_push($Result, array('time' => (MysqlDateTimeToTime($Row['time'])-10), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 361 } 363 array_push($Result, array('time' => (MysqlDateTimeToTime($Row['time'])-10), 'min' => 0, 'avg' => 0, 'max' => 0, 'continuity' => 0)); 364 } 362 365 // if($Debug) print_r($Result); 363 366 return($Result); … … 368 371 { 369 372 global $DivisionCount, $Debug, $Database; 370 373 371 374 if($Debug) echo('TimeFrom: '.$TimeFrom.'('.TimeToMysqlDateTime($TimeFrom).')<br>'); 372 375 if($Debug) echo('TimeTo: '.$TimeTo.'('.TimeToMysqlDateTime($TimeTo).')<br>'); 373 376 374 377 //$AbsoluteTime = GetTimeRange($MeasureId); 375 378 376 379 // if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 377 380 // ($TimeTo > $AbsoluteLeftTime) and ($TimeTo < $AbsoluteRightTime)) … … 379 382 380 383 // Load values in time range 381 $Result = $Database->select($Measure['DataTable'], 'time, min, avg, max, continuity', 'time > "'.TimeToMysqlDateTime($TimeFrom).'" AND time < "'. 382 TimeToMysqlDateTime($TimeTo).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time'); 384 $Result = $Database->select($Measure['DataTable'], 'time, min, avg, max, continuity', 'time > "'.TimeToMysqlDateTime($TimeFrom).'" AND time < "'.TimeToMysqlDateTime($TimeTo).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY time'); 383 385 // echo($Level.' '.TimeToMysqlDateTime($TimeFrom).' '.TimeToMysqlDateTime($TimeTo)); 384 386 $Values = array(); … … 395 397 // die(); 396 398 if($Debug) echo('Item count: '.count($Values)); 397 399 398 400 $Points = array(); 399 401 if(count($Values) > 0) 400 402 { 401 403 $Values = array_merge(LoadLeftSideValue($Level, $Measure, $TimeFrom), $Values, LoadRightSideValue($Level, $Measure, $TimeTo)); 402 404 403 405 //echo(count($Values).'<br>'); 404 406 //echo($TimeFrom.','.$TimeTo.'<br>'); … … 421 423 //print_r($SubValues); 422 424 $Points[] = ComputeOneValue($TimeStart, $TimeEnd, $SubValues, $Measure, $Level); 423 $StartIndex = $EndIndex - 1; 425 $StartIndex = $EndIndex - 1; 424 426 } 425 427 } else $Points[] = array('min' => 0, 'avg' => 0, 'max' => 0); … … 445 447 { 446 448 echo('Uroven '.$Level."<br>\n"); 447 $TimeRange = GetTimeRange($Measure, $Level -1);449 $TimeRange = GetTimeRange($Measure, $Level - 1); 448 450 //echo($Measure['Id'].','.($Level-1)."\n"); 449 451 //echo(TimeToMysqlDateTime($TimeRange['left']).'-'.TimeToMysqlDateTime($TimeRange['right'])."\n"); 450 $TimeSegment = TimeSegment($ Level);452 $TimeSegment = TimeSegment($Measure['Period'], $Level); 451 453 $StartTime = AlignTime($TimeRange['left'], $TimeSegment) - $TimeSegment; 452 454 $EndTime = AlignTime($TimeRange['right'], $TimeSegment); 453 $BurstCount = 500; 455 $BurstCount = 500; 454 456 echo('For 0 to '.round(($EndTime - $StartTime) / $TimeSegment / $BurstCount)."<br>\n"); 455 457 for($I = 0; $I <= round(($EndTime - $StartTime) / $TimeSegment / $BurstCount); $I++) … … 459 461 $EndTime2 = $StartTime + ($I+1) * $BurstCount * $TimeSegment; 460 462 $Values = array(); 461 $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($StartTime2).'" AND time < "'. 462 TimeToMysqlDateTime($EndTime2).'" AND measure='.$Measure['Id'].' AND level='.($Level-1).' ORDER BY time'); 463 $DbResult = $Database->select($Measure['DataTable'], '*', 'time > "'.TimeToMysqlDateTime($StartTime2).'" AND time < "'.TimeToMysqlDateTime($EndTime2).'" AND measure='.$Measure['Id'].' AND level='.($Level-1).' ORDER BY time'); 463 464 while($Row = $DbResult->fetch_array()) 464 465 { … … 466 467 $Values[] = $Row; 467 468 } 468 469 469 470 if(count($Values) > 0) 470 { 471 $Values = array_merge(LoadLeftSideValue($Level -1, $Measure, $StartTime2), $Values, LoadRightSideValue($Level-1, $Measure, $EndTime2));472 471 { 472 $Values = array_merge(LoadLeftSideValue($Level - 1, $Measure, $StartTime2), $Values, LoadRightSideValue($Level - 1, $Measure, $EndTime2)); 473 473 474 $StartIndex = 0; 474 475 for($B = 0; $B < $BurstCount; $B++) 475 { 476 { 476 477 echo('.'); 477 478 $StartTime3 = $StartTime2 + (($EndTime2 - $StartTime2) / $BurstCount) * $B; 478 $EndTime3 = $StartTime2 + (($EndTime2 - $StartTime2) / $BurstCount) * ($B +1);479 479 $EndTime3 = $StartTime2 + (($EndTime2 - $StartTime2) / $BurstCount) * ($B + 1); 480 480 481 $EndIndex = $StartIndex; 481 482 while($Values[$EndIndex]['time'] < $EndTime3) $EndIndex = $EndIndex + 1; … … 484 485 //print_r($SubValues); 485 486 if(count($SubValues) > 2) 486 { 487 { 487 488 $Point = ComputeOneValue($StartTime3, $EndTime3, $SubValues, $Measure, $Level); 488 $Continuity = $SubValues[1]['continuity']; 489 $Database->insert($Measure['DataTable'], array('level' => $Level, 'measure' => $Measure['Id'], 'min' => $Point['min'], 490 'avg' => $Point['avg'], 'max' => $Point['max'], 'continuity' => $Continuity, 'time' => TimeToMysqlDateTime($StartTime3+($EndTime3-$StartTime3)/2))); 491 } 492 $StartIndex = $EndIndex - 1; 489 $Continuity = $SubValues[1]['continuity']; 490 $Database->insert($Measure['DataTable'], array('level' => $Level, 'measure' => $Measure['Id'], 'min' => $Point['min'], 'avg' => $Point['avg'], 'max' => $Point['max'], 'continuity' => $Continuity, 'time' => TimeToMysqlDateTime($StartTime3 + ($EndTime3 - $StartTime3) / 2))); 491 } 492 $StartIndex = $EndIndex - 1; 493 493 } 494 494 } … … 496 496 //array_pop($NextValues); 497 497 } 498 echo("Uroven dokoncena<br>\n"); 498 echo("Uroven dokoncena<br>\n"); 499 499 $DbResult = $Database->select($Measure['DataTable'], 'COUNT(*)', 'level='.$Level.' AND measure='.$Measure['Id']); 500 500 $Row = $DbResult->fetch_array(); 501 echo("Vlo zeno ".$Row[0]." polozek.<br>\n");502 } 503 } 501 echo("Vloženo ".$Row[0]." položek.<br>\n"); 502 } 503 } 504 504 505 505 function RebuildAllMeasuresCache() 506 506 { 507 507 global $Database; 508 509 510 // echo("Vytvarim novou cache...\n"); 508 509 // echo("Vytvarim novou cache...\n"); 511 510 // Load measures 512 511 $Measures = array(); … … 517 516 foreach($Measures as $Measure) 518 517 { 519 RebuildMeasureCache($Measure); 520 echo('Velicina dokoncena<br>'); 518 RebuildMeasureCache($Measure); 519 echo('Velicina dokoncena<br>'); 521 520 } 522 521 } … … 525 524 { 526 525 global $Database; 526 527 527 $Database->query('CREATE TABLE `data_'.$Measure['Name'].'` ( 528 528 `Time` TIMESTAMP NOT NULL ,
Note:
See TracChangeset
for help on using the changeset viewer.