/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
backend/widgets/server/StatsWidget.php
132 строки
3 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace backend\widgets\server; use common\helpers\ArrayHelper; use common\kdf\KMetric; use common\kdf\KPeriod; use common\models\stat\Metric; /** * Список проектов * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2020 */ class StatsWidget extends BaseServerWidget { /** * @inheritdoc */ public $icon = 'icon-stack'; /** * @inheritdoc */ public $title = 'Statistics'; /** * @inheritdoc */ public $sub_title = 'Aggregating data from AI usage logs.'; /** * @inheritdoc */ protected function getCols() { return [ [ 'title' => 'Metric', 'slug' => 'metric', 'width' => '20' ], [ 'title' => 'Today', 'slug' => 'today', 'is_center' => true, 'width' => '20' ], [ 'title' => 'Week', 'slug' => 'week', 'is_center' => true, 'width' => '20' ], [ 'title' => 'Month', 'slug' => 'month', 'is_center' => true, 'width' => '20' ], [ 'title' => 'Year', 'slug' => 'year', 'is_center' => true, 'width' => '20' ], // [ // 'title' => 'Logic', // 'slug' => 'logic', // 'width' => '5' // ], ]; } /** * @inheritdoc */ protected function getRows() { $data = Metric::find() ->select([ 'metric_id', 'period_id', 'value' ]) ->asArray() ->all(); $result = []; foreach ($data as $row) { $result[$row['metric_id']][$row['period_id']] = $row['value']; } $metric = KMetric::find() ->select([ 'id', 'title' ]) ->asArray() ->all(); $period = KPeriod::find() ->select([ 'id', 'title', 'slug' ]) ->asArray() ->all(); $rows = []; foreach ($metric as $row) { $cell = []; foreach ($period as $col) { $value = ArrayHelper::getValue($result, $row['id'] . '.' . $col['id'], 0); $value = number_format($value, 0, '.', ' '); $cell[$col['slug']] = [ 'value' => $value ]; } $rows[] = ArrayHelper::merge($cell, [ 'metric' => ['value' => $row['title']], ]); } return $rows; } }