/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/views/countview.php

  • Committer: Suren A. Chilingaryan
  • Date: 2018-07-15 01:53:01 UTC
  • Revision ID: csa@suren.me-20180715015301-s17qbq19snb3wlr5
Adding generalized data functions to VIEW

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
 
2
require_once($ADEI_ROOTDIR . "/classes/views/basehistogramview.php");
2
3
 
3
 
class COUNTView extends VIEW {
 
4
class COUNTView extends BASEHistogramView {
4
5
 var $title = "Count Records";
5
6
 
6
7
 function __construct(REQUEST $req  = NULL, $options) {
7
8
    parent::__construct($req, $options);
 
9
    $this->max_points = $this->GetOption('max_points', 100000);
8
10
 }
9
11
 
10
12
 function GetOptions() {
11
 
    $req = $this->req->CreateGroupRequest();
12
 
    $x = $req->GetProp("view_x", false);
13
 
    if ($x) list($x_gid, $x_id) = explode(":", $x);
14
 
    else list($x_gid, $x_id) = array(0, 0);
15
 
 
16
 
    $rdr = $req->CreateReader();
17
 
    $group = $rdr->CreateGroup();
18
 
    $caches = $rdr->CreateCacheSet($group, $mask);
19
 
 
20
 
    $gid = 0;
21
 
    $result = array();
22
 
    $result2 = array();
23
 
    foreach ($caches as $key => $cachewrap) {
24
 
        array_push($result, array("label" => $cachewrap->GetGroupTitle(), "disabled" => 1));
25
 
        array_push($result2, array("label" => $cachewrap->GetGroupTitle(), "disabled" => 1));
26
 
 
27
 
        $id = 0;
28
 
        $list = $cachewrap->GetItemList();
29
 
        foreach ($list as $id => $info) {
30
 
            $title = $info['name'];
31
 
            array_push($result, array("value" => "$gid:$id", "label" => "  $title"));
32
 
            if (($x_gid == $gid)&&($x_id != $id))
33
 
                array_push($result2, array("value" => "$gid:$id", "label" => "  $title"));
34
 
            $id++;
35
 
        }
36
 
        $gid++;
37
 
    }
38
 
 
39
 
 
40
 
    return array(
41
 
//        array("input" => array("label" => _("Channel Combination (i.e. v1 - 2 * v2)"), "id" => "count_formula", "type" => "text", "value" => "v1")),
42
 
//        array("xml"=>"<br/>"),
43
 
 
 
13
    $chan = $this->GetDataVariants(array("x", "y"), VIEW::FORBID_MULTIPLE_GROUPS);
 
14
    $hist = $this->GetHistOptions();
 
15
 
 
16
    return array_merge(array(
44
17
        array("input" => array("label" => _("x"), "id" => "x_mult", "type" => "text", "size" => "3", "value" => "1")),
45
 
        array("select" => array("label" => _("*"), "id" => "x", "options" => $result)), 
 
18
        array("select" => array("label" => _("*"), "id" => "x", "options" => $chan[0])), 
46
19
        array("xml"=>"<br/>"),
47
20
        array("input" => array("label" => _("y"), "id" => "y_mult", "type" => "text", "size" => "3", "value" => "1")),
48
 
        array("select" => array("label" => _("*"), "id" => "y", "options" => $result2)),
 
21
        array("select" => array("label" => _("*"), "id" => "y", "options" => $chan[1])),
49
22
        array("xml"=>"<br/>"),
50
23
        array("input" => array("label" => _("From"), "id" => "count_min", "type" => "text", size => "8", "value" => "")),
51
 
        array("input" => array("label" => _("To"), "id" => "count_max", "type" => "text", size => "8", "value" => ""))
52
 
    );
 
24
        array("input" => array("label" => _("To"), "id" => "count_max", "type" => "text", size => "8", "value" => "")),
 
25
        array("xml"=>"<br/>"),
 
26
        array("input" => array("label" => _("Test"), "id" => "count_test", "type" => "text", "value" => "")),
 
27
        array("xml"=>"<br/>"),
 
28
    ), $hist);
53
29
 }
54
30
 
55
31
 function GetView() {
56
32
    global $TMP_PATH;
57
33
 
58
34
    $req = $this->req->CreateDataRequest();
59
 
    $x = $req->GetProp("view_x", false);
60
 
    $y = $req->GetProp("view_y", false);
61
35
    $x_mult = $req->GetProp("view_x_mult", 1);
62
36
    $y_mult = $req->GetProp("view_y_mult", 1);
63
37
    $min = $req->GetProp("view_count_min", false);
64
38
    $max = $req->GetProp("view_count_max", false);
 
39
    $test = $req->GetProp("view_count_test", false);
65
40
    
66
 
    if (!$x) 
67
 
        throw new ADEIException(translate("Parameter view_x should be set"));
68
 
 
69
 
    list($x_gid, $x_id) = explode(":", $x);
70
 
    list($y_gid, $y_id) = explode(":", $y);
71
 
 
72
 
    if ((!$y)&&($x_gid != $y_gid))    
73
 
        throw new ADEIException(translate("Both x and y should belong to the same group"));
74
 
 
75
 
    $rdr = $req->CreateReader();
76
 
    $group = $rdr->CreateGroup();
77
 
    $caches = $rdr->CreateCacheSet($group);
78
 
    $iv = $caches->CreateInterval($req, true);
79
 
 
80
 
 
81
 
    $gid = 0;
82
 
 
83
 
    foreach ($caches as $key => $cachewrap) {
84
 
        if ($gid != $x_gid) {
85
 
            $gid++;
86
 
            continue;
87
 
        }
88
 
 
89
 
        $total = 0;
90
 
        $inrange = 0;
91
 
 
92
 
        $points = $cachewrap->GetAllPoints($iv);
93
 
        foreach($points as $t => $v) {
94
 
                $total++;
95
 
 
96
 
                $vx = $v[$x_id];
97
 
                if ($y) $vy = $v[$y_id];
98
 
                else $vy = 0;
99
 
                
100
 
                $sum = $x_mult * $vx + $y_mult * $vy;
101
 
                
102
 
                if (is_numeric($min)) {
103
 
                    if ($sum < $min) continue;
104
 
                }
105
 
 
106
 
                if (is_numeric($max)) {
107
 
                    if ($sum > $max) continue;
108
 
                }
109
 
                
110
 
                $inrange++;
111
 
        }
112
 
 
113
 
        return array(
114
 
            "info" => array(
115
 
                array("title"=>_("Total"), "value" => $total),
116
 
                array("title"=>_("In Range"), "value" => $inrange),
117
 
            )
118
 
        );
119
 
    }
120
 
 
121
 
    return array("div" => array("xml" => "not found"));
 
41
    if ($test) {
 
42
        $func = dsMathCreateFunction('$x,$y', $test);
 
43
    }
 
44
 
 
45
    $res = $this->GetData(array("x", "y"), NULL, VIEW::GET_RAW_DATA);
 
46
 
 
47
    $total = 0;
 
48
    $inrange = 0;
 
49
    $data = array();
 
50
 
 
51
    foreach($res['data'] as $t => $v) {
 
52
        $total++;
 
53
 
 
54
        $sum = $x_mult * $v[0] + $y_mult * $v[1];
 
55
        
 
56
        if ($test) {
 
57
            if (!$func($v[0], $v[1]))
 
58
                continue;
 
59
        } else {
 
60
            if (is_numeric($min)) {
 
61
                if ($sum < $min) continue;
 
62
            }
 
63
 
 
64
            if (is_numeric($max)) {
 
65
                if ($sum > $max) continue;
 
66
            }
 
67
        }
 
68
        
 
69
        $inrange++;
 
70
        array_push($data, $sum);
 
71
    }
 
72
 
 
73
    $info = array(
 
74
        array("title"=>_("Total"), "value" => $total),
 
75
        array("title"=>_("In Range"), "value" => $inrange),
 
76
    );
 
77
 
 
78
    if ($data) {
 
79
        $view = $this->GetHistView($data);
 
80
        $this->MergeViewInfo($view, $info, VIEW::MERGE_START);
 
81
    } else {
 
82
        $view = array("info" => $info);
 
83
    }
 
84
    return $view;
122
85
 }
 
86
 
 
87
 
123
88
};
124
89
 
125
90
?>
 
 
b'\\ No newline at end of file'