Changeset 655 for trunk/Modules/TimeMeasure
- Timestamp:
- May 11, 2014, 4:28:01 PM (11 years ago)
- Location:
- trunk/Modules/TimeMeasure
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/TimeMeasure/Graph.php
r569 r655 1 1 <?php 2 2 3 class GraphView extends View3 class PageGraph extends Page 4 4 { 5 var $FontSize; 6 var $FontFileName; 7 var $ValueToImageHeigthCoefficient; 8 var $DefaultWidth; 9 var $DefaultHeight; 10 11 function __construct($System) 12 { 13 parent::__construct($System); 14 $this->FontSize = 10; 15 $this->FontFileName = 'Arial.ttf'; 16 $this->ValueToImageHeigthCoefficient = 0.9; 17 } 18 19 function Show() 20 { 21 $this->ClearPage = true; 22 return($this->Render()); 23 } 24 5 25 function Render() 6 26 { 7 if(array_key_exists('Debug', $_GET)) $Debug = $_GET['Debug']; 27 $PrefixMultiplier = new PrefixMultiplier(); 28 29 if(array_key_exists('Debug', $_GET)) $Debug = $_GET['Debug']; 8 30 else $Debug = 0; 9 31 10 32 if(!array_key_exists('From', $_GET)) die('Musíte zadat čas počátku'); 11 33 $StartTime = addslashes($_GET['From']); … … 15 37 $TimeDifference = $EndTime - $StartTime; 16 38 if(!array_key_exists('Measure', $_GET)) die('Musíte zadat měřenou veličinu'); 17 $MeasureId = addslashes($_GET['Measure']); 18 if(!array_key_exists('Width', $_GET)) $Width = $ DefaultWidth;39 $MeasureId = addslashes($_GET['Measure']); 40 if(!array_key_exists('Width', $_GET)) $Width = $this->DefaultWidth; 19 41 else $Width = addslashes($_GET['Width']); 20 if(!array_key_exists('Height', $_GET)) $Height = $ DefaultHeight;42 if(!array_key_exists('Height', $_GET)) $Height = $this->DefaultHeight; 21 43 else $Height = addslashes($_GET['Height']); 22 44 if(!array_key_exists('Differential', $_GET)) $Differential = $this->Config['Application']['DefaultVariables']['Differential']; 23 45 else $Differential = addslashes($_GET['Differential']); 24 $VerticalLinesCount = round($Height / ($this-> Config['Application']['FontSize']+ 4));25 26 $StopWatchStart = $this->System->GetMicrotime();46 $VerticalLinesCount = round($Height / ($this->FontSize + 4)); 47 48 $StopWatchStart = GetMicrotime(); 27 49 28 50 $Measure = new Measure($this->System); 29 51 $Measure->Load($MeasureId); 30 $Measure->LevelReducing = $this->Config['Application']['LevelReducing'];31 $Measure->ReferenceTime = $this->Config['Application']['ReferenceTime'];32 $Measure->MaxLevel = $this->Config['Application']['MaxLevel'];33 $Measure->DivisionCount = $this->Config['Application']['DivisionCount'];34 $Measure->Differential = $this->Config['Application']['DefaultVariables']['Differential'];52 //$Measure->LevelReducing = $this->LevelReducing; 53 //$Measure->ReferenceTime = $this->Config['Application']['ReferenceTime']; 54 //$Measure->MaxLevel = $this->Config['Application']['MaxLevel']; 55 //$Measure->DivisionCount = $this->Config['Application']['DivisionCount']; 56 //$Measure->Differential = $this->Config['Application']['DefaultVariables']['Differential']; 35 57 $Measure->Debug = $Debug; 36 58 $DbResult2 = $this->Database->select('MeasureMethod', '*', 'Id='.$Measure->Data['Method']); 37 59 $MeasureMethod = $DbResult2->fetch_assoc(); 38 60 39 $FontSize = $this-> Config['Application']['FontSize'];40 $FontFile = dirname(__FILE__).'/../ Style/'.$this->Config['System']['Style'].'/'.$this->Config['Application']['FontFileName'];61 $FontSize = $this->FontSize; 62 $FontFile = dirname(__FILE__).'/../../style/'.$this->System->Config['Web']['Style'].'/'.$this->FontFileName; 41 63 42 64 $Level = floor(log(($EndTime - $StartTime) / $Measure->DivisionCount / 60) / log($Measure->LevelReducing)) - 1; … … 47 69 $Points = $Measure->GetValues($StartTime, $EndTime, $Level); 48 70 49 if($Debug) echo('Points count: '.count($Points).'<br/>'); 50 //if($Debug) foreach($Points as $Index => $Item) 71 if($Debug) echo('Points count: '.count($Points).'<br/>'); 72 //if($Debug) foreach($Points as $Index => $Item) 51 73 // echo($Index.': '.$Item['min'].'<br>'); 52 74 … … 70 92 $AvgValue = $AvgValue / count($Points); //round( * $Measure['Divider']) / $Measure['Divider']; 71 93 72 // Generate polygon and recalculate y values to fit graph height 94 // Generate polygon and recalculate y values to fit graph height 73 95 $PointsMin = array(0, $Height - 1); 74 96 $PointsAvg = array(0, $Height - 1); 75 97 $PointsMax = array(0, $Height - 1); 76 98 if(($MaxValue - $MinValue) == 0) $MaxValue = $MinValue + 1; 77 { 99 { 78 100 foreach($Points as $Index => $Item) 79 101 { 80 102 $PointsMin[] = $Index * $Width / $Measure->DivisionCount; 81 $PointsMin[] = $Height - 1 - ($Points[$Index]['Min'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this-> Config['Application']['ValueToImageHeigthCoefficient'];103 $PointsMin[] = $Height - 1 - ($Points[$Index]['Min'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 82 104 $PointsAvg[] = $Index * $Width / $Measure->DivisionCount; 83 $PointsAvg[] = $Height - 1 - ($Points[$Index]['Avg'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this-> Config['Application']['ValueToImageHeigthCoefficient'];105 $PointsAvg[] = $Height - 1 - ($Points[$Index]['Avg'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 84 106 $PointsMax[] = $Index * $Width / $Measure->DivisionCount; 85 $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this-> Config['Application']['ValueToImageHeigthCoefficient'];107 $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 86 108 //echo($Index.' - '.$Item.' '.$Points[$Index].'<br>'); 87 109 } … … 107 129 108 130 //print_r($PointsMax); 109 131 110 132 // Generate image 111 if(!$Debug) 133 if(!$Debug) 112 134 { 113 135 Header('Content-type: image/png'); 114 Header('Cache-Control: no-cache'); // Dynamic graph - no cache 136 Header('Cache-Control: no-cache'); // Dynamic graph - no cache 115 137 $Image = @imagecreate($Width, $Height); 116 138 $BackgroundColor = imagecolorallocate($Image, 255, 255, 255); … … 129 151 imagefilledpolygon($Image, $PointsAvg, count($PointsAvg) / 2, $LightGreen); 130 152 imagefilledpolygon($Image, $PointsMin, count($PointsMin) / 2, $LightBlue); 131 153 132 154 $TimeMarks = array(1, 60, 60*60, 60*60*24, 60*60*24*7, 60*60*24*30, 60*60*24*365, 60*60*24*365*10); 133 155 134 156 $TimeRange = $EndTime - $StartTime; 135 157 $TimeMarksIndex = 0; … … 137 159 if($TimeMarksIndex < 2) $TimeMarksIndex = 2; 138 160 $MajorTimeMarks = $TimeMarks[$TimeMarksIndex - 1]; 139 $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2]; 140 141 $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime; 161 $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2]; 162 163 $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime; 142 164 //imagestring($Image, 10, 40, 50, $TimeShift, $Black); 143 165 144 166 // Zobraz měřítko Y 145 167 $VerticalLinesDistance = $Height / $VerticalLinesCount; … … 149 171 for($X = 1; $X < $Width; $X = $X + 3) imagesetpixel($Image, $X, $Y, $Gray); 150 172 //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED); 151 } 152 153 $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime; 154 173 } 174 175 $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime; 176 155 177 // Zobraz měřítko X 156 178 $LastTextEnd = 0; 157 179 for($Time = $StartTime; $Time < $EndTime; $Time += $MajorTimeMarks) 158 180 { 159 $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width; 181 $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width; 160 182 //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED); 161 183 if(($MajorTimeMarks > 60 * 60 * 24)) $Text = date('j.n.Y', $Time + $TimeShift); … … 169 191 } 170 192 else for($Y = 0; $Y < $Height; $Y = $Y + 3) imagesetpixel($Image, $X, $Y, $Gray); 171 } 172 193 } 194 173 195 // Popisky osy Y 174 196 for($I = 1; $I <= $VerticalLinesCount; $I++) 175 197 { 176 198 $Y = $Height - 1 - ($VerticalLinesDistance * $I); 177 //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) * $this->Config['Application']['ValueToImageHeigthCoefficient'] * $Height); 178 $Text = $this->System->AddPrefixMultipliers(round(($I * $VerticalLinesDistance / $Height / $this->Config['Application']['ValueToImageHeigthCoefficient'] * ($MaxValue - $MinValue) + $MinValue)), $MeasureMethod['Unit'], 3); 199 //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) * 200 // $this->ValueToImageHeigthCoefficient * $Height); 201 $Text = $PrefixMultiplier->Add(round(($I * $VerticalLinesDistance / $Height / 202 $this->ValueToImageHeigthCoefficient * ($MaxValue - $MinValue) + $MinValue)), $MeasureMethod['Unit'], 3); 179 203 $BoundBox = imagettfbbox($FontSize, 0, $FontFile, $Text); 180 204 if(($Y - ($BoundBox[5] - $BoundBox[1]) / 2) > 10) 181 205 imagettftext($Image, $FontSize, 0, 2, $Y - ($BoundBox[5] - $BoundBox[1]) / 2, $Black, $FontFile, $Text); 182 } 183 $GenerationTime = floor(( $this->System->GetMicrotime() - $StopWatchStart) * 1000 ) / 1000;206 } 207 $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000 ) / 1000; 184 208 185 209 $Left = $Width - 10; 186 $Text = ' Max. '.$ this->System->AddPrefixMultipliers($MaxValue, $MeasureMethod['Unit']);210 $Text = ' Max. '.$PrefixMultiplier->Add($MaxValue, $MeasureMethod['Unit']); 187 211 $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text); 188 212 $Left -= ($BoundingBox[2] - $BoundingBox[0]); 189 213 imagettftext($Image, $FontSize, 0, $Left, 14, $Red, $FontFile, $Text); 190 214 191 $Text = ' Avg. '.$ this->System->AddPrefixMultipliers($AvgValue, $MeasureMethod['Unit']);215 $Text = ' Avg. '.$PrefixMultiplier->Add($AvgValue, $MeasureMethod['Unit']); 192 216 $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text); 193 217 $Left -= ($BoundingBox[2] - $BoundingBox[0]); 194 218 imagettftext($Image, $FontSize, 0, $Left, 14, $Green, $FontFile, $Text); 195 219 196 $Text = ' Min. '.$ this->System->AddPrefixMultipliers($MinValue, $MeasureMethod['Unit']);220 $Text = ' Min. '.$PrefixMultiplier->Add($MinValue, $MeasureMethod['Unit']); 197 221 $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text); 198 222 $Left -= ($BoundingBox[2] - $BoundingBox[0]); … … 205 229 imagepng($Image); 206 230 imagedestroy($Image); 207 } 231 } 208 232 } 209 233 } -
trunk/Modules/TimeMeasure/Main.php
r577 r655 3 3 class PageMeasure extends Page 4 4 { 5 var $Months = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'); 6 7 var $GraphTimeRanges = array 5 var $Months; 6 var $GraphTimeRanges; 7 var $DefaultVariables; 8 var $ImageHeight; 9 var $ImageWidth; 10 11 function __construct($System) 12 { 13 parent::__construct($System); 14 $this->ShortTitle = 'Grafy'; 15 $this->FullTitle = 'Časové grafy veličin'; 16 $this->ImageWidth = 800; 17 $this->ImageHeight = 200; 18 $this->ParentClass = 'PagePortal'; 19 $this->DefaultVariables = array( 20 'TimeSpecify' => 0, 21 'Period' => 'day', 22 'Measure' => 1, 23 'Differential' => 0, 24 ); 25 $this->Months = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 26 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'); 27 $this->GraphTimeRanges = array 8 28 ( 9 29 'hour' => array( … … 22 42 'caption' => 'Měsíc', 23 43 'period' => 2592000, // 3600 * 24 * 30, 24 ), 44 ), 25 45 'year' => array( 26 46 'caption' => 'Rok', … … 32 52 ), 33 53 ); 54 } 34 55 35 56 function EditTime($Time) … … 44 65 for($I = 1; $I < 32; $I++) 45 66 { 46 if($I == $TimeParts['mday']) $Selected = ' selected="1"'; else $Selected = ''; 67 if($I == $TimeParts['mday']) $Selected = ' selected="1"'; else $Selected = ''; 47 68 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>'; 48 69 } … … 52 73 $Output .= '<select name="Month">'; 53 74 foreach($this->Months as $Index => $Month) 54 { 75 { 55 76 if($Index == $TimeParts['mon']) $Selected = ' selected="1"'; else $Selected = ''; 56 77 if($Index > 0) $Output .= '<option value="'.$Index.'"'.$Selected.'>'.$Month.'</option>'; … … 61 82 $Output .= '<select name="Year">'; 62 83 for($I = 2000; $I < 2010; $I++) 63 { 84 { 64 85 if($I == $TimeParts['year']) $Selected = ' selected="1"'; else $Selected = ''; 65 86 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>'; … … 70 91 $Output .= '<select name="Hour">'; 71 92 for($I = 0; $I < 24; $I++) 72 { 93 { 73 94 if($I == $TimeParts['hours']) $Selected = ' selected="1"'; else $Selected = ''; 74 95 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>'; … … 78 99 // Minute selection 79 100 $Output .= '<select name="Minute">'; 80 for($I = 0; $I < 60; $I++) 101 for($I = 0; $I < 60; $I++) 81 102 { 82 103 if($I == $TimeParts['minutes']) $Selected = ' selected="1"'; else $Selected = ''; … … 98 119 $Debug = 0; 99 120 100 foreach($this-> System->Config['Application']['DefaultVariables']as $Index => $Variable)121 foreach($this->DefaultVariables as $Index => $Variable) 101 122 { 102 123 if(!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable; … … 110 131 $_SESSION['TimeEnd'] = time() - 60; 111 132 $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GraphTimeRanges[$_SESSION['Period']]['period']; 112 } 113 114 $Output = ' <div class="Title">Statistiky</div>';133 } 134 135 $Output = ''; 115 136 116 137 if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = ''; … … 128 149 } 129 150 } 130 break; 151 break; 131 152 case 'SetTimeNow': 132 if(array_key_exists('Time', $_GET)) 153 if(array_key_exists('Time', $_GET)) 133 154 { 134 155 if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd')) … … 160 181 $Output .= '<br/>'.$this->MeasureTable(); 161 182 return($Output); 162 } 163 183 } 184 164 185 function Graph() 165 186 { 166 187 $Output = '<strong>Graf:</strong><br/>'; 167 $Output .= '<img alt="Graf" src="?M=Graph&Measure='.$_SESSION['Measure'].'&From='.$_SESSION['TimeStart'].'&To='.$_SESSION['TimeEnd'].'&Width='.$this->Config['Application']['GraphSize']['Width'].'&Height='.$this->Config['Application']['GraphSize']['Height'].'&Differential='.$_SESSION['Differential'].'" width="'.$this->Config['Application']['GraphSize']['Width'].'" height="'.$this->Config['Application']['GraphSize']['Height'].'"><br>'; 168 $Output .= '<a href="?Measure='.$_SESSION['Measure'].'&TimeStart='.$_SESSION['TimeStart'].'&TimeEnd='.$_SESSION['TimeEnd'].'&TimeSpecify=1&Differential='.$_SESSION['Differential'].'">Odkaz na vybraný graf</a><br>'; 169 return($Output); 170 } 171 188 $Output .= '<img alt="Graf" src="'.$this->System->Link('/grafy/graf.png?Measure='.$_SESSION['Measure']. 189 '&From='.$_SESSION['TimeStart'].'&To='.$_SESSION['TimeEnd'].'&Width='. 190 $this->ImageWidth.'&Height='.$this->ImageHeight.'&Differential='. 191 $_SESSION['Differential']).'" width="'.$this->ImageWidth.'" height="'.$this->ImageHeight.'"><br>'; 192 $Output .= '<a href="?Measure='.$_SESSION['Measure'].'&TimeStart='. 193 $_SESSION['TimeStart'].'&TimeEnd='.$_SESSION['TimeEnd'].'&TimeSpecify=1&Differential='.$_SESSION['Differential'].'">Odkaz na vybraný graf</a><br>'; 194 return($Output); 195 } 196 172 197 function MeasureTable() 173 198 { 199 $PrefixMultiplier = new PrefixMultiplier(); 174 200 $Output = '<table border="1" cellspacing="0" cellpadding="2" style="font-size: small;">'; 175 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>'; … … 181 207 $DbResult2 = $this->Database->select('MeasureMethod', '*', 'Id='.$Measure['Method']); 182 208 $MeasureMethod = $DbResult2->fetch_assoc(); 183 $StopWatchStart = $this->System->GetMicrotime();209 $StopWatchStart = GetMicrotime(); 184 210 if(array_key_exists('Debug', $_GET)) 185 211 { … … 192 218 { 193 219 $Row = $Result2->fetch_array(); 194 $LastMeasureTime = date('j.n.Y G:i:s', $this->Database->MysqlDateTimeToTime($Row['Time']));195 $LastMeasureValue = $ this->System->AddPrefixMultipliers($Row['Avg'], $MeasureMethod['Unit']);220 $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['Time'])); 221 $LastMeasureValue = $PrefixMultiplier->Add($Row['Avg'], $MeasureMethod['Unit']); 196 222 } else 197 223 { … … 199 225 $LastMeasureValue = ' '; 200 226 } 201 if($Measure['Continuity'] == 1) $Interpolate = 'Ano'; 227 if($Measure['Continuity'] == 1) $Interpolate = 'Ano'; 202 228 else $Interpolate = 'Ne'; 203 if($Measure['Info'] == '') $Measure['Info'] = ' ';204 $GenerationTime = floor(( $this->System->GetMicrotime() - $StopWatchStart) * 1000 ) / 1000;229 //if($Measure['Description'] == '') $Measure['Description'] = ' '; 230 $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000 ) / 1000; 205 231 $Output .= '<tr><td><a href="?Measure='.$Measure['Id'].'&Differential=0">'.$Measure['Name'].'</a></td><td align="center">'.$LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'.$Interpolate.'</td><td>'.$Measure['Description'].'</td>'; 206 232 if(array_key_exists('Debug', $_GET)) $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>'; … … 211 237 //print_r(gd_info()); 212 238 //print_r($_SESSION); 213 239 214 240 //ShowPage($Output); 215 //echo( AddPrefixMultipliers('-0.000000071112345', 'B'));241 //echo($PrefixMultiplier->Add('-0.000000071112345', 'B')); 216 242 return($Output); 217 243 } -
trunk/Modules/TimeMeasure/Measure.php
r569 r655 11 11 var $DivisionCount = 500; 12 12 var $ValueTypes = array('Min', 'Avg', 'Max'); 13 13 14 14 function Load($Id) 15 15 { … … 22 22 } else throw new Exception('Measure not found'); 23 23 } 24 24 25 25 function TimeSegment($Base, $Level) 26 26 { … … 48 48 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2'); 49 49 //echo($Database->LastQuery."\n"); 50 if($Result->num_rows == 0) 51 { 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)); 50 if($Result->num_rows == 0) 51 { 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 53 //echo($Database->LastQuery."\n"); 54 54 } else if($Result->num_rows == 1) … … 61 61 $NextToLastValue = $Result->fetch_assoc(); 62 62 //echo($Level.': '.$Time.' - '.MysqlDateTimeToTime($LastValue['Time']).' '.($Time - MysqlDateTimeToTime($LastValue['Time'])).' = '.$Measure['Period']."\n"); 63 if((($Time - $this->Database->MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0))64 { 63 if((($Time - MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0)) 64 { 65 65 echo('Too short period\n'); 66 66 } else 67 67 { 68 if(($Time - $this->Database->MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1;68 if(($Time - MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1; 69 69 else $Continuity = 0; 70 70 echo('('.$LastValue['Avg'].'=='.$NextToLastValue['Avg'].') and ('.$LastValue['Avg'].' == '.$Value.') and ('.$LastValue['Continuity'].' == 1) and ('.$Continuity.' == 1))'."\n"); 71 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 72 { 73 $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$ Measure['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time)));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 74 //echo($this->Database->LastQuery."\n"); 75 75 } else … … 77 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)); 78 78 } 79 } 79 } 80 80 81 81 // Update next level … … 95 95 $Values = array(); 96 96 //.'" AND Time < "'.TimeToMysqlDateTime($EndTime).'" AND Measure='.$Measure['Id'].' AND Level='.($Level - 1).' ORDER BY Time'); 97 $Result = $this->Database->select($this->Data['DataTable'], '*', '(Time > "'. $this->Database->TimeToMysqlDateTime($StartTime).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($EndTime).'") AND (Measure='.$this->Data['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'); 98 98 while($Row = $Result->fetch_assoc()) 99 99 { 100 $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);100 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 101 101 $Values[] = $Row; 102 102 } … … 108 108 // Load subsidary values 109 109 print_r($Values); 110 $Values = array_merge($this->LoadLeftSideValue($Level - 1, $this->Data, $StartTime), $Values, $this->LoadRightSideValue($Level - 1, $EndTime)); 110 $Values = array_merge($this->LoadLeftSideValue($Level - 1, $this->Data, 111 $StartTime), $Values, $this->LoadRightSideValue($Level - 1, $EndTime)); 111 112 print_r($Values); 112 113 … … 114 115 //print_r($Point); 115 116 116 $this->Database->delete($this->Data['DataTable'], '(Time > "'.$this->Database->TimeToMysqlDateTime($StartTime).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($EndTime).'") AND Measure='.$this->Data['Id'].' AND Level='.$Level); 117 $this->Database->delete($this->Data['DataTable'], '(Time > "'.TimeToMysqlDateTime($StartTime). 118 '") AND (Time < "'.TimeToMysqlDateTime($EndTime).'") AND Measure='.$this->Data['Id'].' AND Level='.$Level); 117 119 $this->Data['Period'] = $TimeSegment; 118 $this->AddValue(array('Min' => $Point['Min'], 'Avg' => $Point['Avg'], 'Max' => $Point['Max']), $Level, $StartTime + ($EndTime - $StartTime) / 2); 120 $this->AddValue(array('Min' => $Point['Min'], 'Avg' => $Point['Avg'], 121 'Max' => $Point['Max']), $Level, $StartTime + ($EndTime - $StartTime) / 2); 119 122 } 120 123 } … … 180 183 } 181 184 } 182 } 183 else if($ValueType == 'Min') 184 { 185 //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>'); 185 } 186 else if($ValueType == 'Min') 187 { 188 //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>'); 186 189 if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']) 187 190 { … … 201 204 $NewValue[$ValueType] = $NewValue[$ValueType]; 202 205 } 203 //if(($RightTime - $LeftTime) > 0) 204 if($this->Data['Cumulative'] == 0) 206 //if(($RightTime - $LeftTime) > 0) 207 if($this->Data['Cumulative'] == 0) 205 208 { 206 209 $NewValue['Avg'] = $NewValue['Avg'] / ($RightTime - $LeftTime); … … 214 217 { 215 218 // Get first and last time 216 //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n"); 219 //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n"); 217 220 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time LIMIT 1'); 218 221 if($Result->num_rows > 0) … … 229 232 } else $AbsoluteRightTime = 0; 230 233 231 if($this->Debug) 232 { 233 echo('AbsoluteLeftTime: '.$AbsoluteLeftTime.'('. $this->Database->TimeToMysqlDateTime($AbsoluteLeftTime).')<br>');234 echo('AbsoluteRightTime: '.$AbsoluteRightTime.'('. $this->Database->TimeToMysqlDateTime($AbsoluteRightTime).')<br>');234 if($this->Debug) 235 { 236 echo('AbsoluteLeftTime: '.$AbsoluteLeftTime.'('.TimeToMysqlDateTime($AbsoluteLeftTime).')<br>'); 237 echo('AbsoluteRightTime: '.$AbsoluteRightTime.'('.TimeToMysqlDateTime($AbsoluteRightTime).')<br>'); 235 238 } 236 239 return(array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime)); … … 238 241 239 242 function LoadRightSideValue($Level, $Time) 240 { 243 { 241 244 $Result = array(); 242 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'. $this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1');245 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1'); 243 246 if($DbResult->num_rows > 0) 244 247 { 245 248 $Row = $DbResult->fetch_assoc(); 246 $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);249 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 247 250 return(array($Row)); 248 251 } else … … 251 254 //array_push($Values, array('Time' => $Time, 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 252 255 $Result[] = array('Time' => ($Time + $this->TimeSegment($this->Data['Period'], $Level)), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0); 253 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'.$this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1'); 256 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'. 257 TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1'); 254 258 if($DbResult->num_rows > 0) 255 259 { 256 260 $Row = $DbResult->fetch_assoc(); 257 array_unshift($Result, array('Time' => ( $this->Database->MysqlDateTimeToTime($Row['Time']) + 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));261 array_unshift($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) + 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 258 262 } 259 263 // if($Debug) print_r($Result); … … 266 270 $Result = array(); 267 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"); 268 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'. $this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1');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'); 269 273 if($DbResult->num_rows > 0) 270 274 { 271 275 $Row = $DbResult->fetch_assoc(); 272 $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);276 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 273 277 return(array($Row)); 274 278 } else … … 279 283 $Result[] = array('Time' => ($Time - $this->TimeSegment($this->Data['Period'], $Level)), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0); 280 284 281 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'. $this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1');285 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1'); 282 286 if($DbResult->num_rows > 0) 283 287 { 284 288 $Row = $DbResult->fetch_assoc(); 285 array_push($Result, array('Time' => ( $this->Database->MysqlDateTimeToTime($Row['Time']) - 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));289 array_push($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) - 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 286 290 } 287 291 // if($Debug) print_r($Result); … … 292 296 function GetValues($TimeFrom, $TimeTo, $Level) 293 297 { 294 if($this->Debug) echo('TimeFrom: '.$TimeFrom.'('. $this->Database->TimeToMysqlDateTime($TimeFrom).')<br>');295 if($this->Debug) echo('TimeTo: '.$TimeTo.'('. $this->Database->TimeToMysqlDateTime($TimeTo).')<br>');298 if($this->Debug) echo('TimeFrom: '.$TimeFrom.'('.TimeToMysqlDateTime($TimeFrom).')<br>'); 299 if($this->Debug) echo('TimeTo: '.$TimeTo.'('.TimeToMysqlDateTime($TimeTo).')<br>'); 296 300 297 301 //$AbsoluteTime = GetTimeRange($MeasureId); 298 302 299 // if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 303 // if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 300 304 // ($TimeTo > $AbsoluteLeftTime) and ($TimeTo < $AbsoluteRightTime)) 301 305 // { 302 306 303 307 // Load values in time range 304 $Result = $this->Database->select($this->Data['DataTable'], 'Time, Min, Avg, Max, Continuity', '(Time > "'.$this->Database->TimeToMysqlDateTime($TimeFrom).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($TimeTo).'") AND (Measure='.$this->Data['Id'].') AND (Level='.$Level.') ORDER BY Time'); 308 $Result = $this->Database->select($this->Data['DataTable'], 'Time, Min, Avg, Max, Continuity', '(Time > "'. 309 TimeToMysqlDateTime($TimeFrom).'") AND (Time < "'. 310 TimeToMysqlDateTime($TimeTo).'") AND (Measure='. 311 $this->Data['Id'].') AND (Level='.$Level.') ORDER BY Time'); 305 312 // echo($Level.' '.TimeToMysqlDateTime($TimeFrom).' '.TimeToMysqlDateTime($TimeTo)); 306 313 $Values = array(); … … 311 318 // echo($III.' '.$Row['Time'].' '.memory_get_usage().','); 312 319 // $III++; 313 $Values[] = array('Time' => $this->Database->MysqlDateTimeToTime($Row['Time']), 'Min' => $Row['Min'], 'Avg' => $Row['Avg'], 'Max' => $Row['Max'], 'Continuity' => $Row['Continuity']); 320 $Values[] = array('Time' => MysqlDateTimeToTime($Row['Time']), 'Min' => $Row['Min'], 321 'Avg' => $Row['Avg'], 'Max' => $Row['Max'], 'Continuity' => $Row['Continuity']); 314 322 } 315 323 // array_pop($Values); … … 317 325 // die(); 318 326 if($this->Debug) echo('Item count: '.count($Values)); 319 327 320 328 $Points = array(); 321 329 if(count($Values) > 0) … … 385 393 while($Row = $DbResult->fetch_assoc()) 386 394 { 387 $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);395 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 388 396 $Values[] = $Row; 389 397 } … … 416 424 // Load values in time range 417 425 //array_pop($NextValues); 418 } 426 } 419 427 echo("Uroven dokoncena<br>\n"); 420 428 $DbResult = $this->Database->select($this->Data['DataTable'], 'COUNT(*)', 'Level='.$Level.' AND Measure='.$this->Data['Id']); -
trunk/Modules/TimeMeasure/TimeMeasure.php
r586 r655 17 17 $this->Dependencies = array('User'); 18 18 } 19 19 20 20 function DoInstall() 21 21 { 22 22 } 23 23 24 24 function DoUnInstall() 25 25 { … … 28 28 function DoStart() 29 29 { 30 $this->System->Pages['grafy'] = 'PageMeasure'; 30 $this->System->RegisterPage('grafy', 'PageMeasure'); 31 $this->System->RegisterPage(array('grafy', 'graf.png'), 'PageGraph'); 31 32 $this->System->FormManager->RegisterClass('Measure', array( 32 33 'Title' => 'Měření', … … 45 46 'DataTable' => array('Type' => 'String', 'Caption' => 'Tabulka měřených dat', 'Default' => 'data'), 46 47 ), 47 )); 48 )); 48 49 } 49 50
Note:
See TracChangeset
for help on using the changeset viewer.