/adei/trunk

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

« back to all changes in this revision

Viewing changes to classes/resamplers/lastresampler.php

  • Committer: Suren A. Chilingaryan
  • Date: 2020-02-06 06:07:51 UTC
  • Revision ID: csa@suren.me-20200206060751-n4lbi25y4wh10f3u
Generalize data filtering/resampling in the VIEWs and provide common tools for secondary time series plots (based on work of Jalal)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
class LASTResampler extends RESAMPLER {
 
4
  var $max_gap;
 
5
 
 
6
  function __construct(REQUEST $req  = NULL, $opts = false, $sampling = false) {
 
7
    parent::__construct($req, $opts, $sampling);
 
8
 
 
9
    $this->max_gap = $this->GetOption('max_gap', 0);
 
10
  }
 
11
 
 
12
  function Resample($data, $flags = 0) {
 
13
    $nchan = $this->GetNumberOfChannels($data);
 
14
 
 
15
    $out = array(
 
16
        'info' => $data['info'],
 
17
        'data' => array()
 
18
    );
 
19
 
 
20
    $keys = array_keys($data['data']);
 
21
    $src = &$data['data'];
 
22
 
 
23
    $filtered = 0;
 
24
    for ($i = 0; $i < sizeof($keys); $i++) {
 
25
        $vout = array();
 
26
        $outkey = $keys[$i];
 
27
        for ($ch = 0; $ch < $nchan; $ch++) {
 
28
            for ($j = $i; $j >=0; $j--) {
 
29
                $key = $keys[$j];
 
30
 
 
31
                if (($this->max_gap)&&(($outkey - $key) > $this->max_gap)) {
 
32
                    $j = -1;
 
33
                    break;
 
34
                }
 
35
 
 
36
                if (is_numeric($src[$key][$ch])) {
 
37
                    $vout[$ch] = $src[$key][$ch];
 
38
                    break;
 
39
                }
 
40
            }
 
41
            if ($j < 0 ) break;
 
42
        }
 
43
        
 
44
        if (sizeof($vout) == $nchan) {
 
45
            $out['data'][$outkey] = $vout;
 
46
        } else {
 
47
            $filtered++;
 
48
        }
 
49
    }
 
50
 
 
51
    $out['info']['incomplete'] = $filtered;
 
52
    return $out;
 
53
  }
 
54
}
 
55
 
 
56
?>
 
 
b'\\ No newline at end of file'