6
"db_server" => "katrin",
7
"db_name" => "hauptspektrometer"
9
## We expecting GMT timezone, if it is not the case please specify
11
#$timezone = "Europe/Berlin";
13
## By default, we are inserting everything found in CSV file, if you need
14
## only to add missing values, please specify the writeout interval in
15
## seconds (i.e. if the gap between two records in the current database
16
## exceed this value, then it would be filled from CSV file).
19
## Try to clean invalid values from database (only for the data we have)
23
require("../adei.php");
25
$adei_timezone = date_default_timezone_get();
27
function Find(&$ginfo, $sn) {
29
foreach (array_keys($ginfo) as $gid) {
30
$size = sizeof($ginfo[$gid]['items']);
31
for ($i=0;$i<$size;$i++) {
32
if (strstr($ginfo[$gid]['items'][$i]['name'], $sn)) {
33
array_push($res, array(
45
if ((!isset($_SERVER['argc']))||($_SERVER['argc']<2)) {
46
echo translate("You should supply CSV file as an argument") . "\n";
50
$f = fopen($_SERVER['argv'][1],"r");
52
echo translate("File \"%s\" is could not be openned", $_SERVER['argv'][1]) . "\n";
62
$pos = strpos($string, ",");
65
if ($timezone) date_default_timezone_set($timezone);
66
$time = strtotime(substr($string, 0, $pos));
67
if ($timezone) date_default_timezone_set($adei_timezone);
69
if (!$from) $from = $to = $time;
71
if ($time > $to) $to = $time;
72
elseif ($time < $from) $from = $time;
80
$req = new SOURCERequest($config);
81
$reader = $req->CreateReader(REQUEST::READER_FORBID_CACHEREADER);
82
$ginfo = $reader->GetGroupList(READER::NEED_INFO|READER::NEED_ITEMINFO);
84
foreach (array_keys($ginfo) as $gid) {
85
$size = sizeof($ginfo[$gid]['items']);
86
$groups[$gid] = array("items"=>false, "size"=>$size);
87
for ($i=0;$i<$size;$i++) $groups[$gid][$i] = -1;
92
$names = split(',', preg_replace('/(^\s+|\s+$)/', "", $namestr));
96
foreach ($names as $pos => $name) {
97
$sn = strstr($name, "\\");
98
if ($sn) $sn = substr($sn, 1);
101
$res = Find($ginfo, $sn);
102
if ((!sizeof($res))&&(preg_match("/IST(WERT)?$/", $sn))) {
103
$sn = preg_replace("/[._]?IST(WERT)?$/", "", $sn);
104
$res = Find($ginfo, $sn);
107
if ((!sizeof($res))&&(preg_match("/_/", $sn))) {
108
$sn = preg_replace("/^[^_]+_/", "", $sn);
109
$res = Find($ginfo, $sn);
112
switch(sizeof($res)) {
114
echo translate("Missing column : %u(%s)", $pos, $name) . "\n";
119
echo translate("Multimatch column: %u(%s):", $pos, $name);
121
foreach ($res as $r) {
122
if ($output) echo ", ";
125
echo $r['gid'] . "(" . $ginfo[$r['gid']]['items'][$r['i']]['name'] . ")";
130
foreach ($res as $r) {
131
$groups[$r['gid']][$r['i']] = $pos;
132
$groups[$r['gid']]['items'] = true;
139
foreach ($groups as $gid=>$group) {
140
if (!$group['items']) {
141
if ($output) echo ", ";
143
echo translate("Missing groups: ");
147
$gname = preg_replace('/(^\s+|\s+$)/', "", $ginfo[$gid]['name']);
148
echo $gid . "(" . $gname . ")";
152
if ($output) echo "\n";
154
foreach ($groups as $gid=>$group) {
155
if ($group['items']) {
157
for ($i=0;$i<$group['size'];$i++) {
158
if ($group[$i] < 0) {
159
if ($output) echo ", ";
161
$gname = preg_replace('/(^\s+|\s+$)/', "", $ginfo[$gid]['name']);
162
echo translate("Group %u(%s) missing items: ", $gid, $gname);
165
echo $ginfo[$gid]['items'][$i]['name'];
169
if ($output) echo "\n";
174
echo translate("Procceed[Y/n]? ");
175
$answer = fgets(STDIN);
176
if (preg_match("/[nN]/", $answer)) exit;
179
foreach ($groups as $gid=>&$group) {
180
if ($group['items']) {
182
$gconfig["db_group"] = $gid;
183
$lgs[$gid] = $reader->CreateGroup($gconfig);
187
$reader->Clean($lgs[$gid], $from - $frequency - 1, $to + $frequency + 1);
196
$values = split(',', preg_replace('/(^\s+|\s+$)/', "", $str));
198
if ($timezone) date_default_timezone_set($timezone);
199
$time = strtotime($values[0]);
200
if ($timezone) date_default_timezone_set($adei_timezone);
202
# print $values[0] . " = " . date("c", $time) . "\n";
203
# echo $values[126] . "\n";
206
foreach ($lgs as $gid=>&$lg) {
208
$data = $reader->GetData($lg, max($min[$gid], $time - $frequency), $time + $frequency);
211
if ($data->valid()) continue;
214
$min[$gid] = $time + 1;
216
$data = array("values"=>array());
218
for ($i=0;$i<$groups[$gid]["size"];$i++) {
219
if ($groups[$gid][$i])
220
$data["values"][$i] = $values[$groups[$gid][$i]];
222
$data["values"][$i] = 0;
225
$reader->PushData($lg, $time, $data);
b'\\ No newline at end of file'