Пример #1
0
 protected function health_core($from_secord, $to_secord)
 {
     $stepNum = Variables::getStepNum();
     $period_secord = $from_secord - $to_secord;
     $step_secord = (int) ($period_secord / $stepNum);
     $now = time();
     #_tp means time point.
     $beforebefore_tp = $now - $from_secord;
     $before_tp = $now - $to_secord;
     $account_time = array();
     $usage_rate = array('success' => 0, 'all' => 0);
     $usage_rate_exact = array('success' => 0, 'all' => 0);
     $aliving = array();
     $codedist = array(300 => array(), 3600 => array(), 14400 => array(), 'MORE' => array());
     $aset = array();
     $codeset = array();
     $slist = Account::period($beforebefore_tp, $before_tp);
     $total = 0.0;
     $interval = array();
     $last = array();
     $interval_count = array();
     foreach ($slist as $account) {
         $username = $account['username'];
         $time = $account['time'];
         $code = $account['code'];
         if ($code == -1) {
             $usage_rate['all'] += 1;
             if (isset($last[$username])) {
                 $interval[$username] += $last[$username] - $time;
                 $last[$username] = $time;
                 $interval_count[$username] += 1;
             } else {
                 $interval[$username] = 0;
                 $last[$username] = $time;
                 $interval_count[$username] = 0;
             }
         } elseif ($code == 0) {
             $usage_rate['success'] += 1;
         }
         if (isset($aset[$username])) {
             if ($code == -1) {
                 unset($aset[$username]);
                 unset($codeset[$username]);
                 $usage_rate_exact['all'] += 1;
             } elseif ($code == 0) {
                 $keep = $aset[$username] - $time;
                 $account_time[] = $keep;
                 $total += $keep;
                 $usage_rate_exact['success'] += 1;
                 if ($keep <= 300) {
                     $keep = 300;
                 } elseif ($keep <= 3600) {
                     $keep = 3600;
                 } elseif ($keep <= 14400) {
                     $keep = 14400;
                 } else {
                     $keep = 'MORE';
                 }
                 if (isset($codedist[$keep][$codeset[$username]])) {
                     $codedist[$keep][$codeset[$username]] += 1;
                 } else {
                     $codedist[$keep][$codeset[$username]] = 1;
                 }
             } else {
                 return redirect('/');
             }
         } else {
             if ($code == -1) {
                 continue;
             } elseif ($code == 0) {
                 $aliving[$username] = Variables::secordtoHMS($now - $time);
             } else {
                 $aset[$username] = $time;
                 $codeset[$username] = $code;
             }
         }
     }
     $res = Variables::chartjs_line_one_inited_with_timedist('account');
     foreach ($account_time as $time) {
         $id = Variables::timedist_getindex($time);
         $res['datasets'][0]['data'][$id] += 1;
     }
     $res = json_encode($res);
     $all_interval = 0;
     $all_interval_count = 0;
     foreach ($interval as $username => $alltime) {
         $all_interval += $alltime;
         $all_interval_count += $interval_count[$username];
     }
     if ($all_interval_count != 0) {
         $ave_interval = Variables::secordtoHMS($all_interval / $all_interval_count);
     } else {
         $ave_interval = 0;
     }
     $sus = $usage_rate['success'];
     $all = $usage_rate['all'];
     $sus_e = $usage_rate_exact['success'];
     $all_e = $usage_rate_exact['all'];
     if ($all != 0) {
         $value = number_format(100 * $sus / $all, 2);
     } else {
         $value = 0;
     }
     if (count($account_time)) {
         $ave = Variables::secordtoHMS($total / count($account_time));
     } else {
         $ave = 0;
     }
     $usage = "{$sus}" . '/' . "{$all}" . ' (' . "{$sus_e}" . '/' . "{$all_e}" . ') ' . "{$value}" . '%. Average reuse interval: ' . "{$ave_interval}" . '. Average alive duration: ' . "{$ave}" . '.';
     $cnt = count($aliving);
     $usage .= " Aliving account: {$cnt}.";
     $code_res_a = array();
     $paes = Variables::paerror();
     foreach ($codedist as $time => $codes) {
         $rest = Variables::chartjs_line_one('one');
         arsort($codes);
         foreach ($codes as $code => $count) {
             $rest['labels'][] = $paes[$code];
             $rest['datasets'][0]['data'][] = $count;
         }
         $code_res_a[$time] = json_encode($rest);
     }
     $url = action('AccountController@hstep', ['']);
     return compact('res', 'code_res_a', 'from_secord', 'to_secord', 'usage', 'aliving', 'url');
 }
Пример #2
0
 public function errortype()
 {
     $paes = Variables::paerror();
     ksort($paes);
     return view('proxy.errortype', compact('paes'));
 }