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'];
?>
CPU нагрузка
$str="LANGUAGE=en_US.UTF-8 sar 1 2 | grep \"Average\" | sed 's/^.* //'";
$out = [];
exec($str, $out);
echo 100-$out[0]*1;
?>
%