source: trunk/www/Module/History/Model.php

Last change on this file was 95, checked in by chronos, 10 years ago
  • Upraveno: Soubory různých logických částí systému odděleny do aplikačních modulů.
File size: 2.2 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Base/Model.php');
4
5class History extends Model
6{
7 var $ServerId;
8 var $MeasureId;
9 var $Database;
10 var $PeriodList;
11 var $Resolution = 1000;
12
13 function __construct($System, $ServerId, $MeasureId)
14 {
15 parent::__construct($System);
16 $this->ServerId = $ServerId;
17 $this->MeasureId = $MeasureId;
18 $this->PeriodList = array(
19 array('Name' => 'Hodina', 'Period' => 60 * 60),
20 array('Name' => 'Den', 'Period' => 60 * 60 * 24),
21 array('Name' => 'Týden', 'Period' => 60 * 60 * 24 * 7),
22 array('Name' => 'Měsíc', 'Period' => 60 * 60 * 24 * 30),
23 array('Name' => 'Rok', 'Period' => 60 * 60 * 24 * 365),
24 array('Name' => 'Desetiletí', 'Period' => 60 * 60 * 24 * 3650),
25 );
26 }
27
28 function AddValue($Value)
29 {
30 $Time = time();
31 foreach($this->PeriodList as $Index => $Period)
32 {
33 $Resolution = $this->Resolution;
34 if($Resolution > ($Period['Period'] / 60)) $Resolution = $Period['Period'] / 60;
35 $PeriodTime = floor(floor($Time * $Resolution / $Period['Period']) * $Period['Period'] / $Resolution);
36 $PeriodTimeStart = floor((floor($Time / $Period['Period'] * $Resolution) - 1) * $Period['Period'] / $Resolution);
37 //echo($PeriodTimeStart.' - '.$PeriodTime.' = '.($PeriodTime - $PeriodTimeStart).', ');
38 if($Index == 0)
39 {
40 $ValueMinimum = $Value;
41 $ValueAverage = $Value;
42 $ValueMaximum = $Value;
43 } else
44 {
45 $DbResult = $this->Database->query('SELECT MIN(`Minimum`), AVG(`Average`), MAX(`Maximum`) FROM `History` WHERE `Server`='.$this->ServerId.' AND `Measure`='.$this->MeasureId.' AND `Period`='.($Index - 1).' AND `Time` > '.$PeriodTimeStart.' AND `Time` <= '.$PeriodTime);
46 $Value = $DbResult->fetch_row();
47 $ValueMinimum = $Value[0];
48 $ValueAverage = $Value[1];
49 $ValueMaximum = $Value[2];
50 }
51 $this->Database->replace('History', array('Time' => $PeriodTime, 'Period' => $Index, 'Server' => $this->ServerId, 'Measure' => $this->MeasureId, 'Minimum' => $ValueMinimum, 'Average' => $ValueAverage, 'Maximum' => $ValueMaximum));
52 }
53 // echo("\n");
54 }
55
56 function GetImage($Width, $Height)
57 {
58
59 }
60}
Note: See TracBrowser for help on using the repository browser.