Skip to content

Commit

Permalink
add crontab and finish census command
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStorz committed Oct 27, 2023
1 parent 8de0204 commit 445e429
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 3 additions & 0 deletions crontab
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# Run every 3 months at 00:00 (AM)
0 0 1 */3 * /usr/local/bin/php /srv/bin/console app:import-geo-addresses

# Run once a year on the first of february at 01:00 (AM)
0 1 1 2 * /usr/local/bin/php /srv/bin/console app:fetch-census
12 changes: 4 additions & 8 deletions src/Command/FetchCensusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class FetchCensusCommand extends StatisticsCommand
protected GroupTypeRepository $groupTypeRepository;

private SymfonyStyle $io;
private $start;

public function __construct(
CensusAPIService $apiService,
Expand All @@ -36,16 +37,16 @@ public function __construct(
public function configure()
{
$this->setName('app:fetch-census')
->setDescription('Not implemented');
->setDescription('Fetch and aggregate census data');
}

public function execute(InputInterface $input, OutputInterface $output)
{
$this->start = microtime(true);
$this->io = new SymfonyStyle($input, $output);

$year = (int) date('Y');
$minYear = $year - 6;
$groupsToAggregate = [];
// Fetch groups
while ($year > $minYear) {
$this->io->writeln('year ' . $year);
Expand All @@ -54,15 +55,11 @@ public function execute(InputInterface $input, OutputInterface $output)
foreach ($rawCensusGroups as $rawCensusGroup) {
$exists = $this->censusGroupRepository->findOneBy(['group_id' => $rawCensusGroup['group_id'], 'year' => $year]);
if (is_null($exists)) {
$groupsToAggregate[] = $rawCensusGroup['group_id'];
$this->mapRawCensusGroupToCensusGroup($rawCensusGroup, $year);
}
}
$year--;
}
// Aggregate Groups
foreach (array_unique($groupsToAggregate) as $groupId) {
}
return Command::SUCCESS;
}

Expand Down Expand Up @@ -102,9 +99,8 @@ private function sanitizeValue($raw): int
}


// TODO: Implement the statistics
public function getStats(): CommandStatistics
{
return new CommandStatistics(0, 'Statistics not yet implemented.');
return new CommandStatistics(microtime(true) - $this->start, '');
}
}

0 comments on commit 445e429

Please sign in to comment.