1 | <?php
|
---|
2 |
|
---|
3 | class PageMeasure extends Page
|
---|
4 | {
|
---|
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
|
---|
28 | (
|
---|
29 | 'hour' => array(
|
---|
30 | 'caption' => 'Hodina',
|
---|
31 | 'period' => 3600,
|
---|
32 | ),
|
---|
33 | 'day' => array(
|
---|
34 | 'caption' => 'Den',
|
---|
35 | 'period' => 86400, // 3600 * 24,
|
---|
36 | ),
|
---|
37 | 'week' => array(
|
---|
38 | 'caption' => 'Týden',
|
---|
39 | 'period' => 604800, // 3600 * 24 * 7,
|
---|
40 | ),
|
---|
41 | 'month' => array(
|
---|
42 | 'caption' => 'Měsíc',
|
---|
43 | 'period' => 2592000, // 3600 * 24 * 30,
|
---|
44 | ),
|
---|
45 | 'year' => array(
|
---|
46 | 'caption' => 'Rok',
|
---|
47 | 'period' => 31536000, // 3600 * 24 * 365,
|
---|
48 | ),
|
---|
49 | 'years' => array(
|
---|
50 | 'caption' => 'Desetiletí',
|
---|
51 | 'period' => 315360000, // 3600 * 24 * 365 * 10,
|
---|
52 | ),
|
---|
53 | );
|
---|
54 | }
|
---|
55 |
|
---|
56 | function EditTime($Time)
|
---|
57 | {
|
---|
58 | $Output = '<form style="display: inline;" action="?Operation=SetTime&Time='.$Time.'" method="post">';
|
---|
59 |
|
---|
60 | $TimeParts = getdate($_SESSION[$Time]);
|
---|
61 | //print_r($TimeParts);
|
---|
62 |
|
---|
63 | // Day selection
|
---|
64 | $Output .= '<select name="Day">';
|
---|
65 | for($I = 1; $I < 32; $I++)
|
---|
66 | {
|
---|
67 | if($I == $TimeParts['mday']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
68 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
---|
69 | }
|
---|
70 | $Output .= '</select>. ';
|
---|
71 |
|
---|
72 | // Month selection
|
---|
73 | $Output .= '<select name="Month">';
|
---|
74 | foreach($this->Months as $Index => $Month)
|
---|
75 | {
|
---|
76 | if($Index == $TimeParts['mon']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
77 | if($Index > 0) $Output .= '<option value="'.$Index.'"'.$Selected.'>'.$Month.'</option>';
|
---|
78 | }
|
---|
79 | $Output .= '</select>. ';
|
---|
80 |
|
---|
81 | // Day selection
|
---|
82 | $Output .= '<select name="Year">';
|
---|
83 | for($I = 2000; $I < 2010; $I++)
|
---|
84 | {
|
---|
85 | if($I == $TimeParts['year']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
86 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
---|
87 | }
|
---|
88 | $Output .= '</select> ';
|
---|
89 |
|
---|
90 | // Hour selection
|
---|
91 | $Output .= '<select name="Hour">';
|
---|
92 | for($I = 0; $I < 24; $I++)
|
---|
93 | {
|
---|
94 | if($I == $TimeParts['hours']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
95 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
---|
96 | }
|
---|
97 | $Output .= '</select> : ';
|
---|
98 |
|
---|
99 | // Minute selection
|
---|
100 | $Output .= '<select name="Minute">';
|
---|
101 | for($I = 0; $I < 60; $I++)
|
---|
102 | {
|
---|
103 | if($I == $TimeParts['minutes']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
104 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
---|
105 | }
|
---|
106 | $Output .= '</select> ';
|
---|
107 | $Output .= '<input type="submit" value="Nastavit">';
|
---|
108 | $Output .= '</form>';
|
---|
109 |
|
---|
110 | $Output .= ' <form style="display: inline;" action="?Operation=SetTimeNow&Time='.$Time.'" method="post">';
|
---|
111 | $Output .= '<input type="submit" value="Aktuální čas">';
|
---|
112 | $Output .= '</form>';
|
---|
113 |
|
---|
114 | return($Output);
|
---|
115 | }
|
---|
116 |
|
---|
117 | function Show()
|
---|
118 | {
|
---|
119 | $Debug = 0;
|
---|
120 |
|
---|
121 | foreach($this->DefaultVariables as $Index => $Variable)
|
---|
122 | {
|
---|
123 | if(!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable;
|
---|
124 | if(array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index];
|
---|
125 | if(array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index];
|
---|
126 | //$$Index = $_SESSION[$Index];
|
---|
127 | }
|
---|
128 |
|
---|
129 | if($_SESSION['TimeSpecify'] == 0)
|
---|
130 | {
|
---|
131 | $_SESSION['TimeEnd'] = time() - 60;
|
---|
132 | $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GraphTimeRanges[$_SESSION['Period']]['period'];
|
---|
133 | }
|
---|
134 |
|
---|
135 | $Output = '';
|
---|
136 |
|
---|
137 | if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = '';
|
---|
138 | switch($_GET['Operation'])
|
---|
139 | {
|
---|
140 | case 'SetTime':
|
---|
141 | if(array_key_exists('Time', $_GET) and array_key_exists('Month', $_POST) and array_key_exists('Day', $_POST) and
|
---|
142 | array_key_exists('Year', $_POST) and array_key_exists('Hour', $_POST) and array_key_exists('Minute', $_POST))
|
---|
143 | {
|
---|
144 | if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
|
---|
145 | {
|
---|
146 | $_SESSION[$_GET['Time']] = mktime($_POST['Hour'], $_POST['Minute'], 0, $_POST['Month'],
|
---|
147 | $_POST['Day'], $_POST['Year']);
|
---|
148 | $$_GET['Time'] = $_SESSION[$_GET['Time']];
|
---|
149 | }
|
---|
150 | }
|
---|
151 | break;
|
---|
152 | case 'SetTimeNow':
|
---|
153 | if(array_key_exists('Time', $_GET))
|
---|
154 | {
|
---|
155 | if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
|
---|
156 | {
|
---|
157 | $_SESSION[$_GET['Time']] = time();
|
---|
158 | $$_GET['Time'] = $_SESSION[$_GET['Time']];
|
---|
159 | }
|
---|
160 | }
|
---|
161 | break;
|
---|
162 | }
|
---|
163 | $Output .= '<strong>Časový úsek:</strong><br>';
|
---|
164 | // Show graf time range menu
|
---|
165 | if($_SESSION['TimeSpecify'] == 0)
|
---|
166 | {
|
---|
167 | $Output .= 'Délka úseku: ';
|
---|
168 | foreach($this->GraphTimeRanges as $Index => $Item)
|
---|
169 | $Output .= '<a href="?Period='.$Index.'">'.$Item['caption'].'</a> ';
|
---|
170 | $Output .= '<br/>';
|
---|
171 | $Output .= '<a href="?TimeSpecify=1">Přesnější nastavení...</a><br>';
|
---|
172 | } else {
|
---|
173 | $Output .= '<table cellspacing="0" cellpadding="2" border="0">';
|
---|
174 | $Output .= '<tr><td>Počátek:</td><td>'.$this->EditTime('TimeStart').'</td></tr>';
|
---|
175 | $Output .= '<tr><td>Konec:</td><td>'.$this->EditTime('TimeEnd').'</td></tr>';
|
---|
176 | $Output .= '</table>';
|
---|
177 | $Output .= '<a href="?TimeSpecify=0">Jednoduché nastavení...</a><br>';
|
---|
178 | }
|
---|
179 | $Output .= '<br/>'.$this->Graph();
|
---|
180 |
|
---|
181 | $Output .= '<br/>'.$this->MeasureTable();
|
---|
182 | return($Output);
|
---|
183 | }
|
---|
184 |
|
---|
185 | function Graph()
|
---|
186 | {
|
---|
187 | $Output = '<strong>Graf:</strong><br/>';
|
---|
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 |
|
---|
197 | function MeasureTable()
|
---|
198 | {
|
---|
199 | $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');
|
---|
205 | while($Measure = $Result->fetch_array())
|
---|
206 | {
|
---|
207 | $DbResult2 = $this->Database->select('MeasureMethod', '*', 'Id='.$Measure['Method']);
|
---|
208 | $MeasureMethod = $DbResult2->fetch_assoc();
|
---|
209 | $StopWatchStart = GetMicrotime();
|
---|
210 | if(array_key_exists('Debug', $_GET))
|
---|
211 | {
|
---|
212 | $DbResult = $this->Database->select($Measure['DataTable'], 'COUNT(*)', 'Measure='.$Measure['Id']);
|
---|
213 | $RowCount = $DbResult->fetch_array();
|
---|
214 | $RowCount = $RowCount[0];
|
---|
215 | }
|
---|
216 | $Result2 = $this->Database->select($Measure['DataTable'], 'Time, Avg', 'Measure='.$Measure['Id'].' AND Level=0 ORDER BY Time DESC LIMIT 1');
|
---|
217 | if($Result2->num_rows > 0)
|
---|
218 | {
|
---|
219 | $Row = $Result2->fetch_array();
|
---|
220 | $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['Time']));
|
---|
221 | $LastMeasureValue = $PrefixMultiplier->Add($Row['Avg'], $MeasureMethod['Unit']);
|
---|
222 | } else
|
---|
223 | {
|
---|
224 | $LastMeasureTime = ' ';
|
---|
225 | $LastMeasureValue = ' ';
|
---|
226 | }
|
---|
227 | if($Measure['Continuity'] == 1) $Interpolate = 'Ano';
|
---|
228 | else $Interpolate = 'Ne';
|
---|
229 | //if($Measure['Description'] == '') $Measure['Description'] = ' ';
|
---|
230 | $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000 ) / 1000;
|
---|
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>';
|
---|
232 | if(array_key_exists('Debug', $_GET)) $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>';
|
---|
233 | $Output .= '</tr>';
|
---|
234 | }
|
---|
235 | $Output .= '</table>';
|
---|
236 | //echo(time());
|
---|
237 | //print_r(gd_info());
|
---|
238 | //print_r($_SESSION);
|
---|
239 |
|
---|
240 | //ShowPage($Output);
|
---|
241 | //echo($PrefixMultiplier->Add('-0.000000071112345', 'B'));
|
---|
242 | return($Output);
|
---|
243 | }
|
---|
244 | }
|
---|