index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <?php
  2. if ($this->beginCache("dashestats", ['duration' => 60*2])) {
  3. $this->title="Статистика";
  4. $this->params['breadcrumbs'][] = ['label' => 'Статистика', 'url' => ['index']];
  5. $this->params['breadcrumbs'][] = $this->title;
  6. $y = date("Y")*1;
  7. $m = date("m");
  8. // $d = cal_days_in_month(CAL_GREGORIAN, $m, $y);
  9. $d = date("d");
  10. $m = $m<10?"0$m":$m;
  11. $d = $d<10?"0$d":$d;
  12. $b_date = date("Y-".$m."-01 00:00:00");
  13. $e_date = date("Y-".$m."-".$d." H:i:59");
  14. //$newsonmath
  15. $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();
  16. $newsonday = '';
  17. $mathday = '';
  18. $min = 100000;
  19. $max = 0;
  20. $i = 0;
  21. $maxd = '';
  22. $mind = '';
  23. $sum = 0;
  24. $a= [];
  25. foreach( $cmd as $item ){
  26. $i++;
  27. $sum += $item['c']*1;
  28. $newsonday .= $item['c'].',';
  29. $mathday .= '"'.$item['day'].'"'.',';
  30. $max = ( $item['c'] > $max )?$item['c']:$max;
  31. $maxd = ( $item['c'] > $max )?$item['d']:$maxd;
  32. if( date("d") != $item['day'] ) $min = ( $item['c'] < $min )?$item['c']:$min;
  33. if( date("d") != $item['day'] ) $mind = ( $item['c'] < $min )?$item['d']:$mind;
  34. $a[] = $item['c'];
  35. }
  36. sort($a);
  37. $count = sizeof($a); // cache the count
  38. $index = floor($count/2); // cache the index
  39. if (!$count) {
  40. $mid = ($max+$min)/2;
  41. } elseif ($count & 1) { // count is odd
  42. $mid = $a[$index];
  43. } else { // count is even
  44. $mid = ($a[$index-1] + $a[$index]) / 2;
  45. }
  46. $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();
  47. $old_author_name = ['kondakov' => 'Вячеслав Кондаков*','bers'=>'Евгений Берсенёв','kuznecov' =>'Артём Кузнецов*', 'katya'=>'Екатерина Смолихина*', 'elena'=>'Елена Лепезина*', 'cherdanceva'=>'Александра Черданцева*'];
  48. // рубрики заполнены
  49. $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();
  50. // количество рубрик
  51. $crubric = Yii::$app->db->createCommand("select count(id) as c from news_topic where `active`=1 and `show`='Y'")->queryOne();
  52. $sumr = $crubric['c'];
  53. $cnews = Yii::$app->db->createCommand("select count(id) as c from news where `dt_pub` BETWEEN '".$b_date."' AND '".$e_date."' and active = 'Y'")->queryOne();
  54. $cntnews = $cnews['c'];
  55. $cnewsp = Yii::$app->db->createCommand("select count(id) as c from news where `dt_pub` BETWEEN DATE_SUB('".$b_date."', INTERVAL 1 MONTH) AND DATE_SUB('".$e_date."', INTERVAL 1 MONTH) and active = 'Y'")->queryOne();
  56. $cntnewsp = $cnewsp['c'];
  57. $cnewsy = Yii::$app->db->createCommand("select count(id) as c from news where `dt_pub` BETWEEN '".$y."-01-01 00:00:00' AND '".$e_date."' and active = 'Y'")->queryOne();
  58. $cntnewsy = $cnewsy['c'];
  59. $cnewsyy = Yii::$app->db->createCommand("select count(id) as c from news where `dt_pub` BETWEEN DATE_SUB('".$b_date."', INTERVAL 1 YEAR) AND '".$e_date."' and active = 'Y'")->queryOne();
  60. $cntnewsyy = $cnewsyy['c'];
  61. $now = time();
  62. $ndate = strtotime( $y."-01-01");
  63. $datediff = $now - $ndate;
  64. $daysp = round($datediff / (60 * 60 * 24));
  65. $edate = strtotime( $y."-12-31");
  66. $datediff = $now - $edate;
  67. $dayso = -round($datediff / (60 * 60 * 24));
  68. $newsinterpolite = round($cntnewsy*$dayso/$daysp);
  69. $rate = Yii::$app->db->createCommand("select counter from reaction_button limit ".$cntnews)->queryAll();
  70. $cnt = [0,0,0,0,0,0];
  71. $sumrb = 0;
  72. foreach( $rate as $item ){
  73. $a = json_decode( $item['counter'] );
  74. $cnt[0] += $a[0];
  75. $cnt[1] += $a[1];
  76. $cnt[2] += $a[2];
  77. $cnt[3] += $a[3];
  78. $cnt[4] += $a[4];
  79. $cnt[5] += $a[5];
  80. $sumrb += array_sum( $a );
  81. }
  82. $cntcomment = Yii::$app->db->createCommand("select count(id) as c from comments where `created_at` BETWEEN '".$b_date."' AND '".$e_date."' and visible = 'Y'")->queryOne();
  83. $cnt_comment = $cntcomment['c'];
  84. $cntcomment = Yii::$app->db->createCommand("select count(id) as c from comments where `created_at` BETWEEN '".$b_date."' AND '".$e_date."' and visible = 'N'")->queryOne();
  85. $cnt_commenth = $cntcomment['c'];
  86. ?>
  87. <section class="content dark-mode">
  88. <div class="container-fluid">
  89. <div class="row">
  90. <div class="col-12 col-sm-6 col-md-3">
  91. <div class="info-box">
  92. <span class="info-box-icon bg-info elevation-1"><i class="fas fa-cog"></i></span>
  93. <div class="info-box-content">
  94. <span class="info-box-text">CPU нагрузка</span>
  95. <span class="info-box-number">
  96. <?
  97. $str="LANGUAGE=en_US.UTF-8 sar 1 2 | grep \"Average\" | sed 's/^.* //'";
  98. $out = [];
  99. exec($str, $out);
  100. echo 100-$out[0]*1;
  101. ?>
  102. <small>%</small>
  103. </span>
  104. </div>
  105. </div>
  106. </div>
  107. <div class="col-12 col-sm-6 col-md-3">
  108. <div class="info-box mb-3">
  109. <span class="info-box-icon bg-warning elevation-1"><i class="fas fa-users"></i></span>
  110. <div class="info-box-content">
  111. <span class="info-box-text">Запросов в секунду</span>
  112. <span class="info-box-number">
  113. <?
  114. $str = "wget -q -O - http://localhost/nginx_status |grep 'Active connections:'";
  115. $out = [];
  116. exec($str, $out);
  117. $s = explode(':',$out[0]);
  118. ?>
  119. <?=$s[1]?></span>
  120. </div>
  121. </div>
  122. </div>
  123. <div class="clearfix hidden-md-up"></div>
  124. <div class="col-12 col-sm-6 col-md-3">
  125. <div class="info-box mb-3">
  126. <span class="info-box-icon bg-success elevation-1"><i class="fas fa-thumbs-up"></i></span>
  127. <div class="info-box-content">
  128. <span class="info-box-text">Наибольшее число новостей</span>
  129. <span class="info-box-number"><?=$max?></span>
  130. </div>
  131. </div>
  132. </div>
  133. <div class="col-12 col-sm-6 col-md-3">
  134. <div class="info-box mb-3">
  135. <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-thumbs-down"></i></span>
  136. <div class="info-box-content">
  137. <span class="info-box-text">Минимум новостей</span>
  138. <span class="info-box-number"><?=$min?></span>
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. <div class="row">
  144. <div class="col-md-12">
  145. <div class="card">
  146. <div class="card-header">
  147. <h5 class="card-title">Выпуск новостей по месяцу</h5>
  148. <div class="card-tools">
  149. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  150. <i class="fas fa-minus"></i>
  151. </button>
  152. <div class="btn-group">
  153. </div>
  154. <button type="button" class="btn btn-tool" data-card-widget="remove">
  155. <i class="fas fa-times"></i>
  156. </button>
  157. </div>
  158. </div>
  159. <div class="card-body">
  160. <div class="row">
  161. <div class="col-md-8">
  162. <p class="text-center">
  163. <strong>выпуски с <?=$b_date?> по <?=$e_date?></strong>
  164. </p>
  165. <div class="chart">
  166. <canvas id="salesChart" height="180" style="height: 180px;"></canvas>
  167. </div>
  168. </div>
  169. <div class="col-md-4">
  170. <p class="text-center">
  171. <strong>Дни</strong>
  172. </p>
  173. <div class="progress-group">
  174. Лучший день
  175. <span class="float-right"><b><?=$max?></b>/<?=$max?></span>
  176. <div class="progress progress-sm">
  177. <div class="progress-bar bg-primary" style="width: 100%"></div>
  178. </div>
  179. </div>
  180. <div class="progress-group">
  181. Худший день
  182. <span class="float-right"><b><?=$min?></b>/<?=$max?></span>
  183. <div class="progress progress-sm">
  184. <div class="progress-bar bg-danger" style="width: <?=$min*100/$max?>%"></div>
  185. </div>
  186. </div>
  187. <div class="progress-group">
  188. <span class="progress-text">среднее число новостей</span>
  189. <span class="float-right"><b><?=round($sum/count($cmd))?></b>/<?=$max?></span>
  190. <div class="progress progress-sm">
  191. <div class="progress-bar bg-success" style="width: <?=round($sum/count($cmd)*100/$max)?>%"></div>
  192. </div>
  193. </div>
  194. <div class="progress-group">
  195. Медианное значение
  196. <span class="float-right"><b><?=$mid?></b>/<?=$max?></span>
  197. <div class="progress progress-sm">
  198. <div class="progress-bar bg-warning" style="width: <?=round($mid*100/$max)?>%"></div>
  199. </div>
  200. </div>
  201. </div>
  202. </div>
  203. <div class="card-footer">
  204. <div class="row">
  205. <div class="col-sm-3 col-6">
  206. <div class="description-block border-right">
  207. <span class="description-percentage <?=$cntnews-$cntnewsp>0?'text-success':'text-danger'?>" title="От предыдущего месяца <?=$cntnewsp?>"><i class="fas <?=$cntnews-$cntnewsp>0?'fa-caret-up':'fa-caret-down'?>"></i><?=round(($cntnews-$cntnewsp)*100/$cntnewsp, 1)?>%</span>
  208. <h5 class="description-header"><?=$cntnews?></h5>
  209. <span class="description-text">Всего новостей за месяц</span>
  210. </div>
  211. </div>
  212. <div class="col-sm-3 col-6">
  213. <div class="description-block border-right">
  214. <span class="description-percentage <?=$cntnewsy-$cntnewsyy>0?'text-success':'text-danger'?>" title="До конца года <?=$cntnewsyy?>"><i class="fas <?=$cntnewsy-$cntnewsyy>0?'fa-caret-up':'fa-caret-down'?>"></i><?=round(($cntnewsy-$cntnewsyy)*100/$cntnewsyy, 1)?>%</span>
  215. <h5 class="description-header"><?=$cntnewsy?></h5>
  216. <span class="description-text">Новостей сначала года</span>
  217. </div>
  218. </div>
  219. <div class="col-sm-3 col-6">
  220. <div class="description-block border-right">
  221. <span class="description-percentage text-success"><i class="fas fa-caret-up"></i> 0%</span>
  222. <h5 class="description-header"><?=$cntnewsyy?></h5>
  223. <span class="description-text">За 365 дней</span>
  224. </div>
  225. </div>
  226. <div class="col-sm-3 col-6">
  227. <div class="description-block">
  228. <span class="description-percentage text-danger" title="От прошлого года"><i class="fas <?=($newsinterpolite+$cntnewsy)-$cntnewsyy>0?'text-success':'text-danger'?>"></i><i class="fas <?=($newsinterpolite+$cntnewsy)-$cntnewsyy>0?'fa-caret-up':'fa-caret-down'?>"></i><?=round((($newsinterpolite+$cntnewsy)-$cntnewsyy)*100/$cntnewsyy, 1)?>%</span>
  229. <h5 class="description-header"><?=$newsinterpolite+$cntnewsy?></h5>
  230. <span class="description-text">Будет новостей за этот год</span>
  231. </div>
  232. </div>
  233. </div>
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. <div class="row">
  240. <div class="col-md-8">
  241. <div class="row">
  242. <div class="col-md-6">
  243. <div class="card">
  244. <div class="card-header">
  245. <h3 class="card-title">Активность авторов<a href="/manager/stats/authors"></h3><div class="card-tools"><span class="badge badge-primary">Статистика по месяцам</span></a></div>
  246. </div>
  247. <div class="card-body">
  248. <table class="table table-bordered">
  249. <thead>
  250. <tr>
  251. <th style="width: 10px">#</th>
  252. <th>Автор</th>
  253. <th>Progress</th>
  254. <th style="width: 40px">Label</th>
  255. <th style="width: 40px">количество</th>
  256. </tr>
  257. </thead>
  258. <tbody>
  259. <?
  260. $i = 0;
  261. foreach( $authors as $author ){
  262. $i++;
  263. $aname = $author['e'];
  264. $aname = isset($old_author_name[$aname])?$old_author_name[$aname]:$aname;
  265. ?>
  266. <tr>
  267. <td><?=$i?></td>
  268. <td><?=$aname?></td>
  269. <td>
  270. <div class="progress progress-xs">
  271. <div class="progress-bar progress-bar-danger" style="width: <?=round( $author['c']*100/$sum,1)?>%"></div>
  272. </div>
  273. </td>
  274. <td><span class="badge bg-danger"><?=round( $author['c']*100/$sum,1)?>%</span></td>
  275. <td><span class="badge bg-warning"><?=$author['c']?></span></td>
  276. </tr>
  277. <?}?>
  278. </tbody>
  279. </table>
  280. </div>
  281. <div class="card-footer clearfix">
  282. * переопубликованые материалы
  283. </div>
  284. </div>
  285. </div>
  286. <div class="col-md-6">
  287. <div class="card">
  288. <div class="card-header">
  289. <h3 class="card-title">Активность рубрик</h3>
  290. </div>
  291. <div class="card-body">
  292. <table class="table table-bordered">
  293. <thead>
  294. <tr>
  295. <th style="width: 10px">#</th>
  296. <th>Рубрика</th>
  297. <th>Progress</th>
  298. <th style="width: 40px">Label</th>
  299. <th style="width: 40px">количество</th>
  300. </tr>
  301. </thead>
  302. <tbody>
  303. <?
  304. $i = 0;
  305. $srub = '';
  306. $srubc = '';
  307. $bgc = '';
  308. foreach( $rubric as $item ){
  309. $i++;
  310. $srub .= "'".$item['t']."'".',';
  311. $srubc .= $item['c'].',';
  312. $bgc .= "'#".dechex(rand(10,255)).dechex(rand(10,255)).dechex(rand(1,255))."',";
  313. ?>
  314. <tr>
  315. <td><?=$i?></td>
  316. <td><?=$item['t']?></td>
  317. <td>
  318. <div class="progress progress-xs">
  319. <div class="progress-bar progress-bar-danger" style="width: <?=round( $item['c']*100/$sum,1)?>%"></div>
  320. </div>
  321. </td>
  322. <td><span class="badge bg-danger"><?=round( $item['c']*100/$sum,1)?>%</span></td>
  323. <td><span class="badge bg-warning"><?=$item['c']?></span></td>
  324. </tr>
  325. <?}?>
  326. </tbody>
  327. </table>
  328. </div>
  329. <div class="card-footer clearfix">
  330. </div>
  331. </div>
  332. </div>
  333. </div>
  334. </div>
  335. <div class="col-md-4">
  336. <div class="card">
  337. <div class="card-header">
  338. <h3 class="card-title">Рубрики</h3>
  339. <div class="card-tools">
  340. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  341. <i class="fas fa-minus"></i>
  342. </button>
  343. <button type="button" class="btn btn-tool" data-card-widget="remove">
  344. <i class="fas fa-times"></i>
  345. </button>
  346. </div>
  347. </div>
  348. <div class="card-body">
  349. <canvas id="pieChart"></canvas>
  350. </div>
  351. </div>
  352. <div class="card">
  353. <div class="card-header">
  354. <h3 class="card-title">Реакция посетителей на статьи</h3>
  355. <div class="card-tools">
  356. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  357. <i class="fas fa-minus"></i>
  358. </button>
  359. <button type="button" class="btn btn-tool" data-card-widget="remove">
  360. <i class="fas fa-times"></i>
  361. </button>
  362. </div>
  363. </div>
  364. <div class="card-body p-0">
  365. <ul class="products-list product-list-in-card pl-2 pr-2">
  366. <?
  367. $i = 1;
  368. $c = ['bg-danger','bg-warning', 'bg-primary', 'bg-success'];
  369. foreach( $cnt as $item ){
  370. $cc = $c[round($item*100/$sumrb/25)];
  371. ?>
  372. <li class="item">
  373. <div class="product-img">
  374. <img src="/img/reactionbutton/<?=$i?>.svg" alt="Product Image" class="img-size-50">
  375. </div>
  376. <div class="product-info mt-3">
  377. <h3><span class="badge <?=$cc?> float-right"><?=$item?></span></h3>
  378. <div class="progress progress-sm mr-5">
  379. <div class="progress-bar <?=$cc?>" style="width: <?=round($item*100/$sumrb)?>%"></div>
  380. </div>
  381. </div>
  382. </li>
  383. <?
  384. $i++;
  385. }
  386. ?>
  387. </ul>
  388. </div>
  389. <div class="card-footer text-center">
  390. реакции
  391. </div>
  392. </div>
  393. <div class="small-box bg-succes">
  394. <div class="inner">
  395. <h3><?=$cnt_comment+$cnt_commenth?></h3>
  396. <p>Всего комментариев</p>
  397. </div>
  398. <div class="icon">
  399. <i class="fas fa-chart-pie"></i>
  400. </div>
  401. <a href="/manager/comments/index" class="small-box-footer">
  402. More info <i class="fas fa-arrow-circle-right"></i>
  403. </a>
  404. </div>
  405. <div class="small-box bg-succes">
  406. <div class="inner">
  407. <h3><?=$cnt_comment?></h3>
  408. <p>Опубликованных комментариев</p>
  409. </div>
  410. <div class="icon">
  411. <i class="fas fa-chart-pie"></i>
  412. </div>
  413. <a href="/manager/comments/index" class="small-box-footer">
  414. More info <i class="fas fa-arrow-circle-right"></i>
  415. </a>
  416. </div>
  417. <div class="small-box bg-danger">
  418. <div class="inner">
  419. <h3><?=$cnt_commenth?></h3>
  420. <p>Заблоченных комментариев</p>
  421. </div>
  422. <div class="icon">
  423. <i class="fas fa-chart-pie"></i>
  424. </div>
  425. <a href="/manager/comments/index" class="small-box-footer">
  426. More info <i class="fas fa-arrow-circle-right"></i>
  427. </a>
  428. </div>
  429. </div>
  430. </div>
  431. </div>
  432. </section>
  433. </div>
  434. <aside class="control-sidebar control-sidebar-dark">
  435. </aside>
  436. <?
  437. //#f56954
  438. ?>
  439. <script>
  440. $(function(){
  441. //var salesChartCanvas=$('#salesChart').get(0).getContext('2d')
  442. var salesChartCanvas = document.getElementById('salesChart');
  443. 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?>]}]}
  444. var salesChartOptions={maintainAspectRatio:false,responsive:true,legend:{display:false},scales:{xAxes:[{gridLines:{display:true}}],yAxes:[{gridLines:{display:false}}]}}
  445. var salesChart=new Chart(salesChartCanvas,{type:'line',data:salesChartData,options:salesChartOptions})
  446. var donutData = {
  447. labels: [<?=$srub?>],
  448. datasets: [
  449. {
  450. data: [<?=$srubc?>],
  451. backgroundColor : [<?=$bgc?>],
  452. }
  453. ]
  454. }
  455. var pieChartCanvas = $('#pieChart').get(0).getContext('2d')
  456. var pieData = donutData;
  457. var pieOptions = {
  458. maintainAspectRatio : true,
  459. responsive : true,
  460. legend: false,
  461. }
  462. new Chart(pieChartCanvas, {
  463. type: 'doughnut',
  464. data: pieData,
  465. options: pieOptions
  466. })
  467. });
  468. <?=$this->render('chartjs');?>
  469. $('body').addClass('dark-mode');
  470. </script>
  471. <?
  472. $this->endCache();
  473. }