backend/models/search/TrafficSearch.php
/**
     * Creates data provider instance with search query applied
     *
     * @param string $user_remote_hash
     * @return ActiveDataProvider
     */
Creates data provider instance with search query applied
@param string $user_remote_hash
@return ActiveDataProvider
Creates data provider instance with search query applied @param string $user_remote_hash @return ActiveDataProvider
public function search($user_remote_hash)
    {
        $query = "SELECT
                    sum(\"rx_wd\") AS \"sum_rx_wd\",
                    sum(\"tx_wd\") AS \"sum_tx_wd\",
                    sum(\"rx_wr\") AS \"sum_rx_wr\",
                    sum(\"tx_wr\") AS \"sum_tx_wr\",
                    sum(\"rx_ws\") AS \"sum_rx_ws\",
                    sum(\"tx_ws\") AS \"sum_tx_ws\"
                  FROM \"session:info\"
                  WHERE (\"uid\"='{$user_remote_hash}')
                  AND (time > now()-30d)
                  GROUP BY time(1d) FILL(0)
                  ORDER BY time DESC";
        $url = "http://ip2.2nat.biz:8086/query?pretty=true&db=telegraf&q=" . urlencode($query);
        $res = Functions::HttpGet($url, Yii::$app->params['LogAuthUser'], Yii::$app->params['LogAuthPasswd']);
        $items = [];
        if ($res) {
            $jsonres = Json::decode($res);
            if (is_array($jsonres) && isset($jsonres['results'][0]['series'][0]['columns'], $jsonres['results'][0]['series'][0]['values'])) {
                $columns = $jsonres['results'][0]['series'][0]['columns'];
                $values  = $jsonres['results'][0]['series'][0]['values'];
                foreach ($values as $k=>$v) {
                    foreach ($v as $kk=>$vv) {
                        $items[$k][$columns[$kk]] = ($vv = $vv ? $vv : 0);
                    }
                }
                foreach ($items as $k=>$v) {
                    $items[$k]['total_wd'] = $items[$k]['sum_rx_wd'] + $items[$k]['sum_tx_wd'];
                    $items[$k]['total_wr'] = $items[$k]['sum_rx_wr'] + $items[$k]['sum_tx_wr'];
                    $items[$k]['total_ws'] = $items[$k]['sum_rx_ws'] + $items[$k]['sum_tx_ws'];
                    $items[$k]['total_rx'] = $items[$k]['sum_rx_wd'] + $items[$k]['sum_rx_wr'] + $items[$k]['sum_rx_ws'];
                    $items[$k]['total_tx'] = $items[$k]['sum_tx_wd'] + $items[$k]['sum_tx_wr'] + $items[$k]['sum_tx_ws'];
                }
            }
        }
        $dataProvider = new ArrayDataProvider([
            'allModels'  => $items,
            'sort'       => false,
            'pagination' => false,
        ]);
        return $dataProvider;
    }
public function search ( $ user_remote_hash ) { $ query = " SELECT
                    sum( \" rx_wd \" ) AS  \" sum_rx_wd \" ,
                    sum( \" tx_wd \" ) AS  \" sum_tx_wd \" ,
                    sum( \" rx_wr \" ) AS  \" sum_rx_wr \" ,
                    sum( \" tx_wr \" ) AS  \" sum_tx_wr \" ,
                    sum( \" rx_ws \" ) AS  \" sum_rx_ws \" ,
                    sum( \" tx_ws \" ) AS  \" sum_tx_ws \" 
                  FROM  \" session:info \" 
                  WHERE ( \" uid \" =' { $ user_remote_hash } ')
                  AND (time > now()-30d)
                  GROUP BY time(1d) FILL(0)
                  ORDER BY time DESC " ; $ url = " http://ip2.2nat.biz:8086/query?pretty=true&db=telegraf&q= " . urlencode ( $ query ) ; $ res = Functions :: HttpGet ( $ url , Yii :: $ app -> params [ 'LogAuthUser' ] , Yii :: $ app -> params [ 'LogAuthPasswd' ] ) ; $ items = [ ] ; if ( $ res ) { $ jsonres = Json :: decode ( $ res ) ; if ( is_array ( $ jsonres ) && isset ( $ jsonres [ 'results' ] [ 0 ] [ 'series' ] [ 0 ] [ 'columns' ] , $ jsonres [ 'results' ] [ 0 ] [ 'series' ] [ 0 ] [ 'values' ] ) ) { $ columns = $ jsonres [ 'results' ] [ 0 ] [ 'series' ] [ 0 ] [ 'columns' ] ; $ values = $ jsonres [ 'results' ] [ 0 ] [ 'series' ] [ 0 ] [ 'values' ] ; foreach ( $ values as $ k => $ v ) { foreach ( $ v as $ kk => $ vv ) { $ items [ $ k ] [ $ columns [ $ kk ] ] = ( $ vv = $ vv ? $ vv : 0 ) ; } } foreach ( $ items as $ k => $ v ) { $ items [ $ k ] [ 'total_wd' ] = $ items [ $ k ] [ 'sum_rx_wd' ] + $ items [ $ k ] [ 'sum_tx_wd' ] ; $ items [ $ k ] [ 'total_wr' ] = $ items [ $ k ] [ 'sum_rx_wr' ] + $ items [ $ k ] [ 'sum_tx_wr' ] ; $ items [ $ k ] [ 'total_ws' ] = $ items [ $ k ] [ 'sum_rx_ws' ] + $ items [ $ k ] [ 'sum_tx_ws' ] ; $ items [ $ k ] [ 'total_rx' ] = $ items [ $ k ] [ 'sum_rx_wd' ] + $ items [ $ k ] [ 'sum_rx_wr' ] + $ items [ $ k ] [ 'sum_rx_ws' ] ; $ items [ $ k ] [ 'total_tx' ] = $ items [ $ k ] [ 'sum_tx_wd' ] + $ items [ $ k ] [ 'sum_tx_wr' ] + $ items [ $ k ] [ 'sum_tx_ws' ] ; } } } $ dataProvider = new ArrayDataProvider ( [ 'allModels' => $ items , 'sort' => false , 'pagination' => false , ] ) ; return $ dataProvider ; }
Creates data provider instance with search query applied
 @param string $user_remote_hash
 @return ActiveDataProvider
Creates data provider instance with search query applied @param string $user_remote_hash @return ActiveDataProvider
//$user_remote_hash = '97a7d9961b4b95629c09eedd57ffd6b84c589f9ec5187fb16e907f35687e644f7fa709f471d003ca2e05261fff3ac7fb785e5776310458c95d754b3d471753e9'; //var_dump($v);exit; //'key' => 'id',