diff --git a/webui/controller/stat/stat.php b/webui/controller/stat/stat.php index e80caf14..7cf822e5 100644 --- a/webui/controller/stat/stat.php +++ b/webui/controller/stat/stat.php @@ -15,6 +15,7 @@ class ControllerStatStat extends Controller { $db = Registry::get('db'); $this->load->model('user/user'); + $this->load->model('stat/chart'); $this->document->title = $this->data['text_statistics']; @@ -24,10 +25,19 @@ class ControllerStatStat extends Controller { $this->data['admin_user'] = Registry::get('admin_user'); $this->data['readonly_admin'] = Registry::get('readonly_admin'); + $this->data['username'] = Registry::get('username'); + + $timespan = @$this->request->get['timespan']; + + $db->select_db($db->database); + + $chart = new ModelStatChart(); + + $this->data['data'] = $chart->lineChartArchivedMessages($timespan); + + $this->render(); } } - -?> diff --git a/webui/model/stat/chart.php b/webui/model/stat/chart.php index 42e8951b..987e73cc 100644 --- a/webui/model/stat/chart.php +++ b/webui/model/stat/chart.php @@ -2,23 +2,11 @@ class ModelStatChart extends Model { - public function lineChartHamSpam($timespan, $title, $size_x, $size_y, $output){ - $ydata = array(); - $ydata2 = array(); - $dates = array(); + public function lineChartArchivedMessages($timespan){ + $data = []; $session = Registry::get('session'); - $chart = new LineChart($size_x, $size_y); - - $chart->getPlot()->getPalette()->setLineColor(array( - new Color(208, 48, 128), - )); - - $line1 = new XYDataSet(); - - $limit = $this->getDataPoints($timespan); - $range = $this->getRangeInSeconds($timespan); if($timespan == "daily"){ $grouping = "GROUP BY FROM_UNIXTIME(ts, '%Y.%m.%d. %H')"; } @@ -27,10 +15,18 @@ class ModelStatChart extends Model { if($timespan == "daily"){ $delta = 3600; - $date_format = "H:i"; + $data_points = 24; } else { $delta = 86400; - $date_format = "m.d."; + $data_points = 30; + } + + $now = time(); + $now -= $now % $delta + ($data_points-1)*$delta; + + for($i=0; $i<$data_points; $i++) { + $data[$now] = 0; + $now += $delta; } if(Registry::get('admin_user') == 0) { @@ -42,57 +38,18 @@ class ModelStatChart extends Model { if($q) { $q .= ",?"; } else { $q = "?"; } } reset($auditdomains); - $query = $this->db->query("select (arrived-(arrived%$delta)) as ts, count(*) as num from " . VIEW_MESSAGES . " where arrived > $range AND todomain IN ($q) $domains $grouping ORDER BY ts DESC limit $limit", $auditdomains); + $query = $this->db->query("select (arrived-(arrived%$delta)) as ts, count(*) as num from " . VIEW_MESSAGES . " where arrived > $range AND todomain IN ($q) $domains $grouping ORDER BY ts DESC limit $data_points", $auditdomains); } else { - $query = $this->db->query("select (arrived-(arrived%$delta)) as ts, count(*) as num from " . TABLE_META . " where arrived > $range $grouping ORDER BY ts DESC limit $limit"); + $query = $this->db->query("select (arrived-(arrived%$delta)) as ts, count(*) as num from " . TABLE_META . " where arrived > $range $grouping ORDER BY ts DESC limit $data_points"); } - foreach ($query->rows as $q) { - array_push($ydata, $q['num']); - array_push($dates, date($date_format, $q['ts'])); - } - - // If there's a single data point, then we can't draw a line - // so we add an artificial value of 0 - if(count($ydata) <= 1) { - if($timespan == "daily") { - $ts = NOW - (NOW % 3600) - 3600; - } else { - $ts = NOW - (NOW % 86400) - 86400; + if(isset($data[$q['ts']])) { + $data[$q['ts']] = $q['num']; } - - array_push($ydata, 0); - array_push($dates, date($date_format, $ts)); } - - if($query->num_rows >= 15) { - $i = 0; - foreach($dates as $k => $v) { - $i++; - if($i % 3) { $dates[$k] = ""; } - } - reset($dates); - } - - - - $ydata = array_reverse($ydata); - $dates = array_reverse($dates); - - for($i=0; $iaddPoint(new Point("$ts", $ydata[$i])); - } - - - $chart->setDataSet($line1); - - $chart->setTitle($title); - $chart->getPlot()->setGraphCaptionRatio(0.80); - - $this->sendOutput($chart, $output); + return $data; } diff --git a/webui/view/theme/default/templates/stat/stat.tpl b/webui/view/theme/default/templates/stat/stat.tpl index 96baab59..a6e94343 100644 --- a/webui/view/theme/default/templates/stat/stat.tpl +++ b/webui/view/theme/default/templates/stat/stat.tpl @@ -1,12 +1,42 @@

- + - +

-

+
+ +
+ + + +