Changeset 95 for trunk/Modules
- Timestamp:
- Dec 6, 2021, 11:33:48 AM (3 years ago)
- Location:
- trunk/Modules
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Admin/Admin.php
r92 r95 1 1 <?php 2 2 3 class ModuleAdmin extends AppModule3 class ModuleAdmin extends Module 4 4 { 5 5 function __construct($System) … … 14 14 } 15 15 16 function DoStart() 16 function DoStart(): void 17 17 { 18 $this->System->RegisterPage('admin', 'PageAdmin'); 19 } 20 21 function DoInstall() 22 { 23 } 24 25 function DoUninstall() 26 { 27 } 28 29 function DoUpgrade() 30 { 18 $this->System->RegisterPage(['admin'], 'PageAdmin'); 31 19 } 32 20 } … … 39 27 } 40 28 41 function Show() 29 function Show(): string 42 30 { 43 31 if (array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = ''; … … 62 50 } 63 51 64 function ShowNone() 52 function ShowNone(): string 65 53 { 66 54 $Table = array( … … 78 66 } 79 67 80 function ShowEdit() 68 function ShowEdit(): string 81 69 { 82 70 $DbResult = $this->Database->select('Measure', '*', 'Id='.addslashes($_GET['MeasureId'])); … … 86 74 } 87 75 88 function ShowAdd() 76 function ShowAdd(): string 89 77 { 90 78 $Values = array(); … … 92 80 } 93 81 94 function ShowRebuildCache() 82 function ShowDelete(): string 83 { 84 return ''; 85 } 86 87 function ShowRebuildCache(): string 95 88 { 96 89 echo("Vytvařím novou cache...<br>"); … … 100 93 $Measure->RebuildMeasureCache(); 101 94 echo('Dokončeno<br>'); 95 return ''; 102 96 } 103 97 } -
trunk/Modules/Measure/Measure.php
r92 r95 3 3 include_once(dirname(__FILE__).'/Page.php'); 4 4 5 class ModuleMeasure extends AppModule5 class ModuleMeasure extends Module 6 6 { 7 7 function __construct($System) … … 16 16 } 17 17 18 function DoStart() 19 { 20 $this->System->RegisterPage( '', 'PageMain');21 } 22 23 function DoInstall() 24 { 25 $this->Database->query('CREATE TABLE IF NOT EXISTS `Measure` (26 `Id` int(11) NOT NULL auto_increment,27 `Name` varchar(255) collate utf8_general_ci NOT NULL,28 `Description` varchar(255) collate utf8_general_ci NOT NULL,29 `Divider` int(11) NOT NULL default 1,30 `Unit` varchar(16) collate utf8_general_ci NOT NULL,31 `Continuity` tinyint(1) NOT NULL default 0,32 `Period` int(11) NOT NULL default 60,33 `PermissionView` varchar(255) collate utf8_general_ci NOT NULL default "all",34 `PermissionAdd` varchar(255) collate utf8_general_ci NOT NULL default "localhost.localdomain",35 `Info` varchar(255) collate utf8_general_ci NOT NULL,36 `Enabled` int(11) NOT NULL default 1,37 `Cumulative` int(11) NOT NULL default 0,38 `DataTable` varchar(32) collate utf8_general_ci NOT NULL default "data",39 `DataType` varchar(32) collate utf8_general_ci NOT NULL,40 PRIMARY KEY (`Id`)41 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');42 43 44 function DoUninstall() 18 function DoStart(): void 19 { 20 $this->System->RegisterPage(array(''), 'PageMain'); 21 } 22 23 function DoInstall(): void 24 { 25 $this->Database->query('CREATE TABLE IF NOT EXISTS `Measure` ( 26 `Id` int(11) NOT NULL auto_increment, 27 `Name` varchar(255) collate utf8_general_ci NOT NULL, 28 `Description` varchar(255) collate utf8_general_ci NOT NULL, 29 `Divider` int(11) NOT NULL default 1, 30 `Unit` varchar(16) collate utf8_general_ci NOT NULL, 31 `Continuity` tinyint(1) NOT NULL default 0, 32 `Period` int(11) NOT NULL default 60, 33 `PermissionView` varchar(255) collate utf8_general_ci NOT NULL default "all", 34 `PermissionAdd` varchar(255) collate utf8_general_ci NOT NULL default "localhost.localdomain", 35 `Info` varchar(255) collate utf8_general_ci NOT NULL, 36 `Enabled` int(11) NOT NULL default 1, 37 `Cumulative` int(11) NOT NULL default 0, 38 `DataTable` varchar(32) collate utf8_general_ci NOT NULL default "data", 39 `DataType` varchar(32) collate utf8_general_ci NOT NULL, 40 PRIMARY KEY (`Id`) 41 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 42 } 43 44 function DoUninstall(): void 45 45 { 46 46 $this->Database->query('DROP TABLE IF EXISTS `Measure`'); 47 }48 49 function DoUpgrade()50 {51 52 47 } 53 48 } … … 81 76 } 82 77 83 function TimeSegment( $Level)78 function TimeSegment(int $Level): int 84 79 { 85 80 return pow($this->LevelReducing, $Level) * 60; 86 81 } 87 82 88 function GetDataTable() 83 function GetDataTable(): string 89 84 { 90 85 return 'data_'.$this->Data['Name']; 91 86 } 92 87 93 function AlignTime( $Time, $TimeSegment)88 function AlignTime(int $Time, int $TimeSegment): int 94 89 { 95 90 return round(($Time - $this->ReferenceTime) / $TimeSegment) * $TimeSegment + … … 97 92 } 98 93 99 function Load( $Id)94 function Load(int $Id): void 100 95 { 101 96 $Result = $this->Database->select('Measure', '*', '`Id`='.$Id); … … 108 103 } 109 104 110 function AddValue( $Value, $Time)105 function AddValue(float $Value, int $Time): void 111 106 { 112 107 $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '. … … 163 158 } 164 159 165 function UpdateHigherLevels( $Time)160 function UpdateHigherLevels(int $Time): void 166 161 { 167 162 for ($Level = 1; $Level <= $this->MaxLevel; $Level++) … … 206 201 207 202 /* Compute one value for upper time level from multiple values */ 208 function ComputeOneValue( $LeftTime, $RightTime, $Values, $Level)203 function ComputeOneValue(int $LeftTime, int $RightTime, array $Values, int $Level): array 209 204 { 210 205 $NewValue = array('Min' => +1000000000000000000, 'Avg' => 0, 'Max' => -1000000000000000000); … … 294 289 } 295 290 296 function GetTimeRange( $Level)291 function GetTimeRange(int $Level): array 297 292 { 298 293 // Get first and last time … … 317 312 318 313 // Load one nearest value newer then given time 319 function LoadRightSideValue( $Level, $Time)314 function LoadRightSideValue(int $Level, int $Time): array 320 315 { 321 316 $Result = array(); … … 350 345 351 346 // Load one nearest value older then given time 352 function LoadLeftSideValue( $Level, $Time)347 function LoadLeftSideValue(int $Level, int $Time): array 353 348 { 354 349 $Result = array(); … … 382 377 } 383 378 384 function GetValues( $TimeFrom, $TimeTo, $Level)379 function GetValues(int $TimeFrom, int $TimeTo, int $Level): array 385 380 { 386 381 //$AbsoluteTime = GetTimeRange($this->DataId); … … 430 425 } 431 426 432 function RebuildMeasureCache() 427 function RebuildMeasureCache(): void 433 428 { 434 429 echo('Velicina '.$this->Data['Name']."<br>\n"); … … 508 503 } 509 504 510 function RebuildAllMeasuresCache() 505 function RebuildAllMeasuresCache(): void 511 506 { 512 507 $Result = $this->Database->select('Measure', 'Id'); 513 508 while ($Row = $Result->fetch_array()) 514 509 { 515 $Measure = new Measure( );510 $Measure = new Measure($this->Database); 516 511 $Measure->Load($Row['Id']); 517 512 $Measure->RebuildMeasureCache(); … … 520 515 } 521 516 522 function ClearData() 517 function ClearData(): void 523 518 { 524 519 $this->Database->delete($this->Data['DataTable'], '1'); -
trunk/Modules/Measure/Page.php
r92 r95 44 44 $this->Time = time(); 45 45 } 46 47 function GetTimeRange() 46 47 function GetTimeRange(): string 48 48 { 49 49 if (!array_key_exists($_SESSION['Period'], $this->GraphTimeRanges)) 50 50 $_SESSION['Period'] = 'day'; 51 51 52 52 $Result = $this->GraphTimeRanges[$_SESSION['Period']]['period']; 53 53 if ($Result == -1) … … 61 61 } 62 62 63 function EditTime($Time) 63 function EditTime($Time): string 64 64 { 65 65 $Output = '<form style="display: inline;" action="?Operation=SetTime&Time='.$Time.'" method="post">'; … … 119 119 return $Output; 120 120 } 121 122 function GetFirstMeasure($Measure) 121 122 function GetFirstMeasure($Measure): array 123 123 { 124 124 $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.$Measure['Id'].') AND (`Level`=0) ORDER BY `Time` ASC LIMIT 1'); … … 135 135 } 136 136 137 function GetLastMeasure($Measure) 137 function GetLastMeasure($Measure): array 138 138 { 139 139 $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.$Measure['Id'].') AND (`Level`=0) ORDER BY `Time` DESC LIMIT 1'); … … 149 149 return array('Time' => $LastMeasureTime, 'Value' => $LastMeasureValue); 150 150 } 151 152 function LoadMeasure($Id) 151 152 function LoadMeasure($Id): array 153 153 { 154 154 $DbResult = $this->Database->select('Measure', '*', '( `Enabled`=1) AND (`Id`='.$Id.') AND ((`PermissionView`="all") OR (`PermissionView`="'. 155 gethostbyaddr($_SERVER['REMOTE_ADDR']).'"))'); 155 gethostbyaddr($_SERVER['REMOTE_ADDR']).'"))'); 156 156 $DbRow = $DbResult->fetch_array(); 157 157 return $DbRow; 158 158 } 159 159 160 160 /* Produce table with available measures */ 161 function ShowMeasureTable() 161 function ShowMeasureTable(): string 162 162 { 163 163 $PrefixMultiplier = new PrefixMultiplier(); … … 195 195 $LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'. 196 196 $Interpolate.'</td><td>'.$Measure['Info'].'</td>'; 197 if (array_key_exists('Debug', $_GET)) 197 if (array_key_exists('Debug', $_GET)) 198 198 $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>'; 199 199 $Output .= '</tr>'; … … 203 203 } 204 204 205 function ShowGraph() 205 function ShowGraph(): string 206 206 { 207 207 $Output = '<strong>Graf:</strong><br>'; … … 217 217 } 218 218 219 function ShowTimeRange() 219 function ShowTimeRange(): string 220 220 { 221 221 $Output = ''; … … 269 269 270 270 } 271 272 function HandleURL() 273 { 274 global $Config; 275 276 foreach ($Config['DefaultVariables'] as $Index => $Variable) 271 272 function HandleURL(): void 273 { 274 foreach ($this->System->Config['DefaultVariables'] as $Index => $Variable) 277 275 { 278 276 if (!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable; … … 285 283 $_SESSION['Period'] = $_GET['Period']; 286 284 // Update time start according time period 287 if ($_SESSION['Period'] == 'all') 285 if ($_SESSION['Period'] == 'all') 288 286 { 289 287 $Measure = $this->LoadMeasure($_SESSION['Measure']); … … 322 320 $_SESSION['TimeSpecify'] = $_GET['TimeSpecify']; 323 321 } 324 322 325 323 if (array_key_exists('Move', $_GET)) 326 324 { 327 325 $Move = $_GET['Move']; 328 if ($Move == 'Left') 326 if ($Move == 'Left') 329 327 { 330 328 $_SESSION['TimeStart'] = $_SESSION['TimeStart'] - $this->GetTimeRange(); 331 329 $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] - $this->GetTimeRange(); 332 330 } else 333 if ($Move == 'Right') 331 if ($Move == 'Right') 334 332 { 335 333 $_SESSION['TimeStart'] = $_SESSION['TimeStart'] + $this->GetTimeRange(); 336 334 $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] + $this->GetTimeRange(); 337 } else 335 } else 338 336 if ($Move == 'Now') 339 337 { … … 358 356 } 359 357 360 function Show() 358 function Show(): string 361 359 { 362 360 global $Config; … … 364 362 $Debug = 0; 365 363 $this->HandleURL(); 366 364 367 365 $Output = '<div style="text-align: center"><div class="Title">'.$Config['Web']['Title'].'</div>'; 368 366
Note:
See TracChangeset
for help on using the changeset viewer.