|
@@ -3,24 +3,25 @@
|
|
|
namespace App\Http\Controllers\Admin;
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Controller;
|
|
|
-use App\Models\GameEnterLog;
|
|
|
|
|
|
|
+use App\Models\GameEnterDailyStat;
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class GameEnterLogController extends Controller
|
|
class GameEnterLogController extends Controller
|
|
|
{
|
|
{
|
|
|
/**
|
|
/**
|
|
|
- * Average game enter duration statistics per game.
|
|
|
|
|
|
|
+ * Daily per-game enter duration statistics (from aggregate table).
|
|
|
*/
|
|
*/
|
|
|
public function statistics(Request $request)
|
|
public function statistics(Request $request)
|
|
|
{
|
|
{
|
|
|
- $startDate = $request->input('start_date', date('Y-m-d', strtotime('-7 days')));
|
|
|
|
|
- $endDate = $request->input('end_date', date('Y-m-d'));
|
|
|
|
|
|
|
+ $today = date('Y-m-d');
|
|
|
|
|
+ $startDate = $request->input('start_date', $today);
|
|
|
|
|
+ $endDate = $request->input('end_date', $today);
|
|
|
|
|
|
|
|
- $rows = DB::table(GameEnterLog::TABLE)
|
|
|
|
|
|
|
+ $rows = DB::connection('read')->table(GameEnterDailyStat::TABLE)
|
|
|
->whereBetween('log_date', [$startDate, $endDate])
|
|
->whereBetween('log_date', [$startDate, $endDate])
|
|
|
- ->selectRaw('game_id, COUNT(*) as enter_count, AVG(CAST(duration_ms AS FLOAT)) as avg_duration_ms')
|
|
|
|
|
- ->groupBy('game_id')
|
|
|
|
|
|
|
+ ->select('log_date', 'game_id', 'enter_count', 'total_duration_ms')
|
|
|
|
|
+ ->orderByDesc('log_date')
|
|
|
->orderByDesc('enter_count')
|
|
->orderByDesc('enter_count')
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
@@ -40,17 +41,21 @@ class GameEnterLogController extends Controller
|
|
|
$statistics = [];
|
|
$statistics = [];
|
|
|
foreach ($rows as $row) {
|
|
foreach ($rows as $row) {
|
|
|
$gameId = (int) $row->game_id;
|
|
$gameId = (int) $row->game_id;
|
|
|
- $avgMs = (float) $row->avg_duration_ms;
|
|
|
|
|
- $gameName = __('auto.未知游�');
|
|
|
|
|
|
|
+ $enterCount = (int) $row->enter_count;
|
|
|
|
|
+ $totalMs = (int) $row->total_duration_ms;
|
|
|
|
|
+ $avgMs = $enterCount > 0 ? $totalMs / $enterCount : 0;
|
|
|
|
|
+
|
|
|
|
|
+ $gameName = __('auto.δ֪ÓÎÏ·');
|
|
|
if (isset($games[$gameId])) {
|
|
if (isset($games[$gameId])) {
|
|
|
$game = $games[$gameId];
|
|
$game = $games[$gameId];
|
|
|
$gameName = $game->brand . ' - ' . $game->title;
|
|
$gameName = $game->brand . ' - ' . $game->title;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$statistics[] = [
|
|
$statistics[] = [
|
|
|
|
|
+ 'log_date' => $row->log_date,
|
|
|
'game_id' => $gameId,
|
|
'game_id' => $gameId,
|
|
|
'game_name' => $gameName,
|
|
'game_name' => $gameName,
|
|
|
- 'enter_count' => (int) $row->enter_count,
|
|
|
|
|
|
|
+ 'enter_count' => $enterCount,
|
|
|
'avg_duration_ms' => round($avgMs, 2),
|
|
'avg_duration_ms' => round($avgMs, 2),
|
|
|
'avg_duration_sec' => round($avgMs / 1000, 3),
|
|
'avg_duration_sec' => round($avgMs / 1000, 3),
|
|
|
];
|
|
];
|