123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- <?php
- /** @var yii\web\View $this */
- use yii\helpers\Html;
- use yii\widgets\DetailView;
- $cache = Yii::$app->cache;
- $month = array(
- 1 => 'Январь',
- 2 => 'Февраль',
- 3 => 'Март',
- 4 => 'Апрель',
- 5 => 'Май',
- 6 => 'Июнь',
- 7 => 'Июль',
- 8 => 'Август',
- 9 => 'Сентябрь',
- 10 => 'Октябрь',
- 11 => 'Ноябрь',
- 12 => 'Декабрь'
- );
- $week = 1;
- if (Yii::$app->request->isGet){
- $week = Yii::$app->request->get('week');
- $week = $week?$week:'1';
- }
- $start = strtotime( date("Y-m-d", strtotime( date("Y-m-d")." $week weeks ago")) );
- $mstart = date("Y-m-d", strtotime(" monday this week", $start ));
- $mend = date("Y-m-d", strtotime( " sunday this week", $start ));
- $this->title = "Контентная аналитика ".$mstart;
- $this->params['breadcrumbs'][] = ['label' => $this->title, 'url' => ['index']];
- $cache = Yii::$app->cache;
- $ckey = "w page:".md5("$mstart $mend");
- if( $res = $cache->get($ckey) ){
- $r = unserialize($res);
- }else{
- $r = $model->YGetByTime(['date1'=>$mstart, 'date2'=>$mend,'dimensions'=>'ym:s:publisherArticle','metrics'=>'ym:s:publisherviews','filters'=>'(ym:s:publisherArticle!n)','sort'=>'-ym:s:publisherviews','limit'=>20, 'top_keys'=>20]);
- if( $r ){
- $cache->set($ckey, serialize( $r ));
- }
- }
- $ckey = "w rubric:".md5("$mstart $mend");
- if( $res = $cache->get($ckey) ){
- $r1 = unserialize($res);
- }else{
- $r1 = $model->YGetByTime(['date1'=>$mstart, 'date2'=>$mend,'dimensions'=>'ym:s:publisherArticleRubric, ym:s:publisherArticleRubric2','metrics'=>'ym:s:publisherviews','filters'=>'(ym:s:publisherArticle!n)','sort'=>'-ym:s:publisherviews','limit'=>20, 'top_keys'=>20]);
- if( $r ){
- $cache->set($ckey, serialize( $r1 ));
- }
- }
- $ckey = "w topic:".md5("$mstart $mend");
- if( $res = $cache->get($ckey) ){
- $r2 = unserialize($res);
- }else{
- $r2 = $model->YGetByTime(['date1'=>$mstart, 'date2'=>$mend,'dimensions'=>'ym:s:publisherArticleTopic','metrics'=>'ym:s:publisherviews','filters'=>'(ym:s:publisherArticle!n)','sort'=>'-ym:s:publisherviews','limit'=>20, 'top_keys'=>20]);
- if( $r ){
- $cache->set($ckey, serialize( $r2 ));
- }
- }
- $ckey = "w tn:".md5("$mstart $mend");
- if( $res = $cache->get($ckey) ){
- $tncount = unserialize($res);
- }else{
- $rubricInNews = Yii::$app->db->createCommand("select t.topic_id tid, tn.title, count(news_id) c FROM `news` n, `news_topic_relation` t, `news_topic` tn WHERE `dt_pub` BETWEEN '".$mstart."' AND '".$mend."' and n.active = 'Y' and tn.active = 1 and n.id=news_id and tn.id=t.topic_id group by t.topic_id order by c desc")->queryAll();
- $tncount = [];
- foreach($rubricInNews as $item){
- $tncount[$item['title']] = $item['c'];
- }
- $cache->set($ckey, serialize( $tncount ));
- }
- $ckey = "w tagsn:".md5("$mstart $mend");
- if( $res = $cache->get($ckey) ){
- $tagncount = unserialize($res);
- }else{
- // echo "select t.topic_id tid, tn.title, count(news_id) c FROM `news` n, `tags_relation` t, `tags` tn WHERE `dt_pub` BETWEEN '".$mstart."' AND '".$mend."' and n.active = 'Y' and tn.active = 1 and n.id=news_id and tn.id=t.topic_id group by t.topic_id order by c desc";
- $rubricInNews = Yii::$app->db->createCommand("select t.topic_id tid, tn.title, count(news_id) c FROM `news` n, `tags_relation` t, `tags` tn WHERE `dt_pub` BETWEEN '".$mstart."' AND '".$mend."' and n.active = 'Y' and tn.active = 1 and n.id=news_id and tn.id=t.topic_id group by t.topic_id order by c desc")->queryAll();
- $tagncount = [];
- foreach($rubricInNews as $item){
- $tagncount[$item['title']] = $item['c'];
- }
- $cache->set($ckey, serialize( $tagncount ));
- }
- //print_a($tagncount);
- //print_a($r2);
- ?>
- <section class="content">
- <div class="container-fluid">
- <div class="row">
- <div class="col-12">
- <div class="alert bg-lightblue disabled color-palette alert-dismissible">
- <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
- <h5><i class="icon fas fa-info"></i> Alert!</h5>
- <h2>Прошлая неделя: <span class="text-white"><b><?=$mstart?> - <?=$mend?></b></span></h2>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-12">
- <div class="callout callout-info">
- <h5><i class="fas fa-info"></i> amic.ru:</h5>
- Данные <b>amic.ru</b> по данным яндекс метрика
- </div>
- <nav aria-label="Page navigation example">
- <ul class="pagination">
- <li class="page-item <?=($week == 3)?'active':''?>"><a class="page-link" href="?week=3">3 недели назад</a></li>
- <li class="page-item <?=($week == 2)?'active':''?>"><a class="page-link" href="?week=2">2 недели назад</a></li>
- <li class="page-item <?=($week == 1)?'active':''?>"><a class="page-link" href="?week=1">1 неделя назад</a></li>
- </ul>
- </nav>
- <div class="card card-primary card-outline">
- <div class="card-header border-0">
- <h3 class="card-title">ТОП Новостей за неделю</h3>
- </div>
- <div class="card-body table-responsive p-0">
- <table class="table table-striped table-valign-middle" id="reftab">
- <thead>
- <tr>
- <th>Статья</th>
- <th class="sorting">Посетителей</th>
- <th class="sorting">Рубрика 1</th>
- <th>Рубрика 2</th>
- <th>Тэги</th>
- </tr>
- </thead>
- <tbody id="referertab">
- <?
- foreach($r->data as $item){
- if( $item->dimensions[0]->url == 'http://amic.ru/' ) continue;
- ?>
- <tr>
- <?
- echo "<td><a href='{$item->dimensions[0]->url}' target='_blank'>".$item->dimensions[0]->title."</a></td>";
- echo "<td>".$item->metrics[0][0]."</td>";
- echo "<td>".$item->dimensions[0]->rubric."</td>";
- echo "<td>".$item->dimensions[0]->rubric2."</td>";
- echo "<td>".$item->dimensions[0]->topics."</td>";
- ?>
- </tr>
- <?
- }
- ?>
- </tbody>
- </table>
- </div>
- </div>
- </div></div>
- <div class="row">
- <div class="col-6">
- <div class="card card-primary card-outline">
- <div class="card-header border-0">
- <h3 class="card-title">ТОП Рубрик за неделю</h3>
- </div>
- <div class="card-body table-responsive p-0">
- <table class="table table-striped table-valign-middle" id="reftab">
- <thead>
- <tr>
- <th>Рубрика</th>
- <th class="sorting">Посетителей</th>
- <th class="sorting">публикаций в рубрике</th>
- </tr>
- </thead>
- <tbody id="referertab">
- <?
- foreach($r1->data as $item){
- ?>
- <tr>
- <?
- $s = isset($tncount[$item->dimensions[0]->name])?'':'<span class="float-right badge bg-success">раздел/сюжет</span>';
- echo "<td>".$item->dimensions[0]->name." $s</td>";
- echo "<td>".$item->metrics[0][0]."</td>";
- if( isset($tncount[$item->dimensions[0]->name]) ){
- echo "<td>".$tncount[$item->dimensions[0]->name]."</td>";
- }else{
- echo "<td></td>";
- }
- ?>
- </tr>
- <?
- }
- ?>
- </tbody>
- </table>
- </div>
- </div>
- <div class="card card-success card-outline">
- <div class="card-header border-0">
- <h3 class="card-title">ТОП Тэгов за неделю</h3>
- </div>
- <div class="card-body table-responsive p-0">
- <table class="table table-striped table-valign-middle" id="reftab">
- <thead>
- <tr>
- <th>Тэги</th>
- <th class="sorting">Посетителей</th>
- <th class="sorting">Новостей с тэгом</th>
- <th class="sorting">относительно публикаций</th>
- </tr>
- </thead>
- <tbody id="referertab">
- <?
- // $sum = array_sum($tagncount);
- $tnp1 = [];
- foreach($r2->data as $item){
- ?>
- <tr>
- <?
- echo "<td>".$item->dimensions[0]->name."</td>";
- echo "<td>".$item->metrics[0][0]."</td>";
- if( isset($tagncount[$item->dimensions[0]->name]) ){
- echo "<td>".$tagncount[$item->dimensions[0]->name]."</td>";
- $perc = round($item->metrics[0][0]/$tagncount[$item->dimensions[0]->name]);
- echo "<td>".round($perc,1)."</td>";
- $tnp1[$item->dimensions[0]->name] = $perc;
- }else{
- echo "<td></td>";
- echo "<td></td>";
- }
- ?>
- </tr>
- <?
- }
- ?>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- <div class="col-6">
- <div class="card card-primary card-outline">
- <div class="card-header border-0">
- <h3 class="card-title">ТОП Рубрик за неделю относительно количества публикаций</h3>
- </div>
- <div class="card-body table-responsive p-0">
- <table class="table table-striped table-valign-middle" id="reftab">
- <thead>
- <tr>
- <th>Рубрика</th>
- <th class="sorting">Посетителей на публикацию</th>
- </tr>
- </thead>
- <tbody id="referertab">
- <?
- $tnp = [];
- foreach($r1->data as $item){
- if( isset($tncount[$item->dimensions[0]->name]) ){
- $perc = round($item->metrics[0][0]/$tncount[$item->dimensions[0]->name],1)."";
- $tnp[$item->dimensions[0]->name] = $perc;
- }
- }
- $sum = array_sum($tnp);
- arsort($tnp);
- foreach($tnp as $key=>$item){
- ?>
- <tr>
- <?
- echo "<td>".$key."</td>";
- echo "<td>".$item."</td>";
- ?>
- </tr>
- <?
- }
- ?>
- </tbody>
- </table>
- </div>
- </div>
- <div class="card card-primary card-outline">
- <div class="card-header">
- <h3 class="card-title">Эффективность статей по рубрикам</h3>
- </div>
- <div class="card-body">
- <canvas id="pieChart"></canvas>
- </div>
- </div>
- <div class="card card-success card-outline">
- <div class="card-header">
- <h3 class="card-title">Эффективность статей по тэгам</h3>
- </div>
- <div class="card-body">
- <canvas id="pieChart1"></canvas>
- </div>
- </div>
- </div></div>
- <div class="row">
- <div class="col-6">
- </div>
- <div class="col-6">
- </div>
- </div>
- </section>
- <?
- $srub = "";
- $srubc = '';
- $bgc = "";
- $bga = ['#5225f0','#ae55d9','#4c37b6','#7bf793','#6cbbef','#cba4f9','#15b395','#3dc055','#9cce37','#d2fb46','#ce2319','#1eb696','#cacd9a','#231e6a','#a23c80'];
- foreach($tnp as $key=>$item){
- $srubc .= round($item*100/$sum,1).',';
- $srub .= '"'.$key.' '. round($item*100/$sum,1).'%",';
- $r = array_pop($bga);
- if( $r ){
- $bgc .= "'".$r."',";
- }else{
- $bgc .= "'#".dechex(rand(10,255)).dechex(rand(10,255)).dechex(rand(1,255))."',";
- }
- }
- ?>
- <?
- $sum1 = array_sum($tnp1);
- arsort($tnp1);
- $srub1 = "";
- $srubc1 = '';
- $bgc1 = "";
- $bga1 = ['#5225f0','#ae55d9','#4c37b6','#7bf793','#6cbbef','#cba4f9','#15b395','#3dc055','#9cce37','#d2fb46','#ce2319','#1eb696','#cacd9a','#231e6a','#a23c80'];
- foreach($tnp1 as $key=>$item){
- $srubc1 .= round($item*100/$sum1,1).',';
- $srub1 .= '"'.$key.' '. round($item*100/$sum1,1).'%",';
- $r = array_pop($bga1);
- if( $r ){
- $bgc1 .= "'".$r."',";
- }else{
- $bgc1 .= "'#".dechex(rand(10,255)).dechex(rand(10,255)).dechex(rand(1,255))."',";
- }
- }
- ?>
- <script>
- <?=$this->render('/stats/chartjs');?>
- 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: {
- display: true,
- },
- cutoutPercentage: 20,
- }
- new Chart(pieChartCanvas, {
- type: 'doughnut',
- data: pieData,
- options: pieOptions
- })
- var donutData1 = {
- labels: [<?=$srub1?>],
- datasets: [
- {
- data: [<?=$srubc1?>],
- backgroundColor : [<?=$bgc1?>],
- }
- ]
- }
- var pieChartCanvas = $('#pieChart1').get(0).getContext('2d')
- var pieData = donutData1;
- var pieOptions = {
- maintainAspectRatio : true,
- responsive : true,
- legend: {
- display: true,
- },
- cutoutPercentage: 20,
- }
- new Chart(pieChartCanvas, {
- type: 'doughnut',
- data: pieData,
- options: pieOptions
- })
- $('table').DataTable({paging: false, info: false,searching: false,
- columnDefs: [{
- orderable: false,
- targets: 0
- }],
- "responsive": true, "lengthChange": false, "autoWidth": false,
- order: [[1, 'desc']]
- });
- // $('.dataTables_length').addClass('bs-select');
- </script>
|