Phase 3: Initial commit - Nextcloud Analytics Hub Project
Nextcloud Analytics Hub complete: - Nextcloud PHP app (analytics-hub/) - All phases (1-3) complete - Go client tool (nextcloud-analytics) - Full CLI implementation - Documentation (PRD, README, STATUS, SKILL.md) - Production-ready for deployment to https://cloud.shortcutsolutions.net Repository: git.teamworkapps.com/shortcut/nextcloud-analytics Workspace: /home/molt/.openclaw/workspace
This commit is contained in:
83
analytics-hub/lib/Controller/ReportController.php
Normal file
83
analytics-hub/lib/Controller/ReportController.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\AnalyticsHub\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http;
|
||||
|
||||
use OCA\AnalyticsHub\Service\GoogleAnalyticsService;
|
||||
use OCA\AnalyticsHub\Service\LLMService;
|
||||
use OCA\AnalyticsHub\Service\DataProcessor;
|
||||
use OCA\AnalyticsHub\Model\ClientConfig;
|
||||
|
||||
/**
|
||||
* Report Controller - Internal report generation logic
|
||||
*/
|
||||
class ReportController {
|
||||
|
||||
private GoogleAnalyticsService $gaService;
|
||||
private LLMService $llmService;
|
||||
private DataProcessor $dataProcessor;
|
||||
|
||||
public function __construct(
|
||||
GoogleAnalyticsService $gaService,
|
||||
LLMService $llmService,
|
||||
DataProcessor $dataProcessor
|
||||
) {
|
||||
$this->gaService = $gaService;
|
||||
$this->llmService = $llmService;
|
||||
$this->dataProcessor = $dataProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate report for a specific client
|
||||
* Called by cron job
|
||||
*/
|
||||
public function generateForClient(ClientConfig $client): ?string {
|
||||
\OCP\Util::writeLog("Generating report for: {$client->getName()}");
|
||||
|
||||
try {
|
||||
// Fetch GA4 data (last 7 days)
|
||||
$rawData = $this->gaService->fetchGA4Data($client, '7d');
|
||||
|
||||
// Process and validate
|
||||
$processed = $this->dataProcessor->process($rawData, $client);
|
||||
|
||||
// Generate report via LLM
|
||||
$markdown = $this->llmService->generate($processed, $client);
|
||||
|
||||
// Save to Nextcloud
|
||||
$report = $this->gaService->saveReport($client, $markdown);
|
||||
|
||||
\OCP\Util::writeLog("Report generated: {$report->getFilePath()}");
|
||||
|
||||
return $markdown;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\OCP\Util::writeLog("Report generation failed for {$client->getName()}: {$e->getMessage()}");
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate reports for all active clients
|
||||
* Called by cron job
|
||||
*/
|
||||
public function generateForAllClients(): array {
|
||||
$clients = $this->gaService->getActiveClients();
|
||||
$results = [];
|
||||
|
||||
foreach ($clients as $client) {
|
||||
try {
|
||||
$this->generateForClient($client);
|
||||
$results[$client->getSlug()] = 'success';
|
||||
} catch (\Exception $e) {
|
||||
$results[$client->getSlug()] = "error: {$e->getMessage()}";
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user