/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to classes/reader.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-06-17 23:19:26 UTC
  • Revision ID: csa@dside.dyndns.org-20080617231926-w9mpfxw6lv0r0450
Administrative interface and better handling of missing group channels

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 const NEED_ITEMINFO = 8;
54
54
 
55
55
 const BACKUP_FULL = 1;
 
56
 
 
57
 const PARAM_MISSING_ITEMS = 1; // Parameters related to recovery of missing/extra items
56
58
 
57
59
 function __construct(&$props) {
58
60
    if ($props instanceof REQUEST) {
241
243
 }
242
244
 
243
245
 function GetGroupSize(LOGGROUP &$grp = NULL) {
244
 
    return sizeof($this->GetItemList($grp));
 
246
    return sizeof($this->GetItemList($grp, $mask = new MASK()));
245
247
 }
246
248
 
247
249
 function HaveData(LOGGROUP &$grp = NULL, $from = 0, $to = 0) {
278
280
    }
279
281
 }
280
282
 
281
 
 function FixRecordItems(array &$row, LOGGROUP $grp, $expected = 0) {
 
283
 function GetGroupParameters(LOGGROUP $grp, $prm = false) {
 
284
    global $DEFAULT_MISSING_VALUE;
 
285
    
282
286
    if (!$this->groups[$grp->gid]) $this->groups[$grp->gid] = array();
283
287
    $group = &$this->groups[$grp->gid];
 
288
 
 
289
    switch ($prm) {
 
290
        case READER::PARAM_MISSING_ITEMS:
 
291
            if (!isset($group['fix_missing_items'])) {
 
292
                $opts = $this->req->GetGroupOptions($grp);
 
293
        
 
294
                $group['fix_extra_items'] = $opts->Get("fix_extra_items", false);
 
295
                $group['fix_missing_items'] = $opts->Get("fix_missing_items", false);
 
296
                $group['missing_value'] = $opts->Get("missing_value", $DEFAULT_MISSING_VALUE);
 
297
                
 
298
                if ($group['fix_missing_items']) {
 
299
                    if (is_array($group['fix_missing_items'])) {
 
300
                        if (!isset($group['fix_missing_items']['limit']))
 
301
                            $group['fix_missing_items']['limit'] = 1;
 
302
                        if (!isset($group['fix_missing_items']['value']))
 
303
                            $group['fix_missing_items']['value'] = NULL;
 
304
                    } else {
 
305
                        $group['fix_missing_items'] = array(
 
306
                            'limit' => 1,
 
307
                            'value' => NULL
 
308
                        );
 
309
                    }
 
310
                }
 
311
            }
 
312
        break;
 
313
    }
 
314
    
 
315
    return $group;
 
316
 }
 
317
 
 
318
 function FixRecordItems(array &$row, LOGGROUP $grp, $expected = 0) {
284
319
    if (!$expected) {
285
320
/*      
286
321
        The group size could change during the class execution,
295
330
    if (sizeof($row) == $expected) return true;
296
331
    
297
332
 
298
 
    if (!isset($group['fix_missing_items'])) {
299
 
        $opts = $this->req->GetGroupOptions($grp);
300
 
        
301
 
        $group['fix_extra_items'] = $opts->Get("fix_extra_items", false);
302
 
        $group['fix_missing_items'] = $opts->Get("fix_missing_items", false);
303
 
        if ($group['fix_missing_items']) {
304
 
            if (is_array($group['fix_missing_items'])) {
305
 
                if (!isset($group['fix_missing_items']['limit']))
306
 
                    $group['fix_missing_items']['limit'] = 1;
307
 
                if (!isset($group['fix_missing_items']['value']))
308
 
                    $group['fix_missing_items']['value'] = 0;
309
 
            } else {
310
 
                $group['fix_missing_items'] = array(
311
 
                    'limit' => 1,
312
 
                    'value' => 0
313
 
                );
314
 
            }
315
 
        }
316
 
    }
317
 
                
 
333
    $group = $this->GetGroupParameters($grp, READER::PARAM_MISSING_ITEMS);
 
334
 
318
335
    if (sizeof($row) > $expected) {
319
336
        if ($group['fix_extra_items']) {
320
337
            $keys = array_keys($row);
325
342
        }
326
343
    } else {
327
344
        if (($group['fix_missing_items'])&&(sizeof($row) > $group['fix_missing_items']['limit'])) {
328
 
            $row = array_merge($row, array_fill(0, $expected - sizeof($row), $group['fix_missing_items']['value']));
 
345
            $row = array_merge($row, array_fill(0, $expected - sizeof($row), $group['missing_value']));
329
346
            return true;
330
347
        }
331
348
    }           
344
361
    $names = $this->GetItemList($grp, $mask);
345
362
    $data = $this->GetData($grp, $from, $to);
346
363
 
 
364
    if (($mask)&&(is_array($mask->ids))) {
 
365
        $mask_ids = $mask->ids;
 
366
        $mask_max_id = max($mask_ids);
 
367
        if ($mask_max_id >= $this->GetGroupSize($grp)) {
 
368
            throw new ADEIException(translate("Invalid item mask is supplied. The ID:%d refers non-existing item.", $mask_max_id));
 
369
        }
 
370
    } else {
 
371
        $mask_ids = false;
 
372
    }
 
373
 
347
374
    $h->Start();
348
375
    $h->HeaderStart();
349
376
    $h->TimeHeader();
354
381
    }
355
382
    $h->HeaderEnd();
356
383
    
357
 
    if (($mask)&&(is_array($mask->ids))) {
358
 
        $mask_ids = $mask->ids;
359
 
        $mask_max_id = max($mask_ids);
360
 
    } else {
361
 
        $mask_ids = false;
362
 
    }
363
 
    
364
 
    echo "starting\n";
365
384
    foreach ($data as $time => $row) {
366
385
        if ($mask_ids) {
367
386
            if (sizeof($row) <= $mask_max_id) {
370
389
            }
371
390
        } else {
372
391
            if (sizeof($row) != $columns) {
373
 
                $this->FixRecordItems($row, $grp, $columns);
374
392
#               echo sizeof($row) . " (2)\n";
 
393
                if (!$this->FixRecordItems($row, $grp, $columns)) continue;
375
394
            }
376
395
        }
377
396
        
380
399
 
381
400
        if ($mask_ids) {
382
401
            foreach ($mask_ids as $i) {
383
 
                $h->DataValue($row[$i], $i);
 
402
                if ($row[$i] === NULL) {
 
403
                    if (!$group) $group = $this->GetGroupParameters($grp, READER::PARAM_MISSING_ITEMS);
 
404
                    $h->DataValue($group['missing_value'], $i);
 
405
 
 
406
                } else $h->DataValue($row[$i], $i);
384
407
            }
385
408
        } else {
386
409
            foreach ($row as $i => &$column) {
387
 
                $h->DataValue($column, $i);
 
410
                if ($column === NULL) {
 
411
                    if (!$group) $group = $this->GetGroupParameters($grp, READER::PARAM_MISSING_ITEMS);
 
412
                    $h->DataValue($group['missing_value'], $i);
 
413
                } else $h->DataValue($column, $i);
388
414
            }
389
415
        }
390
416
        $h->VectorEnd();