Changeset 656 for trunk/Modules/TimeMeasure
- Timestamp:
- May 16, 2014, 10:44:07 PM (11 years ago)
- Location:
- trunk/Modules/TimeMeasure
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/TimeMeasure/Graph.php
r655 r656 106 106 $PointsMax[] = $Index * $Width / $Measure->DivisionCount; 107 107 $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 108 //echo($Index.' - '.$Item.' '.$Points[$Index].'<br>');109 108 } 110 109 } … … 127 126 //$Points[] = $Width - 1; 128 127 //$Points[] = $Height - 1; 129 130 //print_r($PointsMax);131 128 132 129 // Generate image -
trunk/Modules/TimeMeasure/Main.php
r655 r656 3 3 class PageMeasure extends Page 4 4 { 5 var $Months;6 5 var $GraphTimeRanges; 7 6 var $DefaultVariables; … … 23 22 'Differential' => 0, 24 23 ); 25 $this->Months = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen',26 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');27 24 $this->GraphTimeRanges = array 28 25 ( … … 56 53 function EditTime($Time) 57 54 { 55 global $MonthNames; 56 58 57 $Output = '<form style="display: inline;" action="?Operation=SetTime&Time='.$Time.'" method="post">'; 59 58 … … 72 71 // Month selection 73 72 $Output .= '<select name="Month">'; 74 foreach($ this->Months as $Index => $Month)73 foreach($MonthNames as $Index => $Month) 75 74 { 76 75 if($Index == $TimeParts['mon']) $Selected = ' selected="1"'; else $Selected = ''; … … 133 132 } 134 133 135 $Output = ' ';134 $Output = '<div style="text-align: center;">'; 136 135 137 136 if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = ''; … … 171 170 $Output .= '<a href="?TimeSpecify=1">Přesnější nastavení...</a><br>'; 172 171 } else { 173 $Output .= '<table cellspacing="0" cellpadding="2" border="0">';172 $Output .= '<table style="margin: 10px auto; " cellspacing="0" cellpadding="2" border="0">'; 174 173 $Output .= '<tr><td>Počátek:</td><td>'.$this->EditTime('TimeStart').'</td></tr>'; 175 174 $Output .= '<tr><td>Konec:</td><td>'.$this->EditTime('TimeEnd').'</td></tr>'; … … 198 197 { 199 198 $PrefixMultiplier = new PrefixMultiplier(); 200 $Output = '<table border="1" cellspacing="0" cellpadding="2" style="font-size: small;">'; 201 $Output .= '<tr><th>Měřená veličina</th><th>Poslední hodnota</th><th>Čas posledního měření</th><th>Interpolace</th><th>Poznámky</th>'; 202 if(array_key_exists('Debug', $_GET)) $Output .= '<th>Počet položek</th><th>Čas vykonání</th>'; 203 $Output .= '</tr>'; 204 $Result = $this->Database->select('Measure', '*', 'Enabled=1 ORDER BY Description'); 199 200 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Measure` WHERE `Enabled`=1'); 201 $DbRow = $DbResult->fetch_row(); 202 $PageList = GetPageList($DbRow[0]); 203 204 $Output = $PageList['Output']; 205 $Output .= '<table class="WideTable" style="font-size: small;">'; 206 207 $TableColumns = array( 208 array('Name' => 'Name', 'Title' => 'Měřená veličina'), 209 array('Name' => 'LastValue', 'Title' => 'Poslední hodnota'), 210 array('Name' => 'LastValueTime', 'Title' => 'Čas posledního měření'), 211 array('Name' => 'Continuous', 'Title' => 'Interpolace'), 212 array('Name' => 'Description', 'Title' => 'Popis'), 213 ); 214 if(array_key_exists('Debug', $_GET)) 215 { 216 $TableColumns[] = array('Name' => 'ItemCount', 'Title' => 'Počet položek'); 217 $TableColumns[] = array('Name' => 'MeasureDuration', 'Title' => 'Čas vykonání'); 218 } 219 $Order = GetOrderTableHeader($TableColumns, 'Name', 0); 220 $Output .= $Order['Output']; 221 222 $Result = $this->Database->select('Measure', '*', '`Enabled`=1 '.$Order['SQL'].$PageList['SQLLimit']); 205 223 while($Measure = $Result->fetch_array()) 206 224 { 207 $DbResult2 = $this->Database->select('MeasureMethod', '*', ' Id='.$Measure['Method']);225 $DbResult2 = $this->Database->select('MeasureMethod', '*', '`Id`='.$Measure['Method']); 208 226 $MeasureMethod = $DbResult2->fetch_assoc(); 209 227 $StopWatchStart = GetMicrotime(); … … 234 252 } 235 253 $Output .= '</table>'; 254 $Output .= $PageList['Output']; 236 255 //echo(time()); 237 256 //print_r(gd_info()); … … 240 259 //ShowPage($Output); 241 260 //echo($PrefixMultiplier->Add('-0.000000071112345', 'B')); 261 $Output .= '</div>'; 242 262 return($Output); 243 263 } 244 264 } 265 266 class PageMeasureAddValue extends Page 267 { 268 function Show() 269 { 270 $this->ClearPage = true; 271 272 $Output = ''; 273 if(!array_key_exists('MeasureId', $_GET)) return('Nebylo zadáno Id měření.'); 274 if(!array_key_exists('Value', $_GET)) return('Nebyla zadána hodnota.'); 275 $Measure = new Measure($this->System); 276 $Measure->Load($_GET['MeasureId']); 277 if(!isset($Measure->Data['Id'])) return('Měření s Id '.$_GET['MeasureId'].' nenalezeno.'); 278 $Measure->AddValue(array('Min' => $_GET['Value'], 'Avg' => $_GET['Value'], 'Max' => $_GET['Value'])); 279 return($Output); 280 } 281 } -
trunk/Modules/TimeMeasure/Measure.php
r655 r656 39 39 } 40 40 41 42 41 function AddValue($Value = array('Min' => 0, 'Avg' => 0, 'Max' => 0), $Level = 0, $Time = 0) 43 42 { 44 43 if($Time == 0) $Time = time(); 45 //$Value = round($Measure['divider'] * $Value); 46 //echo(TimeToMysqlDateTime($Time).'|'.$Level."\n"); 47 48 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2'); 49 //echo($Database->LastQuery."\n"); 44 45 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='. 46 $this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2'); 50 47 if($Result->num_rows == 0) 51 48 { 52 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => 0)); 53 //echo($Database->LastQuery."\n"); 49 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 50 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 51 'Measure' => $this->Data['Id'], 'Time' => TimeToMysqlDateTime($Time), 'Continuity' => 0)); 54 52 } else if($Result->num_rows == 1) 55 53 { 56 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => 1)); 57 //echo($Database->LastQuery."\n"); 54 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 55 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 56 'Measure' => $this->Data['Id'], 'Time' => TimeToMysqlDateTime($Time), 'Continuity' => 1)); 58 57 } else 59 58 { 60 59 $LastValue = $Result->fetch_assoc(); 61 60 $NextToLastValue = $Result->fetch_assoc(); 62 //echo($Level.': '.$Time.' - '.MysqlDateTimeToTime($LastValue['Time']).' '.($Time - MysqlDateTimeToTime($LastValue['Time'])).' = '.$Measure['Period']."\n");63 61 if((($Time - MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0)) 64 62 { 65 echo('Too short period \n');63 echo('Too short period. Minimal period is '.(0.75 * $this->Data['Period'])." seconds\n"); 66 64 } else 67 65 { 68 66 if(($Time - MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1; 69 67 else $Continuity = 0; 70 echo('('.$LastValue['Avg'].'=='.$NextToLastValue['Avg'].') and ('.$LastValue['Avg'].' == '.$Value.') and ('.$LastValue['Continuity'].' == 1) and ('.$Continuity.' == 1))'."\n"); 71 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)) 72 { 73 $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$this->Data['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time))); 74 //echo($this->Database->LastQuery."\n"); 68 if(($LastValue['Min'] == $NextToLastValue['Min']) and ($LastValue['Min'] == 69 $Value['Min']) and ($LastValue['Avg'] == $NextToLastValue['Avg']) and 70 ($LastValue['Avg'] == $Value['Avg']) and ($LastValue['Max'] == $NextToLastValue['Max']) 71 and ($LastValue['Max'] == $Value['Max']) and ($LastValue['Continuity'] == 1) and ($Continuity == 1)) 72 { 73 $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time']. 74 '") AND (Level='.$Level.') AND (Measure='.$this->Data['Id'].')', array('Time' => TimeToMysqlDateTime($Time))); 75 75 } else 76 76 { 77 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => $Continuity)); 77 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 78 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 79 'Measure' => $this->Data['Id'], 'Time' => TimeToMysqlDateTime($Time), 'Continuity' => $Continuity)); 78 80 } 79 81 } … … 83 85 { 84 86 $Level = $Level + 1; 85 //echo('Level '.$Level."<br>\n");86 87 $TimeSegment = $this->TimeSegment($this->Data['Period'], 1); 87 88 $EndTime = $this->AlignTime($Time, $TimeSegment); … … 89 90 $StartTime = $EndTime - $TimeSegment; 90 91 91 //echo(" ".$TimeSegment." ".$StartTime.'-'.$EndTime."<br>\n");92 //flush();93 94 92 // Load values in time range 95 93 $Values = array(); 96 94 //.'" AND Time < "'.TimeToMysqlDateTime($EndTime).'" AND Measure='.$Measure['Id'].' AND Level='.($Level - 1).' ORDER BY Time'); 97 $Result = $this->Database->select($this->Data['DataTable'], '*', '(Time > "'.TimeToMysqlDateTime($StartTime).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($EndTime).'") AND (Measure='.$this->Data['Id'].') AND (Level='.($Level - 1).') ORDER BY Time'); 95 $Result = $this->Database->select($this->Data['DataTable'], '*', '(Time > "'. 96 TimeToMysqlDateTime($StartTime).'") AND (Time < "'.TimeToMysqlDateTime($EndTime). 97 '") AND (Measure='.$this->Data['Id'].') AND (Level='.($Level - 1).') ORDER BY Time'); 98 98 while($Row = $Result->fetch_assoc()) 99 99 { … … 103 103 //if(count($Values) > 2) 104 104 { 105 //print_r($Values);106 105 //array_pop($Values); 107 106 108 107 // Load subsidary values 109 print_r($Values); 110 $Values = array_merge($this->LoadLeftSideValue($Level - 1, $this->Data, 108 $Values = array_merge($this->LoadLeftSideValue($Level - 1, 111 109 $StartTime), $Values, $this->LoadRightSideValue($Level - 1, $EndTime)); 112 print_r($Values);113 110 114 111 $Point = $this->ComputeOneValue($StartTime, $EndTime, $Values, $Level); 115 //print_r($Point);116 112 117 113 $this->Database->delete($this->Data['DataTable'], '(Time > "'.TimeToMysqlDateTime($StartTime). … … 128 124 { 129 125 $Y = ($Y2 - $Y1) / ($X2 - $X1) * ($X - $X1) + $Y1; 130 //echo($Y1.'-'.$Y.'-'.$Y2.' '.$X1.'-'.$X.'-'.$X2.'<br>');131 126 return($Y); 132 127 } … … 186 181 else if($ValueType == 'Min') 187 182 { 188 //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>');189 183 if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']) 190 184 { … … 210 204 } 211 205 return($NewValue); 212 //echo($NewValue['avg'].'<br>');213 //return(array('min' => rand(0,1), 'avg' => $NewValue['avg'], 'max' => rand(0,1)));214 206 } 215 207 … … 217 209 { 218 210 // Get first and last time 219 //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n");220 211 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time LIMIT 1'); 221 212 if($Result->num_rows > 0) … … 269 260 { 270 261 $Result = array(); 271 //echo('SELECT * FROM '.StatTableName($Level). ' WHERE '. 'Time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY Time DESC LIMIT 1'."<br>\n");272 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.'ORDER BY Time DESC LIMIT 1');262 $DbResult = $this->Database->select($this->Data['DataTable'], '*', '(Time < "'. 263 TimeToMysqlDateTime($Time).'") AND (Measure='.$this->Data['Id'].') AND (Level='.$Level.') ORDER BY Time DESC LIMIT 1'); 273 264 if($DbResult->num_rows > 0) 274 265 { … … 289 280 array_push($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) - 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 290 281 } 291 // if($Debug) print_r($Result);292 282 return($Result); 293 283 } … … 330 320 { 331 321 $Values = array_merge($this->LoadLeftSideValue($Level, $TimeFrom), $Values, $this->LoadRightSideValue($Level, $TimeTo)); 332 //echo(count($Values).'<br>');333 //echo($TimeFrom.','.$TimeTo.'<br>');334 //echo($Values[0]['Time'].'<br>');335 322 $StartIndex = 0; 336 323 $Points = array(); 337 //echo($DivisionCount.'<br>');338 324 if($this->Debug) print_r($Values); 339 //die();340 325 for($I = 0; $I < $this->DivisionCount; $I++) 341 326 { 342 327 $TimeStart = $TimeFrom + (($TimeTo - $TimeFrom) / $this->DivisionCount) * $I; 343 //if($Debug) echo('TimeStart '.$I.': '.$TimeStart.'('.TimeToMysqlDateTime($TimeStart).')<br>');344 328 $TimeEnd = $TimeFrom + (($TimeTo - $TimeFrom) / $this->DivisionCount) * ($I + 1); 345 if($this->Debug) echo('TimeEnd '.$I.': '.$TimeEnd.'('.$this->Database->TimeToMysqlDateTime($TimeEnd).')<br>'); 346 //echo($TimeStart.','.$TimeEnd.'<br>'); 329 if($this->Debug) echo('TimeEnd '.$I.': '.$TimeEnd.'('.TimeToMysqlDateTime($TimeEnd).')<br>'); 347 330 348 331 $EndIndex = $StartIndex; … … 350 333 //while(($Values[$EndIndex]['Time'] < $TimeEnd)) $EndIndex = $EndIndex + 1; 351 334 $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1); 352 //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br>');353 //print_r($SubValues);354 335 $Points[] = $this->ComputeOneValue($TimeStart, $TimeEnd, $SubValues, $Level); 355 336 $StartIndex = $EndIndex - 1; … … 362 343 function RebuildMeasureCache() 363 344 { 364 echo('Veli cina '.$this->Data['Name']."<br>\n");345 echo('Veličina '.$this->Data['Name']."<br>\n"); 365 346 if($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0; // non continuous 366 347 else $this->Data['ContinuityEnabled'] = 2; // continuous graph … … 377 358 echo('Uroven '.$Level."<br>\n"); 378 359 $TimeRange = $this->GetTimeRange($Level - 1); 379 //echo($Measure['Id'].','.($Level-1)."\n");380 //echo(TimeToMysqlDateTime($TimeRange['left']).'-'.TimeToMysqlDateTime($TimeRange['right'])."\n");381 360 $TimeSegment = $this->TimeSegment($this->Data['Period'], $Level); 382 361 $StartTime = $this->AlignTime($TimeRange['Left'], $TimeSegment) - $TimeSegment; … … 390 369 $EndTime2 = $StartTime + ($I + 1) * $BurstCount * $TimeSegment; 391 370 $Values = array(); 392 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.$this->Database->TimeToMysqlDateTime($StartTime2).'" AND Time < "'.$this->Database->TimeToMysqlDateTime($EndTime2).'" AND Measure='.$Measure['Id'].' AND Level='.($Level - 1).' ORDER BY Time'); 371 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'. 372 TimeToMysqlDateTime($StartTime2).'" AND Time < "'.TimeToMysqlDateTime($EndTime2).'" AND Measure='.$this->Data['Id'].' AND Level='.($Level - 1).' ORDER BY Time'); 393 373 while($Row = $DbResult->fetch_assoc()) 394 374 { … … 399 379 if(count($Values) > 0) 400 380 { 401 $Values = array_merge($this->LoadLeftSideValue($Level - 1, $StartTime2), $Values, $this->LoadRightSideValue($Level - 1, $Measure, $EndTime2)); 381 $Values = array_merge($this->LoadLeftSideValue($Level - 1, $StartTime2), 382 $Values, $this->LoadRightSideValue($Level - 1, $this->Data, $EndTime2)); 402 383 403 384 $StartIndex = 0; … … 411 392 while($Values[$EndIndex]['Time'] < $EndTime3) $EndIndex = $EndIndex + 1; 412 393 $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1); 413 //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br>');414 //print_r($SubValues);415 394 if(count($SubValues) > 2) 416 395 { 417 396 $Point = $this->ComputeOneValue($StartTime3, $EndTime3, $SubValues, $Level); 418 397 $Continuity = $SubValues[1]['Continuity']; 419 $this->Database->insert($this->Data['DataTable'], array('Level' => $Level, 'Measure' => $this->Data['Id'], 'Min' => $Point['Min'], 'Avg' => $Point['avg'], 'max' => $Point['Max'], 'Continuity' => $Continuity, 'Time' => $this->Database->TimeToMysqlDateTime($StartTime3 + ($EndTime3 - $StartTime3) / 2))); 398 $this->Database->insert($this->Data['DataTable'], array('Level' => $Level, 399 'Measure' => $this->Data['Id'], 'Min' => $Point['Min'], 'Avg' => $Point['avg'], 400 'max' => $Point['Max'], 'Continuity' => $Continuity, 'Time' => 401 TimeToMysqlDateTime($StartTime3 + ($EndTime3 - $StartTime3) / 2))); 420 402 } 421 403 $StartIndex = $EndIndex - 1; -
trunk/Modules/TimeMeasure/TimeMeasure.php
r655 r656 30 30 $this->System->RegisterPage('grafy', 'PageMeasure'); 31 31 $this->System->RegisterPage(array('grafy', 'graf.png'), 'PageGraph'); 32 $this->System->RegisterPage(array('grafy', 'add.php'), 'PageMeasureAddValue'); 32 33 $this->System->FormManager->RegisterClass('Measure', array( 33 34 'Title' => 'Měření',
Note:
See TracChangeset
for help on using the changeset viewer.