mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-11-19 23:00:36 +01:00
56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Command;
|
||
|
|
|
||
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||
|
|
use Symfony\Component\Console\Command\Command;
|
||
|
|
use Symfony\Component\Console\Input\InputInterface;
|
||
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
||
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||
|
|
use App\Service\BudgetService;
|
||
|
|
|
||
|
|
#[AsCommand(
|
||
|
|
name: 'app:test-budget',
|
||
|
|
description: 'Test du service BudgetService',
|
||
|
|
)]
|
||
|
|
class TestBudgetCommand extends Command
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private BudgetService $budgetService
|
||
|
|
) {
|
||
|
|
parent::__construct();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||
|
|
{
|
||
|
|
$io = new SymfonyStyle($input, $output);
|
||
|
|
|
||
|
|
// Test avec un code INSEE
|
||
|
|
$codeInsee = '37261'; // Tours
|
||
|
|
$io->info("Test du budget pour le code INSEE: $codeInsee");
|
||
|
|
|
||
|
|
try {
|
||
|
|
$budget = $this->budgetService->getBudgetAnnuel($codeInsee);
|
||
|
|
if ($budget !== null) {
|
||
|
|
$io->success("Budget annuel récupéré: " . number_format($budget, 2) . " €");
|
||
|
|
|
||
|
|
// Test avec une population fictive
|
||
|
|
$population = 138668; // Population de Tours
|
||
|
|
$budgetParHabitant = $this->budgetService->getBudgetParHabitant($budget, $population);
|
||
|
|
$io->info("Budget par habitant: " . number_format($budgetParHabitant, 2) . " €");
|
||
|
|
|
||
|
|
// Test écart à la moyenne
|
||
|
|
$moyenne = 1500; // Moyenne fictive
|
||
|
|
$ecart = $this->budgetService->getEcartMoyenneBudgetParHabitant($budgetParHabitant, $moyenne);
|
||
|
|
$io->info("Écart à la moyenne: " . number_format($ecart, 2) . "%");
|
||
|
|
} else {
|
||
|
|
$io->warning("Aucun budget récupéré");
|
||
|
|
}
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$io->error("Erreur: " . $e->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return Command::SUCCESS;
|
||
|
|
}
|
||
|
|
}
|