/dev/trunk

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

« back to all changes in this revision

Viewing changes to classes/data.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/*
 
4
  missing - maximal empty interval (without data). It's precise up to existing
 
5
  caching levels and should be used only to make decision if there anything
 
6
  missing in the data or not. No support for subresolution data.
 
7
*/
 
8
class DATA {
 
9
    var $min, $max, $mean;
 
10
    var $items, $n, $missing;
 
11
    var $missing_counter;    
 
12
 
 
13
    var $resolution;
 
14
    
 
15
    function __construct($items) {
 
16
        $this->min = array(); $this->max = array();
 
17
        $this->mean = array(); 
 
18
        
 
19
        $this->n = 0;
 
20
        $this->missing = 0;
 
21
        $this->items = $items;
 
22
        
 
23
        $this->missing_counter = 0;
 
24
    }
 
25
    
 
26
    function Push(DATA &$v, $width) {
 
27
        if (!$v->n) {
 
28
            $this->missing_counter += $width;
 
29
            return;
 
30
        }
 
31
        
 
32
        $items = $v->items;
 
33
        if ($items != $this->items)
 
34
            throw new ADEIException(translate("Number of items in the group have changed from %u to %u (Data::Push)", $this->items, $items));
 
35
            
 
36
        if ($this->n) {
 
37
            for ($i = 0; $i < $items; $i++) {
 
38
                if ($v->min[$i] < $this->min[$i]) $this->min[$i] = $v->min[$i];
 
39
                if ($v->max[$i] > $this->max[$i]) $this->max[$i] = $v->max[$i];
 
40
                
 
41
                $this->mean[$i] = ($this->mean[$i] * $this->n + $v->mean[$i] * $v->n) / ($this->n + $v->n);
 
42
            }
 
43
 
 
44
            if ($this->missing_counter) {
 
45
                if ($this->missing_counter > $this->missing) $this->missing = $this->missing_counter;
 
46
                $this->missing_counter = 0;
 
47
            } else  if ($v->missing > $this->missing) $this->missing = $v->missing;
 
48
        } else {
 
49
            for ($i=0; $i < $items; $i++) {
 
50
                $this->min[$i] = $v->min[$i];
 
51
                $this->max[$i] = $v->max[$i];
 
52
                $this->mean[$i] = $v->mean[$i];
 
53
            }
 
54
                
 
55
            if ($this->missing_counter) {
 
56
                $this->missing = $this->missing_counter;
 
57
                $this->missing_counter = 0;
 
58
            } else $this->missing = $v->missing;
 
59
        }
 
60
        $this->n += $v->n;
 
61
    } 
 
62
 
 
63
    
 
64
        // Row from CACHE table (non 0)
 
65
    function PushRow(&$v, $width) {
 
66
        $n = $v[1];
 
67
        
 
68
        if (!$n) {
 
69
            $this->missing_counter += $width;
 
70
            return;
 
71
        }
 
72
        
 
73
        $missing = $v[2];
 
74
        $items = (count($v) - 3) / 3;
 
75
        
 
76
        if ($items != $this->items)
 
77
            throw new ADEIException(translate("Number of items in the group have changed from %u to %u (Data::PushRow)", $this->items, $items));
 
78
        
 
79
        if ($this->n) {
 
80
            for ($i = 0, $j = 2; $i < $items; $i++) {
 
81
                if ($v[++$j] < $this->min[$i]) $this->min[$i] = $v[$j];
 
82
                if ($v[++$j] > $this->max[$i]) $this->max[$i] = $v[$j];
 
83
                $this->mean[$i] = ($this->mean[$i] * $this->n + $n * $v[++$j]) / ($this->n + $n);
 
84
            }
 
85
 
 
86
            if ($this->missing_counter) {
 
87
                if ($this->missing_counter > $this->missing) $this->missing = $this->missing_counter;
 
88
                $this->missing_counter = 0;
 
89
            } elseif ($missing > $this->missing) $this->missing = $missing;
 
90
        } else {
 
91
            for ($i=0, $j = 2; $i < $items; $i++) {
 
92
                $this->min[$i] = $v[++$j];
 
93
                $this->max[$i] = $v[++$j];
 
94
                $this->mean[$i] = $v[++$j];
 
95
            }
 
96
                
 
97
            if ($this->missing_counter) {
 
98
                $this->missing = $this->missing_counter;
 
99
                $this->missing_counter = 0;
 
100
            } else $this->missing = $missing;
 
101
        }
 
102
        $this->n += $n;
 
103
    }
 
104
 
 
105
 
 
106
        // READER->GetData
 
107
    function PushValue(&$v, $gap) {
 
108
        $items = count($v);
 
109
        if (!$items) return;
 
110
        
 
111
        if ($items != $this->items)
 
112
            throw new ADEIException(translate("Number of items in the group have changed from %u to %u (Data::PushValue)", $this->items, $items));
 
113
        
 
114
        if ($this->n) {
 
115
            for ($i = 0; $i < $items; $i++) {
 
116
                if ($v[$i] < $this->min[$i]) $this->min[$i] = $v[$i];
 
117
                if ($v[$i] > $this->max[$i]) $this->max[$i] = $v[$i];
 
118
                $this->mean[$i] = ($this->mean[$i] * $this->n + $v[$i]) / ($this->n + 1);
 
119
            }
 
120
        } else {
 
121
            for ($i=0; $i < $items; $i++) {
 
122
                $this->min[$i] = $v[$i];
 
123
                $this->max[$i] = $v[$i];
 
124
                $this->mean[$i] = $v[$i];
 
125
            }
 
126
        }
 
127
        
 
128
        if ($gap > $this->missing) $this->missing = $gap;
 
129
        
 
130
        $this->n++;
 
131
    }
 
132
 
 
133
    function Finalize($gap = 0) {
 
134
        if ($gap > $this->missing) $this->missing = $gap;
 
135
        if (is_float($this->missing)) $this->missing = (int)floor($this->missing);
 
136
 
 
137
        if ($this->missing_counter > $this->missing) $this->missing = $this->missing_counter;       
 
138
    }
 
139
}
 
140
 
 
141
?>
 
 
b'\\ No newline at end of file'