123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- <?php
- $this->title="Статистика";
- $this->params['breadcrumbs'][] = ['label' => 'Статистика', 'url' => ['index']];
- $this->params['breadcrumbs'][] = $this->title;
- $y = date("Y")*1;
- $m = date("m");
- // $d = cal_days_in_month(CAL_GREGORIAN, $m, $y);
- $d = date("d");
- $m = $m<10?"0$m":$m;
- $d = $d<10?"0$d":$d;
- $b_date = date("Y-".$m."-01 00:00:00");
- $e_date = date("Y-".$m."-".$d." 23:59:59");
- //$newsonmath
- $cmd = Yii::$app->db->createCommand("select count(id) as c, DATE_FORMAT(dt_pub, '%d') as day from news where `dt_pub` BETWEEN '".$b_date."' AND '".$e_date."' and active = 'Y' group by day")->queryAll();
- $newsonday = '';
- $mathday = '';
- $min = 100000;
- $max = 0;
- $i = 0;
- $maxd = '';
- $mind = '';
- $sum = 0;
- $a= [];
- foreach( $cmd as $item ){
- $i++;
- $sum += $item['c']*1;
- $newsonday .= $item['c'].',';
- $mathday .= '"'.$item['day'].'"'.',';
- $max = ( $item['c'] > $max )?$item['c']:$max;
- $maxd = ( $item['c'] > $max )?$item['d']:$maxd;
- if( date("d") != $item['day'] ) $min = ( $item['c'] < $min )?$item['c']:$min;
- if( date("d") != $item['day'] ) $mind = ( $item['c'] < $min )?$item['d']:$mind;
- $a[] = $item['c'];
- }
- sort($a);
- $count = sizeof($a); // cache the count
- $index = floor($count/2); // cache the index
- if (!$count) {
- $mid = ($max+$min)/2;
- } elseif ($count & 1) { // count is odd
- $mid = $a[$index];
- } else { // count is even
- $mid = ($a[$index-1] + $a[$index]) / 2;
- }
- $authors = Yii::$app->db->createCommand("select e, count(e) as c from (SELECT SUBSTRING_INDEX(`editors`,',',1) as e FROM `news` WHERE `dt_pub` BETWEEN '".$b_date."' AND '".$e_date."' and active = 'Y') t where 1 group by e order by e")->queryAll();
- $old_author_name = ['kondakov' => 'Вячеслав Кондаков*','bers'=>'Евгений Берсенёв','kuznecov' =>'Артём Кузнецов*', 'katya'=>'Екатерина Смолихина*', 'elena'=>'Елена Лепезина*', 'cherdanceva'=>'Александра Черданцева*'];
- //select count(id) from news as n, news_topic_relation as tr WHERE dt_pub > "'. date("Y-m-d").'" AND dt_pub < now() and n.id = tr.news_id group by tr.topic_id'
- $rubric = Yii::$app->db->createCommand("select count(tr.topic_id) as c, nt.title as t from news as n, news_topic_relation as tr, news_topic as nt where `dt_pub` BETWEEN '".$b_date."' AND '".$e_date."' and n.active = 'Y' and n.id = tr.news_id and tr.topic_id = nt.id and nt.`active`=1 and nt.`show`='Y' group by tr.topic_id")->queryAll();
- $crubric = Yii::$app->db->createCommand("select count(id) as c from news_topic where `active`=1 and `show`='Y'")->queryOne();
- $sumr = $crubric['c'];
- ?>
- <section class="content dark-mode">
- <div class="container-fluid">
- <div class="row">
- <div class="col-12 col-sm-6 col-md-3">
- <div class="info-box">
- <span class="info-box-icon bg-info elevation-1"><i class="fas fa-cog"></i></span>
- <div class="info-box-content">
- <span class="info-box-text">CPU нагрузка</span>
- <span class="info-box-number">
- <?
- $str="LANGUAGE=en_US.UTF-8 sar 1 2 | grep \"Average\" | sed 's/^.* //'";
- $out = [];
- exec($str, $out);
- echo 100-$out[0]*1;
- ?>
- <small>%</small>
- </span>
- </div>
- </div>
- </div>
- <div class="col-12 col-sm-6 col-md-3">
- <div class="info-box mb-3">
- <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-thumbs-up"></i></span>
- <div class="info-box-content">
- <span class="info-box-text">Запросов</span>
- <span class="info-box-number">
- <?
- $str = "wget -q -O - http://localhost/nginx_status |grep 'Active connections:'";
- $out = [];
- exec($str, $out);
- $s = explode(':',$out[0]);
- ?>
- <?=$s[1]?></span>
- </div>
- </div>
- </div>
- <div class="clearfix hidden-md-up"></div>
- <div class="col-12 col-sm-6 col-md-3">
- <div class="info-box mb-3">
- <span class="info-box-icon bg-success elevation-1"><i class="fas fa-shopping-cart"></i></span>
- <div class="info-box-content">
- <span class="info-box-text">Наибольшее число новостей</span>
- <span class="info-box-number"><?=$max?></span>
- </div>
- </div>
- </div>
- <div class="col-12 col-sm-6 col-md-3">
- <div class="info-box mb-3">
- <span class="info-box-icon bg-warning elevation-1"><i class="fas fa-users"></i></span>
- <div class="info-box-content">
- <span class="info-box-text">Минимум новостей</span>
- <span class="info-box-number"><?=$min?></span>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <div class="card">
- <div class="card-header">
- <h5 class="card-title">Выпуск новостей по месяцу</h5>
- <div class="card-tools">
- <button type="button" class="btn btn-tool" data-card-widget="collapse">
- <i class="fas fa-minus"></i>
- </button>
- <div class="btn-group">
- </div>
- <button type="button" class="btn btn-tool" data-card-widget="remove">
- <i class="fas fa-times"></i>
- </button>
- </div>
- </div>
- <div class="card-body">
- <div class="row">
- <div class="col-md-8">
- <p class="text-center">
- <strong>выпуски с <?=$b_date?> по <?=$e_date?></strong>
- </p>
- <div class="chart">
- <canvas id="salesChart" height="180" style="height: 180px;"></canvas>
- </div>
- </div>
- <div class="col-md-4">
- <p class="text-center">
- <strong>Дни</strong>
- </p>
- <div class="progress-group">
- Лучший день
- <span class="float-right"><b><?=$max?></b>/<?=$max?></span>
- <div class="progress progress-sm">
- <div class="progress-bar bg-primary" style="width: 100%"></div>
- </div>
- </div>
- <div class="progress-group">
- Худший день
- <span class="float-right"><b><?=$min?></b>/<?=$max?></span>
- <div class="progress progress-sm">
- <div class="progress-bar bg-danger" style="width: <?=$min*100/$max?>%"></div>
- </div>
- </div>
- <div class="progress-group">
- <span class="progress-text">усреднее число новостей</span>
- <span class="float-right"><b><?=round($sum/count($cmd))?></b>/<?=$max?></span>
- <div class="progress progress-sm">
- <div class="progress-bar bg-success" style="width: <?=round($sum/count($cmd)*100/$max)?>%"></div>
- </div>
- </div>
- <div class="progress-group">
- Медианное значение
- <span class="float-right"><b><?=$mid?></b>/<?=$max?></span>
- <div class="progress progress-sm">
- <div class="progress-bar bg-warning" style="width: <?=round($mid*100/$max)?>%"></div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-8">
- <div class="row">
- <div class="col-md-6">
- <div class="card">
- <div class="card-header">
- <h3 class="card-title">Активность авторов<a href="/manager/stats/authors"></h3><div class="card-tools"><span class="badge badge-primary">Статистика по месяцам</span></a></div>
- </div>
- <div class="card-body">
- <table class="table table-bordered">
- <thead>
- <tr>
- <th style="width: 10px">#</th>
- <th>Автор</th>
- <th>Progress</th>
- <th style="width: 40px">Label</th>
- <th style="width: 40px">количество</th>
- </tr>
- </thead>
- <tbody>
- <?
- $i = 0;
- foreach( $authors as $author ){
- $i++;
- $aname = $author['e'];
- $aname = isset($old_author_name[$aname])?$old_author_name[$aname]:$aname;
- ?>
- <tr>
- <td><?=$i?></td>
- <td><?=$aname?></td>
- <td>
- <div class="progress progress-xs">
- <div class="progress-bar progress-bar-danger" style="width: <?=round( $author['c']*100/$sum,1)?>%"></div>
- </div>
- </td>
- <td><span class="badge bg-danger"><?=round( $author['c']*100/$sum,1)?>%</span></td>
- <td><span class="badge bg-warning"><?=$author['c']?></span></td>
- </tr>
- <?}?>
- </tbody>
- </table>
- </div>
- <div class="card-footer clearfix">
- * переопубликованые материалы
- </div>
- </div>
- </div>
- <div class="col-md-6">
- <div class="card">
- <div class="card-header">
- <h3 class="card-title">Активность рубрик</h3>
- </div>
- <div class="card-body">
- <table class="table table-bordered">
- <thead>
- <tr>
- <th style="width: 10px">#</th>
- <th>Рубрика</th>
- <th>Progress</th>
- <th style="width: 40px">Label</th>
- <th style="width: 40px">количество</th>
- </tr>
- </thead>
- <tbody>
- <?
- $i = 0;
- $srub = '';
- $srubc = '';
- $bgc = '';
- foreach( $rubric as $item ){
- $i++;
- $srub .= "'".$item['t']."'".',';
- $srubc .= $item['c'].',';
- $bgc .= "'#".dechex(rand(10,255)).dechex(rand(10,255)).dechex(rand(1,255))."',";
- ?>
- <tr>
- <td><?=$i?></td>
- <td><?=$item['t']?></td>
- <td>
- <div class="progress progress-xs">
- <div class="progress-bar progress-bar-danger" style="width: <?=round( $item['c']*100/$sum,1)?>%"></div>
- </div>
- </td>
- <td><span class="badge bg-danger"><?=round( $item['c']*100/$sum,1)?>%</span></td>
- <td><span class="badge bg-warning"><?=$item['c']?></span></td>
- </tr>
- <?}?>
- </tbody>
- </table>
- </div>
- <div class="card-footer clearfix">
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="col-md-4">
- <div class="card">
- <div class="card-header">
- <h3 class="card-title">Рубрики</h3>
- <div class="card-tools">
- <button type="button" class="btn btn-tool" data-card-widget="collapse">
- <i class="fas fa-minus"></i>
- </button>
- <button type="button" class="btn btn-tool" data-card-widget="remove">
- <i class="fas fa-times"></i>
- </button>
- </div>
- </div>
- <div class="card-body">
- <canvas id="pieChart"></canvas>
- </div>
- </div>
- </div>
- </div>
- </div>
- </section>
- </div>
- <aside class="control-sidebar control-sidebar-dark">
- </aside>
- <?
- //#f56954
- ?>
- <script>
- $(function(){
- //var salesChartCanvas=$('#salesChart').get(0).getContext('2d')
- var salesChartCanvas = document.getElementById('salesChart');
- var salesChartData={labels:[<?=$mathday?>],datasets:[{label:'Goods Day',backgroundColor:'rgba(60,141,188,0.9)',borderColor:'rgba(60,141,188,0.8)',pointRadius:true,pointColor:'#3b8bba',pointStrokeColor:'rgba(60,141,188,1)',pointHighlightFill:'#fff',pointHighlightStroke:'rgba(60,141,188,1)',data:[<?=$newsonday?>]}]}
- var salesChartOptions={maintainAspectRatio:false,responsive:true,legend:{display:false},scales:{xAxes:[{gridLines:{display:true}}],yAxes:[{gridLines:{display:false}}]}}
- var salesChart=new Chart(salesChartCanvas,{type:'line',data:salesChartData,options:salesChartOptions})
- var donutData = {
- labels: [<?=$srub?>],
- datasets: [
- {
- data: [<?=$srubc?>],
- backgroundColor : [<?=$bgc?>],
- }
- ]
- }
- var pieChartCanvas = $('#pieChart').get(0).getContext('2d')
- var pieData = donutData;
- var pieOptions = {
- maintainAspectRatio : true,
- responsive : true,
- legend: false,
- }
- new Chart(pieChartCanvas, {
- type: 'doughnut',
- data: pieData,
- options: pieOptions
- })
- });
- <?=$this->render('chartjs');?>
- </script>
|