3.20, // $3.20 per 8-second video 'TEXT2IMAGE' => 0.04, // Average cost per image generation 'TEXT2VOICE' => 0.30, // Cost per TTS conversion 'SPEECH2SPEECH' => 0.50, // Cost per speech-to-speech conversion 'DOCUMENT_TRANSLATION' => 0.10, // Cost per document translation 'VIDEOQUERY' => 0.25, // Cost per video analysis query ]; // Tool display names $toolNames = [ 'VEO3' => 'VEO3 Video Generation', 'TEXT2IMAGE' => 'Text to Image', 'TEXT2VOICE' => 'Text to Voice', 'SPEECH2SPEECH' => 'Speech to Speech', 'DOCUMENT_TRANSLATION' => 'Document Translation', 'VIDEOQUERY' => 'Video Query Analysis', ]; // SSO Authentication require_once __DIR__ . '/AuthMiddleware.php'; $auth = new AuthMiddleware(); $user = $auth->requireAuth(); // This will redirect to login if not authenticated // Load and parse JSON if (!file_exists($responseFile)) { die("Error: Response file not found. Please run webhook_caller.php first."); } $jsonContent = file_get_contents($responseFile); $data = json_decode($jsonContent, true); if (!$data) { die("Error: Unable to parse JSON data."); } // Initialize arrays for analysis $userCounts = []; $dailyCounts = []; $monthlyCounts = []; $promptLengths = []; $toolCounts = []; $toolUserCounts = []; $totalRequests = count($data); $totalCost = 0; // Period-specific analysis $now = new DateTime('now', new DateTimeZone('UTC')); $last24Hours = clone $now; $last24Hours->sub(new DateInterval('P1D')); $last7Days = clone $now; $last7Days->sub(new DateInterval('P7D')); $last30Days = clone $now; $last30Days->sub(new DateInterval('P30D')); $userCounts24h = []; $userCounts7d = []; $userCounts30d = []; $totalPrompts24h = 0; $totalPrompts7d = 0; $totalPrompts30d = 0; // Process each record foreach ($data as $record) { $item = $record['data']; // User counts $user = $item['USER']; $tool = $item['TOOL'] ?? 'UNKNOWN'; if (!isset($userCounts[$user])) { $userCounts[$user] = 0; } $userCounts[$user]++; // Tool counts if (!isset($toolCounts[$tool])) { $toolCounts[$tool] = 0; } $toolCounts[$tool]++; // Tool user counts if (!isset($toolUserCounts[$tool])) { $toolUserCounts[$tool] = []; } if (!isset($toolUserCounts[$tool][$user])) { $toolUserCounts[$tool][$user] = 0; } $toolUserCounts[$tool][$user]++; // Calculate cost - use default of 0 for unknown tools $costPerRequest = $toolCosts[$tool] ?? 0; $totalCost += $costPerRequest; // Date parsing $date = $item['Date']; $dateObj = new DateTime($date); $dateStr = $dateObj->format('Y-m-d'); $monthStr = $dateObj->format('Y-m'); // Period filtering if ($dateObj >= $last24Hours) { if (!isset($userCounts24h[$user])) $userCounts24h[$user] = 0; $userCounts24h[$user]++; $totalPrompts24h++; } if ($dateObj >= $last7Days) { if (!isset($userCounts7d[$user])) $userCounts7d[$user] = 0; $userCounts7d[$user]++; $totalPrompts7d++; } if ($dateObj >= $last30Days) { if (!isset($userCounts30d[$user])) $userCounts30d[$user] = 0; $userCounts30d[$user]++; $totalPrompts30d++; } // Daily counts if (!isset($dailyCounts[$dateStr])) { $dailyCounts[$dateStr] = 0; } $dailyCounts[$dateStr]++; // Monthly counts if (!isset($monthlyCounts[$monthStr])) { $monthlyCounts[$monthStr] = 0; } $monthlyCounts[$monthStr]++; // Prompt length analysis (if prompt exists) if (isset($item['PROMPT']) && $item['PROMPT']) { $promptLength = strlen($item['PROMPT']); $promptLengths[] = $promptLength; } } // Sort tool counts by usage arsort($toolCounts); // Sort period-specific user counts arsort($userCounts24h); arsort($userCounts7d); arsort($userCounts30d); // Get top 25 for each period $topUsers24h = array_slice($userCounts24h, 0, 25, true); $topUsers7d = array_slice($userCounts7d, 0, 25, true); $topUsers30d = array_slice($userCounts30d, 0, 25, true); // Note: totalCost is already calculated in the loop above // Calculate period-specific costs (we'll need to recalculate by tool for accuracy) $cost24h = 0; $cost7d = 0; $cost30d = 0; // Recalculate period costs foreach ($data as $record) { $item = $record['data']; $tool = $item['TOOL'] ?? 'UNKNOWN'; $costPerRequest = $toolCosts[$tool] ?? 0; $dateObj = new DateTime($item['Date']); if ($dateObj >= $last24Hours) $cost24h += $costPerRequest; if ($dateObj >= $last7Days) $cost7d += $costPerRequest; if ($dateObj >= $last30Days) $cost30d += $costPerRequest; } // Sort data arsort($userCounts); ksort($dailyCounts); ksort($monthlyCounts); // Calculate statistics $uniqueUsers = count($userCounts); $avgRequestsPerUser = round($totalRequests / $uniqueUsers, 2); $avgPromptLength = count($promptLengths) > 0 ? round(array_sum($promptLengths) / count($promptLengths), 0) : 0; $maxPromptLength = count($promptLengths) > 0 ? max($promptLengths) : 0; $minPromptLength = count($promptLengths) > 0 ? min($promptLengths) : 0; // Get date range $dates = array_keys($dailyCounts); $startDate = reset($dates); $endDate = end($dates); // Get top 20 users $topUsers = array_slice($userCounts, 0, 20, true); // Get recent daily activity (last 30 days) $recentDaily = array_slice($dailyCounts, -30, 30, true); ?>
Data from to
Usage distribution across all AI tools
| Tool | Requests | Percentage | Top User |
|---|---|---|---|
| % | () - |
| Date | Day of Week | Requests | Activity Level |
|---|---|---|---|
| Month | Requests | Distribution |
|---|---|---|
| (%) |
requests from users Cost: $
| Rank | User | Requests | Percentage | Activity |
|---|---|---|---|---|
| # | % |
No activity in the last 24 hours
requests from users Cost: $
| Rank | User | Requests | Percentage | Activity |
|---|---|---|---|---|
| # | % |
No activity in the last 7 days
requests from users Cost: $
| Rank | User | Requests | Percentage | Activity |
|---|---|---|---|---|
| # | % |
No activity in the last 30 days
| Rank | User | Prompts | Percentage | Activity |
|---|---|---|---|---|
| # | % |
| User | Total Requests | Percentage of Total |
|---|---|---|
| % |