/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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php

class LOGReaderData extends ArrayIterator {
 private $list;
 private $items;
 private $modify_key = false;

 public function __construct($value, $items) {
    if (array_key_exists(0, $value)) {
	$this->modify_key = true;
    }

    $this->items = &$items;
    $this->list = array();

    foreach ($this->items as &$info) {
	$this->list[$info['logid']] = true;
    }

    parent::__construct($value);
 }
 
 public function key() {
    if ($this->modify_key) {
	$res = parent::current();
	return $res['time']->format('U.u');
    }
    return  parent::key();
 }

 public function current() {
    $logs = parent::current();

    $res = array();
    foreach ($this->items as $key => &$info) {
	$id = $info['logid'];
	if (array_key_exists($id, $logs)) {
	    $val = $logs[$id];
	    if (!is_numeric($val)) $val = crc32($val);
	    $res[$key] = $val;
	} else if ($id == "*") {
	    $sum = 0;
	    foreach ($logs as $id => $val) {
		if (!isset($this->list[$id])) $sum += $val;
	    }
	    $res[$key] = $sum;
	} else {
	    $res[$key] = NULL;
	}
    }

    return $res;
 }
}

class LOGReader extends READER {
 var $cache;

 var $groups;
 var $filter;
 var $params;

 function __construct(&$props) {
    parent::__construct($props);
    
    $this->groups = $this->opts->Get('groups');
 }

 function GetGroupInfo(LOGGROUP $grp = NULL, $flags = 0) {
    $groups = array();
    foreach ($this->groups as $gid => &$group) {
	if (($grp)&&(strcmp($grp->gid, $gid))) continue;

	$groups[$gid] = array(
	    'gid' => $gid,
	    'name' => $group['name']
	);
    
	if ($flags&REQUEST::NEED_INFO) {
	    $limit = $this->opts->GetDateLimit(0, time());
	    $groups[$gid]['first'] = $limit[0]; 
	    $groups[$gid]['last'] = $limit[1]; 
/*
	    if ($flags&REQUEST::NEED_COUNT) {
		$groups[$gid]['records'] = 
	    }
*/

	    if ($flags&REQUEST::NEED_ITEMINFO) {
		if ($grp) $grtest = $grp;
		else {
		    $ginfo = array("db_group" => $gid);
		    $grtest = $this->CreateGroup($ginfo);
		}

		$groups[$gid]['items'] = $this->GetItemList($grtest);
	    }
	}
    }

    if (($grp)&&(!$groups)) {
	throw new ADEIException(translate("Invalid group (%s) is specified", $grp->gid));
    }

    return $grp?$groups[$grp->gid]:$groups;
 }
 
 
 function GetItemList(LOGGROUP $grp = NULL, MASK $mask = NULL, $flags = 0) {
    if ($flags&REQUEST::ONLY_AXISINFO) {
	if (!$this->req->GetGroupOptions($grp, "axis")) return array();
    }

    $grp = $this->CheckGroup($grp, $flags);
    if (!$mask) $mask = $this->CreateMask($grp, $info=NULL, $flags);


    $items = $this->groups[$grp->gid]['items'];

    $res = array();
    for ($i = 0, $pos = 0; isset($items[$i]); $i++) {
	if (!$mask->Check($i)) continue;

	$name = (($items[$i]=="*")?"others":$items[$i]);
	$res[$pos] = array(
	    "id" => $i,
	    "uid" => $grp->gid . "__" . $name,
	    "name" =>  $name,
	    "logid" => $items[$i]
	);

	$pos++;
    }

    if ($flags&REQUEST::NEED_AXISINFO) {
	$this->AddAxisInfo($grp, $res);
    }

    return $res;
 }

 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL) {
    $grp = $this->CheckGroup($grp);

    $ivl = $this->CreateInterval($grp);
    $ivl->Limit($from, $to);

    if ($filter) {
	$mask = $filter->GetItemMask();
	$resample = $filter->GetSamplingRate();
	$limit = $filter->GetVectorsLimit();
	if ($limit) $ivl->SetItemLimit($limit);

	if (isset($filter_data)) {
	    if ($mask) $filter_data['masked'] = true;
//	    if ($resample) $filter_data['resampled'] = true;
//	    if ($limit) $filter_data['limited'] = true;
	}
    } else {
	$mask = NULL;
//	$resample = 0;
//	$limit = 0;
    }

    $log_filter = $this->GetGroupOption($grp, 'filter', array());
    $log_opts = $this->GetGroupOption($grp, 'opts', array());

    $cfg = &$this->groups[$grp->gid];

    if ($cfg['filter']) $log_filter = array_merge($log_filter, $cfg['filter']);
    if ($cfg['opts']) $log_opts = array_merge($log_opts, $cfg['opts']);

    $info = adeiAnalyzeLogs($ivl, $log_filter, $log_opts);
    if ($cfg['logs']) $res = &$info[$cfg['logs']];
    else $res = &$info[$grp->gid];

    return new LOGReaderData($res, $this->GetItemList($grp, $mask));
 }
}

?>