Ignore:
Timestamp:
Dec 6, 2021, 11:33:48 AM (2 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
  • Added: Explicit types for better type checking.
  • Fixed: Support for php 8.0.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Measure/Measure.php

    r92 r95  
    33include_once(dirname(__FILE__).'/Page.php');
    44
    5 class ModuleMeasure extends AppModule
     5class ModuleMeasure extends Module
    66{
    77  function __construct($System)
     
    1616  }
    1717
    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
    4545  {
    4646    $this->Database->query('DROP TABLE IF EXISTS `Measure`');
    47   }
    48 
    49   function DoUpgrade()
    50   {
    51 
    5247  }
    5348}
     
    8176  }
    8277
    83   function TimeSegment($Level)
     78  function TimeSegment(int $Level): int
    8479  {
    8580    return pow($this->LevelReducing, $Level) * 60;
    8681  }
    8782
    88   function GetDataTable()
     83  function GetDataTable(): string
    8984  {
    9085    return 'data_'.$this->Data['Name'];
    9186  }
    9287
    93   function AlignTime($Time, $TimeSegment)
     88  function AlignTime(int $Time, int $TimeSegment): int
    9489  {
    9590    return round(($Time - $this->ReferenceTime) / $TimeSegment) * $TimeSegment +
     
    9792  }
    9893
    99   function Load($Id)
     94  function Load(int $Id): void
    10095  {
    10196    $Result = $this->Database->select('Measure', '*', '`Id`='.$Id);
     
    108103  }
    109104
    110   function AddValue($Value, $Time)
     105  function AddValue(float $Value, int $Time): void
    111106  {
    112107    $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '.
     
    163158  }
    164159
    165   function UpdateHigherLevels($Time)
     160  function UpdateHigherLevels(int $Time): void
    166161  {
    167162    for ($Level = 1; $Level <= $this->MaxLevel; $Level++)
     
    206201
    207202  /* 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
    209204  {
    210205    $NewValue = array('Min' => +1000000000000000000, 'Avg' => 0, 'Max' => -1000000000000000000);
     
    294289  }
    295290
    296   function GetTimeRange($Level)
     291  function GetTimeRange(int $Level): array
    297292  {
    298293    // Get first and last time
     
    317312
    318313  // Load one nearest value newer then given time
    319   function LoadRightSideValue($Level, $Time)
     314  function LoadRightSideValue(int $Level, int $Time): array
    320315  {
    321316    $Result = array();
     
    350345
    351346  // Load one nearest value older then given time
    352   function LoadLeftSideValue($Level, $Time)
     347  function LoadLeftSideValue(int $Level, int $Time): array
    353348  {
    354349    $Result = array();
     
    382377  }
    383378
    384   function GetValues($TimeFrom, $TimeTo, $Level)
     379  function GetValues(int $TimeFrom, int $TimeTo, int $Level): array
    385380  {
    386381  //$AbsoluteTime = GetTimeRange($this->DataId);
     
    430425  }
    431426
    432   function RebuildMeasureCache()
     427  function RebuildMeasureCache(): void
    433428  {
    434429    echo('Velicina '.$this->Data['Name']."<br>\n");
     
    508503  }
    509504
    510   function RebuildAllMeasuresCache()
     505  function RebuildAllMeasuresCache(): void
    511506  {
    512507    $Result = $this->Database->select('Measure', 'Id');
    513508    while ($Row = $Result->fetch_array())
    514509    {
    515       $Measure = new Measure();
     510      $Measure = new Measure($this->Database);
    516511      $Measure->Load($Row['Id']);
    517512      $Measure->RebuildMeasureCache();
     
    520515  }
    521516
    522   function ClearData()
     517  function ClearData(): void
    523518  {
    524519    $this->Database->delete($this->Data['DataTable'], '1');
Note: See TracChangeset for help on using the changeset viewer.