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

  • Committer: Suren A. Chilingaryan
  • Date: 2018-07-13 01:23:18 UTC
  • Revision ID: csa@suren.me-20180713012318-kztot7qj2bnmk576
Sample COUNTView for ASEC

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
class COUNTView extends VIEW {
 
4
 var $title = "Count Records";
 
5
 
 
6
 function __construct(REQUEST $req  = NULL, $options) {
 
7
    parent::__construct($req, $options);
 
8
 }
 
9
 
 
10
 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
 
 
44
        array("input" => array("label" => _("x"), "id" => "x_mult", "type" => "text", "size" => "3", "value" => "1")),
 
45
        array("select" => array("label" => _("*"), "id" => "x", "options" => $result)), 
 
46
        array("xml"=>"<br/>"),
 
47
        array("input" => array("label" => _("y"), "id" => "y_mult", "type" => "text", "size" => "3", "value" => "1")),
 
48
        array("select" => array("label" => _("*"), "id" => "y", "options" => $result2)),
 
49
        array("xml"=>"<br/>"),
 
50
        array("input" => array("label" => _("From"), "id" => "count_min", "type" => "text", size => "8", "value" => "0")),
 
51
        array("input" => array("label" => _("To"), "id" => "count_max", "type" => "text", size => "8", "value" => "0"))
 
52
    );
 
53
 }
 
54
 
 
55
 function GetView() {
 
56
    global $TMP_PATH;
 
57
 
 
58
    $req = $this->req->CreateDataRequest();
 
59
    $x = $req->GetProp("view_x", false);
 
60
    $y = $req->GetProp("view_y", false);
 
61
    $x_mult = $req->GetProp("view_x_mult", 1);
 
62
    $y_mult = $req->GetProp("view_y_mult", 1);
 
63
    $min = $req->GetProp("view_count_min", false);
 
64
    $max = $req->GetProp("view_count_max", false);
 
65
    
 
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['mean'.$x_id];
 
97
                if ($y) $vy = $v['mean'.$y_id];
 
98
                else $vy = 0;
 
99
                
 
100
                $sum = $x_mult * $vx + $y_mult * $vy;
 
101
                
 
102
                if ($min !== false) {
 
103
                    if ($sum < $min) continue;
 
104
                }
 
105
 
 
106
                if ($max !== false) {
 
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"));
 
122
 }
 
123
};
 
124
 
 
125
?>
 
 
b'\\ No newline at end of file'