/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to patches/riku-weather/classes/readers/imageservicereader.php

  • Committer: Suren A. Chilingaryan
  • Date: 2012-07-14 17:44:09 UTC
  • Revision ID: csa@dside.dyndns.org-20120714174409-cuzsy4vupyjx9lia
Update of setups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
class IMAGEData implements Iterator {
4
 
 var $period, $multiplier;
5
 
 var $from, $to;
6
 
 var $resample, $nextsample;
7
 
 var $pos;
8
 
 
9
 
 var $items;
10
 
 
11
 
 var $start;
12
 
 
13
 
 const DEFAULT_START = "January 1, 2000";
14
 
   
15
 
 public function __construct(TESTReader &$reader, OPTIONS &$opts, &$items, INTERVAL &$ivl, $resample) {
16
 
    $period = $opts->Get('period');
17
 
 
18
 
    $this->multiplier = $reader->GetFractionalMultiplier($period);
19
 
    $this->period = $this->multiplier * $period;
20
 
    $this->resample = $this->multiplier * $resample;
21
 
    
22
 
    $from = $this->multiplier * $ivl->GetWindowStart();
23
 
    $ifrom = ceil($from);
24
 
    $rem = $ifrom % $this->period;
25
 
    if ($rem) $this->from = $ifrom + ($this->period - $rem);
26
 
    else $this->from = $ifrom;
27
 
 
28
 
    $this->to = $this->multiplier * $ivl->GetWindowEnd();
29
 
    
30
 
    $limit = $ivl->GetItemLimit();
31
 
    if ($limit) {
32
 
        if ($limit > 0) {
33
 
            $to = $this->from + $this->period * $limit;
34
 
            if ($to < $this->to) $this->to = $to;
35
 
        } else {
36
 
            $from = $this->to + $this->period * $limit;
37
 
            if ($from > $this->from) $this->from = $from;
38
 
        }
39
 
    }
40
 
    
41
 
    $this->items = &$items;
42
 
 
43
 
    $limit = $opts->GetDateLimit(TESTData::DEFAULT_START, time());
44
 
    $this->start = $limit[0]; 
45
 
 }
46
 
 
47
 
 function doResample() {
48
 
    for ($next = $this->pos + $this->period;(($next < $this->to)&&($next < $this->nextsample));$next += $this->period)
49
 
        $this->pos = $next;
50
 
 
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;
55
 
    }
56
 
 }
57
 
 
58
 
 function rewind() {
59
 
    $this->pos = $this->from;
60
 
 
61
 
    if ($this->resample) {
62
 
        $this->nextsample = $this->resample*ceil($this->pos / $this->resample);
63
 
        $this->doResample();
64
 
    }
65
 
 }
66
 
 
67
 
 function current() {
68
 
    $x = ($this->pos - $this->start) / $this->multiplier;
69
 
    $period = $this->period / $this->multiplier;
70
 
 
71
 
    $max = getrandmax();
72
 
    
73
 
    $values = array();
74
 
    foreach ($this->items as &$item) {
75
 
        $y = 0;
76
 
 
77
 
        if (eval($item['func'] . ";") === false)
78
 
            throw new ADEIException(translate("Invalid function(%s) is supplied to TESTReader", $item['func']));
79
 
 
80
 
        if ($item['noise']) $y += 2*$item['noise']*((rand() - $max/2)/$max);
81
 
 
82
 
        array_push($values, $y);
83
 
    }
84
 
    return $values;
85
 
 }
86
 
 
87
 
 function key() {
88
 
    $res = $this->pos / $this->multiplier;
89
 
    if (is_float($res)) return sprintf("%.8f", $res);
90
 
    return $res;
91
 
 }
92
 
 
93
 
 function next() {
94
 
    $this->pos += $this->period;
95
 
 
96
 
    if ($this->resample) $this->doResample();
97
 
 }
98
 
 
99
 
 function valid() {
100
 
    return ($this->pos < $this->to);
101
 
 }
102
 
 
103
 
}
104
 
 
105
 
 
106
 
 
107
 
class IMAGEReader extends READER {
108
 
 var $cache;
109
 
 
110
 
 var $items;
111
 
 var $groups;
112
 
 
113
 
 function __construct(&$props) {
114
 
    parent::__construct($props);
115
 
 
116
 
    $this->items = array(
117
 
        
118
 
    );
119
 
    
120
 
 
121
 
    if ($this->dbname) {
122
 
        $list = $this->opts->ListConfiguredGroups();
123
 
    
124
 
        if ($list) {
125
 
            $this->groups = array();
126
 
        
127
 
            foreach ($list as $gid) {
128
 
                $this->groups[$gid] = array();
129
 
            }
130
 
        } else {
131
 
            $this->groups = array(
132
 
                'default' => array(
133
 
                    'name' => _("Default Group")
134
 
                )
135
 
            );
136
 
        }
137
 
    }
138
 
 
139
 
/*
140
 
    if (sizeof($list) > 1) {
141
 
        array_push($this->groups, array(
142
 
            'id' => "-1",
143
 
            'name' => _("Combined Group"),
144
 
            'complex' => true
145
 
        );
146
 
    }
147
 
*/
148
 
 }
149
 
 
150
 
 function GetGroupInfo(LOGGROUP $grp = NULL, $flags = 0) {
151
 
    return NULL;
152
 
 }
153
 
 
154
 
 function GetItemList(LOGGROUP $grp = NULL, MASK $mask = NULL, $flags = 0) {
155
 
    return NULL;
156
 
 }
157
 
 
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);
160
 
 }
161
 
 
162
 
 function HaveData(LOGGROUP $grp = NULL, $from = 0, $to = 0) {
163
 
    $grp = $this->CheckGroup($grp);
164
 
 
165
 
    $ivl = $this->CreateInterval($grp);
166
 
    $ivl->Limit($from, $to);
167
 
    
168
 
    $period = $this->req->GetGroupOption('period', $grp);
169
 
 
170
 
    $from = $ivl->GetWindowStart();
171
 
    $to = $ivl->GetWindowEnd();
172
 
    
173
 
    if (($from - $to) > 2 * $period) return true;
174
 
    else {
175
 
        $multiplier = $this->GetFractionalMultiplier($period);
176
 
        $period *= $multiplier; 
177
 
        
178
 
        $ifrom = ceil($multiplier * $from);
179
 
        $rem = $ifrom % $period;
180
 
        if ($rem) $curfrom = $ifrom + ($period - $rem);
181
 
        else $curfrom = $ifrom;
182
 
        
183
 
        if ($curfrom < $multiplier * $to) return true;
184
 
    }
185
 
    
186
 
    return false;
187
 
 }
188
 
}
189
 
 
190
 
?>
 
 
b'\\ No newline at end of file'