/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
interface SIMPLEItemFilter {
 public function ProcessItem(&$data, $time, $id, &$value);
}

class READER_ITEMFilter extends BASEDataFilter implements READER_SIMPLEDataFilter {
 var $skip;
 var $filter;
 var $indexes;
 var $indexes_full;
 var $indexes_masked;

 function __construct(READER $rdr, LOGGROUP $grp, DATAFilter $filter, &$opts = NULL) {
    if ($rdr instanceof CACHEReader) $this->skip = true;
    else {
	$this->skip = false;

        $filter_class = $opts['filter'];
        
	if (!include_once("item/" . strtolower($filter_class) . ".php")) {
	    if (!isset($opts['filter']))
	        throw new ADEIException(translate("No item filter is configured"));
	    else
	        throw new ADEIException(translate("Unsupported item filter is configured: \"%s\"", $filter_class));
	}
	    

	$this->filter = new $filter_class($opts);
	
        $mask = $filter->GetItemMask();
        
	if (isset($opts['item_mask'])) {
            $key = array(); $re = array();
	    if (is_array($opts['item_mask'])) {
	        if (is_array($opts['item_mask'][0])) {
	            $checks = $opts['item_mask'];
	        } else {
	            $checks = array($opts['item_mask']);
	        }
	    } else {
	            // Just a regexp of numeric ids
	        $checks = $opts['item_mask'];
	    }

            $this->indexes_masked = array();
            $this->indexes_full = array();

	    if ($checks) {
                $skip_full = false;
                if (is_array($checks)) {
	            $items = $rdr->GetItemList($grp, new MASK());
                } else {

	            if (($opts['masking_reader'])&&($mask)&&(!$mask->IsFull())) {
	                $skip_full = true;
	                $items = $mask->GetIDs();
                    } else {
                        $items = range(0, $rdr->GetGroupSize($grp) - 1);
                    }
                }

	        $i = 0; $j = 0;
	        foreach ($items as &$item) {
	            if (is_array($checks)) {
	                $id = $item["id"];

	                $matched = true;
	                foreach ($checks as $check) {
	                    if (!preg_match($check['items'], $item[$check['key']])) {
	                        $matched = false;
	                        break;
	                    }
	                }
                    } else {
                        $id = $item;
	                $matched = preg_match($checks, $item);
                    }
    
	            if ((!$mask)||($mask->Check($i))) {
	                if ($matched) $this->indexes_masked[$j] = $id;
	                $j++;
                    }
	            if ($matched) $this->indexes_full[$i] = $id;
	            $i++;
	        }
	        
	        if ($skip_full) {
	            $this->indexes_masked = $this->indexes_full;
	            $this->indexes_full = false;
                }
	    }
	} else {
	        // Avoid calling GetGroupSize (involves requires to Source Database)
	    if (($opts['masking_reader'])&&($mask)&&(!$mask->IsFull())) {
	        $this->index_full = false;
	        $this->indexes_masked = $mask->GetIDs();
	    } else {
	        $this->indexes_full = range(0, $rdr->GetGroupSize($grp) - 1);
                if (($mask)&&(!$mask->IsFull())) $this->indexes_masked = $mask->ids;
                else $this->indexes_masked = $this->indexes_full;
            }
	}
    }
 }

 function Start(&$data) {
    if ($this->skip) return;

    if ($data['masked']) {
        if ($this->indexes_masked === false)
            throw new ADEIException(translate("ITEMFilter is not configured for masked data..."));
        $this->indexes = $this->indexes_masked;
    } else {
        if ($this->indexes_full === false)
            throw new ADEIException(translate("ITEMFilter is not configured for unmasked data..."));
        $this->indexes = $this->indexes_full;
    }

 }

 function ProcessVector(&$data, &$time, &$values) {
    if ($this->skip) return false;

    foreach ($this->indexes as $idx => $id) {
        $res = $this->filter->ProcessItem($data, $time, $id, $values[$idx]);
        if ($res) return true;
    }
//    print_r($data);
//    print_r($values);
    return false;
 }
}

?>