3
interface READERInterface {
4
public function __construct(&$props);
6
public function GetDatabaseList($flags = 0);
7
public function GetGroupList($flags = 0);
8
public function GetGroupInfo(LOGGROUP &$grp = NULL, $flags = 0);
9
public function GetItemList(LOGGROUP &$grp = NULL, MASK &$mask = NULL, $flags = 0);
10
public function GetExperimentList($flags = 0);
11
public function GetMaskList(LOGGROUP &$grp = NULL, $flags = 0);
13
public function CreateGroup(array &$ginfo = NULL, $flags = 0);
14
public function CreateInterval(LOGGROUP &$group = NULL, array &$iinfo = NULL, $flags = 0);
15
public function CreateMask(LOGGROUP &$grp = NULL, array &$minfo = NULL, $flags = 0);
17
public function GetGroups();
18
public function GetGroupSize(LOGGROUP &$grp = NULL);
20
public function ImportUnixTime($unix_time);
21
public function ExportUnixTime($db_time);
23
public function HaveData(LOGGROUP &$grp = NULL, $from = 0, $to = 0);
24
public function GetData(LOGGROUP &$grp = NULL, $from = 0, $to = 0);
25
public function PushData(LOGGROUP &$grp, $time, $data);
26
public function RemoveData(LOGGROUP &$grp, $time);
28
public function Backup(&$binfo);
31
abstract class READER implements READERInterface {
51
const NEED_ITEMINFO = 8;
53
const BACKUP_FULL = 1;
55
function __construct(&$props) {
56
if ($props instanceof REQUEST) {
58
$this->server = $this->req->GetServerInfo();
60
$this->srvid = $props->props['db_server'];
63
$this->server = &$props;
68
if (isset($this->server['database']))
69
$this->dbname = $this->server['database'];
71
$this->dbname = false;
73
$this->time_format = "U.u";
74
$this->time_zone = new DateTimeZone("GMT");
76
$this->gmt_timezone = new DateTimeZone("GMT");
78
$this->opts = new OPTIONS($props);
80
$date_limit = $this->opts->Get('date_limit');
82
if (is_array($date_limit)) {
83
if (is_int($date_limit[0])) $this->start_date = $date_limit[0];
84
else $this->start_date = strtotime($date_limit[0]);
85
if (is_int($date_limit[1])) $this->end_date = $date_limit[1];
86
else $this->end_date = strtotime($date_limit[1]);
88
if (is_int($date_limit)) $this->start_date = $date_limit;
89
else $this->start_date = strtotime($date_limit);
90
$this->end_date = false;
93
$this->start_date = false;
94
$this->end_date = false;
97
$time_module = $this->opts->Get('time_module');
99
if (!include_once("time/" . strtolower($time_module) . '.php')) {
100
throw new ADEIException(translate("Unsupported time module is configured: \"%s\"", $time_module));
103
$time_options = $this->opts->Get('time_options');
104
$cl = strtoupper($time_module);
105
$this->time_module = new $cl($this, $time_options);
106
} else $this->time_module = false;
108
$group_class = false;
111
function ImportTime(DateTime $dt) {
112
if ($this->time_module) return $this->time_module->ImportTime($dt);
114
$dt->setTimezone($this->time_zone);
115
return $dt->format($this->time_format);
118
function ExportTime($db_time) {
119
if ($this->time_module) return $this->time_module->ExportTime($db_time);
121
if ($this->time_zone) {
122
$ctz = date_default_timezone_get();
123
date_default_timezone_set($this->time_zone->getName());
124
$dt = new DateTime($db_time);
125
date_default_timezone_set($ctz);
127
// $dt->setTimezone($this->gmt_timezone);
130
return new DateTime($db_time);
133
function ImportUnixTime($unix_time) {
134
$itime = (int)floor($unix_time);
136
if ($itime==$unix_time) {
137
// Time zone should be specified, esle "e" output is invalid
138
return $this->ImportTime(new DateTime("@$itime", $this->gmt_timezone));
140
if (is_float($unix_time)) $subsec = strchr(sprintf("%F", $unix_time), '.');
141
else $subsec = strchr($unix_time, '.');
143
// DS: Due to the bug in PHP (precision is limited to 10ns)
144
if (strlen($subsec) > 9) $subsec = substr($subsec, 0, 9);
145
return $this->ImportTime(new DateTime(strftime("%Y-%m-%dT%H:%M:%S", $itime) . $subsec, $this->gmt_timezone));
146
// return $this->ImportTime(new DateTime(strftime("%Y/%m/%d %H:%M:%S", $itime) . $subsec, $this->gmt_timezone));
150
function ExportUnixTime($db_time) {
151
$dt = $this->ExportTime($db_time);
152
return $dt->format("U.u");
155
function GetDatabaseList($flags = 0) {
157
$server = $this->req->GetServerConfig();
159
throw new ADEIException(translate("The data source server is not specified"));
162
foreach ($server['database'] as $name) {
163
$dblist[$name] = array(
171
function GetGroupList($flags = 0) {
172
return $this->GetGroupInfo($gr=NULL, $flags);
175
function GetExperimentList($flags = 0) {
179
function GetMaskList(LOGGROUP &$grp = NULL, $flags = 0) {
183
function CheckGroup(LOGGROUP &$grp = NULL) {
185
if (($this->group_class)&&(!$grp instanceof $this->group_class))
186
throw Exception(translate("Invalid LOGGROUP supplied"));
188
$grinfo = $this->req->GetGroupInfo();
189
$grp = $this->CreateGroup($grinfo);
194
function CreateGroup(array &$ginfo = NULL, $flags = 0) {
195
if (!$ginfo) $ginfo = $this->req->GetGroupInfo();
197
if ($this->group_class) return new $this->group_class($ginfo, $this, $flags);
198
return new LOGGROUP($ginfo, $this, $flags);
201
function CreateMask(LOGGROUP &$grp = NULL, array &$minfo = NULL, $flags = 0) {
203
if ($this->req instanceof GROUPRequest)
204
$minfo = $this->req->GetMaskInfo();
206
//$grp = $this->CheckGroup($grp);
208
return new MASK($minfo);
211
function CreateInterval(LOGGROUP &$grp = NULL, array &$iinfo = NULL, $flags = 0) {
213
if ($this->req instanceof DATARequest)
214
$iinfo = $this->req->GetIntervalInfo();
216
$grp = $this->CheckGroup($grp);
218
$ivl = new INTERVAL($iinfo, $this, $grp, $flags);
220
if ((($this->start_date)&&($ivl->GetWindowStart() < $this->start_date))||(($this->end_date)&&($ivl->GetWindowEnd() > $this->end_date))) {
221
$ivl->Limit($this->start_date, $this->end_date);
228
function GetGroups() {
229
$groups = $this->GetGroupList();
232
foreach (array_keys($groups) as $group) {
233
$ginfo = array("db_group" => $group);
234
array_push($list, $this->CreateGroup($ginfo));
240
function GetGroupSize(LOGGROUP &$grp = NULL) {
241
return sizeof($this->GetItemList($grp));
244
function HaveData(LOGGROUP &$grp = NULL, $from = 0, $to = 0) {
248
function PushData(LOGGROUP &$grp, $time, $data) {
249
throw new ADEIException(get_class($this) . ". PushData is not implemented");
252
function RemoveData(LOGGROUP &$grp, $time) {
253
throw new ADEIException(get_class($this) . ". RemoveData is not implemented");
256
/* DS: check for invalid columns number */
257
function Clean(&$lg, $from = 0, $to = 0) {
258
$data = $this->GetData($lg, $from, $to);
259
foreach ($data as $t => $value) {
260
if (sizeof($value)==0) {
261
$this->RemoveData($lg, $t);
265
foreach ($value as $v) {
273
$this->RemoveData($lg, $t);
278
function Backup(&$binfo) {
279
throw new ADEIException(get_class($this) . ". Backup is not implemented");
282
function Export(DATAHandler &$h = NULL, LOGGROUP &$grp = NULL, MASK &$mask = NULL, $from = 0, $to = 0, $opts = 0) {
283
if (!$h) $h = new CSVHandler();
284
$grp = $this->CheckGroup($grp);
286
$names = $this->GetItemList($grp);
287
$data = $this->GetData($grp, $from, $to);
293
foreach ($names as $name) {
294
$h->DataHeader($name["name"], $columns);
300
foreach ($data as $time => $row) {
301
if (sizeof($row) != $columns) continue;
304
$h->TimeValue($time);
306
foreach ($row as $i => &$column) {
307
$h->DataValue($column, $i);
315
function ExportCSV(STRINGHandler &$h = NULL, LOGGROUP &$grp = NULL, MASK &$mask = NULL, $from = 0, $to = 0, $opts = 0) {
316
return $this->Export(new CSVHandler($h), $grp, $msk, $from, $to, $opts);
320
function ExportCSV(STRINGHandler &$h = NULL, LOGGROUP &$grp = NULL, $from = 0, $to = 0, $opts = 0) {
321
if (!$h) $h = new STRINGStreamHandler();
322
$grp = $this->CheckGroup($grp);
324
$subseconds = !$this->opts->Get('ignore_subsecond');
326
$names = $this->GetItemList($grp);
327
$data = $this->GetData($grp, $from, $to);
330
$h->Process("Date/Time");
331
foreach ($names as $name) {
332
$h->Process(", " . preg_replace("/,/", " ", $name["name"]));
337
$saved_tz = date_default_timezone_get ();
338
date_default_timezone_set("UTC");
339
foreach ($data as $time => $row) {
340
if (sizeof($row) != $columns) continue;
343
$subsec = strchr(sprintf("%.6F", $time), '.');
344
$h->Process(date("d-M-y H:i:s", $time) . $subsec);
346
$h->Process(date("d-M-y H:i:s", $time));
347
foreach ($row as $column) {
348
$h->Process(", " . $column);
352
date_default_timezone_set($saved_tz);
359
class NULLReader implements READERInterface {
360
function __construct(&$props) {}
362
function GetDatabaseList($flags = 0) {
363
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
366
function GetGroupList($flags = 0) {
367
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
370
function GetGroupInfo(LOGGROUP &$grp = NULL, $flags = 0) {
371
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
374
function GetItemList(LOGGROUP &$grp = NULL, MASK &$mask = NULL, $flags = 0) {
375
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
378
function GetExperimentList($flags = 0) {
379
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
382
function GetMaskList(LOGGROUP &$grp = NULL, $flags = 0) {
383
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
386
function CreateGroup(array &$ginfo = NULL, $flags = 0) {
387
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
390
function CreateInterval(LOGGROUP &$group = NULL, array &$iinfo = NULL, $flags = 0) {
391
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
394
function CreateMask(LOGGROUP &$grp = NULL, array &$minfo = NULL, $flags = 0) {
395
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
398
function GetGroups() {
399
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
402
function GetGroupSize(LOGGROUP &$grp = NULL) {
403
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
406
function ImportUnixTime($unix_time) {
407
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
410
function ExportUnixTime($db_time) {
411
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
414
function HaveData(LOGGROUP &$grp = NULL, $from = 0, $to = 0) {
415
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
418
function GetData(LOGGROUP &$grp = NULL, $from = 0, $to = 0) {
419
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
422
function PushData(LOGGROUP &$grp, $time, $data) {
423
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
426
function RemoveData(LOGGROUP &$grp, $time) {
427
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
430
function Backup(&$binfo) {
431
throw new ADEIException(get_class($this) . ". " . __METHOD__ . " is not implemented");
b'\\ No newline at end of file'