index.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. $this->title="Статистика";
  3. $this->params['breadcrumbs'][] = ['label' => 'Статистика', 'url' => ['index']];
  4. $this->params['breadcrumbs'][] = $this->title;
  5. $y = date("Y")*1;
  6. $m = date("m");
  7. // $d = cal_days_in_month(CAL_GREGORIAN, $m, $y);
  8. $d = date("d");
  9. $m = $m<10?"0$m":$m;
  10. $d = $d<10?"0$d":$d;
  11. $b_date = date("Y-".$m."-01 00:00:00");
  12. $e_date = date("Y-".$m."-".$d." 23:59:59");
  13. //$newsonmath
  14. $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();
  15. $newsonday = '';
  16. $mathday = '';
  17. $min = 100000;
  18. $max = 0;
  19. $i = 0;
  20. $maxd = '';
  21. $mind = '';
  22. $sum = 0;
  23. $a= [];
  24. foreach( $cmd as $item ){
  25. $i++;
  26. $sum += $item['c']*1;
  27. $newsonday .= $item['c'].',';
  28. $mathday .= '"'.$item['day'].'"'.',';
  29. $max = ( $item['c'] > $max )?$item['c']:$max;
  30. $maxd = ( $item['c'] > $max )?$item['d']:$maxd;
  31. if( date("d") != $item['day'] ) $min = ( $item['c'] < $min )?$item['c']:$min;
  32. if( date("d") != $item['day'] ) $mind = ( $item['c'] < $min )?$item['d']:$mind;
  33. $a[] = $item['c'];
  34. }
  35. sort($a);
  36. $count = sizeof($a); // cache the count
  37. $index = floor($count/2); // cache the index
  38. if (!$count) {
  39. $mid = ($max+$min)/2;
  40. } elseif ($count & 1) { // count is odd
  41. $mid = $a[$index];
  42. } else { // count is even
  43. $mid = ($a[$index-1] + $a[$index]) / 2;
  44. }
  45. $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();
  46. $old_author_name = ['kondakov' => 'Вячеслав Кондаков*','bers'=>'Евгений Берсенёв','kuznecov' =>'Артём Кузнецов*', 'katya'=>'Екатерина Смолихина*', 'elena'=>'Елена Лепезина*', 'cherdanceva'=>'Александра Черданцева*'];
  47. //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'
  48. $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();
  49. $crubric = Yii::$app->db->createCommand("select count(id) as c from news_topic where `active`=1 and `show`='Y'")->queryOne();
  50. $sumr = $crubric['c'];
  51. ?>
  52. <section class="content dark-mode">
  53. <div class="container-fluid">
  54. <div class="row">
  55. <div class="col-12 col-sm-6 col-md-3">
  56. <div class="info-box">
  57. <span class="info-box-icon bg-info elevation-1"><i class="fas fa-cog"></i></span>
  58. <div class="info-box-content">
  59. <span class="info-box-text">CPU нагрузка</span>
  60. <span class="info-box-number">
  61. <?
  62. $str="LANGUAGE=en_US.UTF-8 sar 1 2 | grep \"Average\" | sed 's/^.* //'";
  63. $out = [];
  64. exec($str, $out);
  65. echo 100-$out[0]*1;
  66. ?>
  67. <small>%</small>
  68. </span>
  69. </div>
  70. </div>
  71. </div>
  72. <div class="col-12 col-sm-6 col-md-3">
  73. <div class="info-box mb-3">
  74. <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-thumbs-up"></i></span>
  75. <div class="info-box-content">
  76. <span class="info-box-text">Запросов</span>
  77. <span class="info-box-number">
  78. <?
  79. $str = "wget -q -O - http://localhost/nginx_status |grep 'Active connections:'";
  80. $out = [];
  81. exec($str, $out);
  82. $s = explode(':',$out[0]);
  83. ?>
  84. <?=$s[1]?></span>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="clearfix hidden-md-up"></div>
  89. <div class="col-12 col-sm-6 col-md-3">
  90. <div class="info-box mb-3">
  91. <span class="info-box-icon bg-success elevation-1"><i class="fas fa-shopping-cart"></i></span>
  92. <div class="info-box-content">
  93. <span class="info-box-text">Наибольшее число новостей</span>
  94. <span class="info-box-number"><?=$max?></span>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="col-12 col-sm-6 col-md-3">
  99. <div class="info-box mb-3">
  100. <span class="info-box-icon bg-warning elevation-1"><i class="fas fa-users"></i></span>
  101. <div class="info-box-content">
  102. <span class="info-box-text">Минимум новостей</span>
  103. <span class="info-box-number"><?=$min?></span>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="row">
  109. <div class="col-md-12">
  110. <div class="card">
  111. <div class="card-header">
  112. <h5 class="card-title">Выпуск новостей по месяцу</h5>
  113. <div class="card-tools">
  114. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  115. <i class="fas fa-minus"></i>
  116. </button>
  117. <div class="btn-group">
  118. </div>
  119. <button type="button" class="btn btn-tool" data-card-widget="remove">
  120. <i class="fas fa-times"></i>
  121. </button>
  122. </div>
  123. </div>
  124. <div class="card-body">
  125. <div class="row">
  126. <div class="col-md-8">
  127. <p class="text-center">
  128. <strong>выпуски с <?=$b_date?> по <?=$e_date?></strong>
  129. </p>
  130. <div class="chart">
  131. <canvas id="salesChart" height="180" style="height: 180px;"></canvas>
  132. </div>
  133. </div>
  134. <div class="col-md-4">
  135. <p class="text-center">
  136. <strong>Дни</strong>
  137. </p>
  138. <div class="progress-group">
  139. Лучший день
  140. <span class="float-right"><b><?=$max?></b>/<?=$max?></span>
  141. <div class="progress progress-sm">
  142. <div class="progress-bar bg-primary" style="width: 100%"></div>
  143. </div>
  144. </div>
  145. <div class="progress-group">
  146. Худший день
  147. <span class="float-right"><b><?=$min?></b>/<?=$max?></span>
  148. <div class="progress progress-sm">
  149. <div class="progress-bar bg-danger" style="width: <?=$min*100/$max?>%"></div>
  150. </div>
  151. </div>
  152. <div class="progress-group">
  153. <span class="progress-text">усреднее число новостей</span>
  154. <span class="float-right"><b><?=round($sum/count($cmd))?></b>/<?=$max?></span>
  155. <div class="progress progress-sm">
  156. <div class="progress-bar bg-success" style="width: <?=round($sum/count($cmd)*100/$max)?>%"></div>
  157. </div>
  158. </div>
  159. <div class="progress-group">
  160. Медианное значение
  161. <span class="float-right"><b><?=$mid?></b>/<?=$max?></span>
  162. <div class="progress progress-sm">
  163. <div class="progress-bar bg-warning" style="width: <?=round($mid*100/$max)?>%"></div>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. </div>
  171. </div>
  172. <div class="row">
  173. <div class="col-md-8">
  174. <div class="row">
  175. <div class="col-md-6">
  176. <div class="card">
  177. <div class="card-header">
  178. <h3 class="card-title">Активность авторов<a href="/manager/stats/authors"></h3><div class="card-tools"><span class="badge badge-primary">Статистика по месяцам</span></a></div>
  179. </div>
  180. <div class="card-body">
  181. <table class="table table-bordered">
  182. <thead>
  183. <tr>
  184. <th style="width: 10px">#</th>
  185. <th>Автор</th>
  186. <th>Progress</th>
  187. <th style="width: 40px">Label</th>
  188. <th style="width: 40px">количество</th>
  189. </tr>
  190. </thead>
  191. <tbody>
  192. <?
  193. $i = 0;
  194. foreach( $authors as $author ){
  195. $i++;
  196. $aname = $author['e'];
  197. $aname = isset($old_author_name[$aname])?$old_author_name[$aname]:$aname;
  198. ?>
  199. <tr>
  200. <td><?=$i?></td>
  201. <td><?=$aname?></td>
  202. <td>
  203. <div class="progress progress-xs">
  204. <div class="progress-bar progress-bar-danger" style="width: <?=round( $author['c']*100/$sum,1)?>%"></div>
  205. </div>
  206. </td>
  207. <td><span class="badge bg-danger"><?=round( $author['c']*100/$sum,1)?>%</span></td>
  208. <td><span class="badge bg-warning"><?=$author['c']?></span></td>
  209. </tr>
  210. <?}?>
  211. </tbody>
  212. </table>
  213. </div>
  214. <div class="card-footer clearfix">
  215. * переопубликованые материалы
  216. </div>
  217. </div>
  218. </div>
  219. <div class="col-md-6">
  220. <div class="card">
  221. <div class="card-header">
  222. <h3 class="card-title">Активность рубрик</h3>
  223. </div>
  224. <div class="card-body">
  225. <table class="table table-bordered">
  226. <thead>
  227. <tr>
  228. <th style="width: 10px">#</th>
  229. <th>Рубрика</th>
  230. <th>Progress</th>
  231. <th style="width: 40px">Label</th>
  232. <th style="width: 40px">количество</th>
  233. </tr>
  234. </thead>
  235. <tbody>
  236. <?
  237. $i = 0;
  238. $srub = '';
  239. $srubc = '';
  240. $bgc = '';
  241. foreach( $rubric as $item ){
  242. $i++;
  243. $srub .= "'".$item['t']."'".',';
  244. $srubc .= $item['c'].',';
  245. $bgc .= "'#".dechex(rand(10,255)).dechex(rand(10,255)).dechex(rand(1,255))."',";
  246. ?>
  247. <tr>
  248. <td><?=$i?></td>
  249. <td><?=$item['t']?></td>
  250. <td>
  251. <div class="progress progress-xs">
  252. <div class="progress-bar progress-bar-danger" style="width: <?=round( $item['c']*100/$sum,1)?>%"></div>
  253. </div>
  254. </td>
  255. <td><span class="badge bg-danger"><?=round( $item['c']*100/$sum,1)?>%</span></td>
  256. <td><span class="badge bg-warning"><?=$item['c']?></span></td>
  257. </tr>
  258. <?}?>
  259. </tbody>
  260. </table>
  261. </div>
  262. <div class="card-footer clearfix">
  263. </div>
  264. </div>
  265. </div>
  266. </div>
  267. </div>
  268. <div class="col-md-4">
  269. <div class="card">
  270. <div class="card-header">
  271. <h3 class="card-title">Рубрики</h3>
  272. <div class="card-tools">
  273. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  274. <i class="fas fa-minus"></i>
  275. </button>
  276. <button type="button" class="btn btn-tool" data-card-widget="remove">
  277. <i class="fas fa-times"></i>
  278. </button>
  279. </div>
  280. </div>
  281. <div class="card-body">
  282. <canvas id="pieChart"></canvas>
  283. </div>
  284. </div>
  285. </div>
  286. </div>
  287. </div>
  288. </section>
  289. </div>
  290. <aside class="control-sidebar control-sidebar-dark">
  291. </aside>
  292. <?
  293. //#f56954
  294. ?>
  295. <script>
  296. $(function(){
  297. //var salesChartCanvas=$('#salesChart').get(0).getContext('2d')
  298. var salesChartCanvas = document.getElementById('salesChart');
  299. 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?>]}]}
  300. var salesChartOptions={maintainAspectRatio:false,responsive:true,legend:{display:false},scales:{xAxes:[{gridLines:{display:true}}],yAxes:[{gridLines:{display:false}}]}}
  301. var salesChart=new Chart(salesChartCanvas,{type:'line',data:salesChartData,options:salesChartOptions})
  302. var donutData = {
  303. labels: [<?=$srub?>],
  304. datasets: [
  305. {
  306. data: [<?=$srubc?>],
  307. backgroundColor : [<?=$bgc?>],
  308. }
  309. ]
  310. }
  311. var pieChartCanvas = $('#pieChart').get(0).getContext('2d')
  312. var pieData = donutData;
  313. var pieOptions = {
  314. maintainAspectRatio : true,
  315. responsive : true,
  316. legend: false,
  317. }
  318. new Chart(pieChartCanvas, {
  319. type: 'doughnut',
  320. data: pieData,
  321. options: pieOptions
  322. })
  323. });
  324. <?=$this->render('chartjs');?>
  325. </script>