3
class IMAGEData implements Iterator {
4
var $period, $multiplier;
6
var $resample, $nextsample;
13
const DEFAULT_START = "January 1, 2000";
15
public function __construct(TESTReader &$reader, OPTIONS &$opts, &$items, INTERVAL &$ivl, $resample) {
16
$period = $opts->Get('period');
18
$this->multiplier = $reader->GetFractionalMultiplier($period);
19
$this->period = $this->multiplier * $period;
20
$this->resample = $this->multiplier * $resample;
22
$from = $this->multiplier * $ivl->GetWindowStart();
24
$rem = $ifrom % $this->period;
25
if ($rem) $this->from = $ifrom + ($this->period - $rem);
26
else $this->from = $ifrom;
28
$this->to = $this->multiplier * $ivl->GetWindowEnd();
30
$limit = $ivl->GetItemLimit();
33
$to = $this->from + $this->period * $limit;
34
if ($to < $this->to) $this->to = $to;
36
$from = $this->to + $this->period * $limit;
37
if ($from > $this->from) $this->from = $from;
41
$this->items = &$items;
43
$limit = $opts->GetDateLimit(TESTData::DEFAULT_START, time());
44
$this->start = $limit[0];
47
function doResample() {
48
for ($next = $this->pos + $this->period;(($next < $this->to)&&($next < $this->nextsample));$next += $this->period)
51
$this->nextsample += $this->resample;
52
if ($this->nextsample < $this->pos) {
53
$add = ceil(($this->pos - $this->nextsample) / $this->resample);
54
$this->nextsample += $add * $this->resample;
59
$this->pos = $this->from;
61
if ($this->resample) {
62
$this->nextsample = $this->resample*ceil($this->pos / $this->resample);
68
$x = ($this->pos - $this->start) / $this->multiplier;
69
$period = $this->period / $this->multiplier;
74
foreach ($this->items as &$item) {
77
if (eval($item['func'] . ";") === false)
78
throw new ADEIException(translate("Invalid function(%s) is supplied to TESTReader", $item['func']));
80
if ($item['noise']) $y += 2*$item['noise']*((rand() - $max/2)/$max);
82
array_push($values, $y);
88
$res = $this->pos / $this->multiplier;
89
if (is_float($res)) return sprintf("%.8f", $res);
94
$this->pos += $this->period;
96
if ($this->resample) $this->doResample();
100
return ($this->pos < $this->to);
107
class IMAGEReader extends READER {
113
function __construct(&$props) {
114
parent::__construct($props);
116
$this->items = array(
122
$list = $this->opts->ListConfiguredGroups();
125
$this->groups = array();
127
foreach ($list as $gid) {
128
$this->groups[$gid] = array();
131
$this->groups = array(
133
'name' => _("Default Group")
140
if (sizeof($list) > 1) {
141
array_push($this->groups, array(
143
'name' => _("Combined Group"),
150
function GetGroupInfo(LOGGROUP $grp = NULL, $flags = 0) {
154
function GetItemList(LOGGROUP $grp = NULL, MASK $mask = NULL, $flags = 0) {
158
function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL) {
159
return new TESTData($this, $this->req->GetGroupOptions($grp), $items, $ivl, $resample);
162
function HaveData(LOGGROUP $grp = NULL, $from = 0, $to = 0) {
163
$grp = $this->CheckGroup($grp);
165
$ivl = $this->CreateInterval($grp);
166
$ivl->Limit($from, $to);
168
$period = $this->req->GetGroupOption('period', $grp);
170
$from = $ivl->GetWindowStart();
171
$to = $ivl->GetWindowEnd();
173
if (($from - $to) > 2 * $period) return true;
175
$multiplier = $this->GetFractionalMultiplier($period);
176
$period *= $multiplier;
178
$ifrom = ceil($multiplier * $from);
179
$rem = $ifrom % $period;
180
if ($rem) $curfrom = $ifrom + ($period - $rem);
181
else $curfrom = $ifrom;
183
if ($curfrom < $multiplier * $to) return true;
b'\\ No newline at end of file'