Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix station #87

Merged
merged 18 commits into from Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions composer.json
Expand Up @@ -8,11 +8,13 @@
"calderacc/yourls-api-manager": "^0.2.0",
"doctrine/doctrine-migrations-bundle": "^1.0",
"dragonmantank/cron-expression": "^2.1",
"fresh/doctrine-enum-bundle": "^6.2",
"friendsofsymfony/elastica-bundle": "^5.0",
"friendsofsymfony/jsrouting-bundle": "^2.2",
"hwi/oauth-bundle": "^0.6.1",
"jms/serializer-bundle": "^2.3",
"jublonet/codebird-php": "^3.1",
"league/csv": "^9.1",
"maxh/php-nominatim": "^1.2",
"nelmio/api-doc-bundle": "^3.1",
"php-curl-class/php-curl-class": "^8.0",
Expand Down
151 changes: 149 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/packages/doctrine.yaml
Expand Up @@ -14,6 +14,11 @@ doctrine:

# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'

types:
StationType: App\DBAL\Types\StationType
AreaType: App\DBAL\Types\AreaType

orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
Expand Down
48 changes: 35 additions & 13 deletions src/Command/StationCommand.php
Expand Up @@ -5,8 +5,10 @@
use App\Entity\Station;
use App\StationLoader\StationLoader;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class StationCommand extends Command
Expand All @@ -25,39 +27,59 @@ protected function configure()
{
$this
->setName('luft:station')
->setDescription('');
->addOption('update', 'u', InputOption::VALUE_NONE, 'Update existing station data')
->setDescription('Fetch station list from Umweltbundesamt');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('update')) {
$this->stationLoader->setUpdate(true);
}

$this->stationLoader->load();

$output->writeln('New stations');
$progressBar = new ProgressBar($output, $this->stationLoader->count());

$table = new Table($output);
$table->setHeaders(['stationCode', 'stateCode', 'title', 'latitude', 'longitude']);
$this->stationLoader->process(function() use ($progressBar) {
$progressBar->advance();
});

foreach ($this->stationLoader->getNewStationList() as $newStation) {
$this->addStationRow($table, $newStation);
}
$progressBar->finish();

$table->render();
$output->writeln('Existing stations');
$this->printTable($output, $this->stationLoader->getExistingStationList());

$output->writeln('');
$output->writeln('Existing stations');

$output->writeln('New stations');
$this->printTable($output, $this->stationLoader->getNewStationList());
}

protected function printTable(OutputInterface $output, array $stationList): void
{
$table = new Table($output);
$table->setHeaders(['stationCode', 'stateCode', 'title', 'latitude', 'longitude']);
$table->setHeaders(['stationCode', 'stateCode', 'title', 'latitude', 'longitude', 'altitude', 'fromDate', 'untilDate', 'stationType']);

foreach ($this->stationLoader->getExistingStationList() as $existingStation) {
$this->addStationRow($table, $existingStation);
foreach ($stationList as $station) {
$this->addStationRow($table, $station);
}

$table->render();
}

protected function addStationRow(Table $table, Station $station): void
{
$table->addRow([$station->getStationCode(), $station->getStateCode(), $station->getTitle(), $station->getLatitude(), $station->getLongitude()]);
$table->addRow([
$station->getStationCode(),
$station->getStateCode(),
$station->getTitle(),
$station->getLatitude(),
$station->getLongitude(),
$station->getAltitude() ?? '',
$station->getFromDate() ? $station->getFromDate()->format('Y-m-d') : '',
$station->getUntilDate() ? $station->getUntilDate()->format('Y-m-d') : '',
$station->getStationType(),
]);
}
}
Empty file added src/DBAL/Types/.gitignore
Empty file.
18 changes: 18 additions & 0 deletions src/DBAL/Types/AreaType.php
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace App\DBAL\Types;

use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;

final class AreaType extends AbstractEnumType
{
public const URBAN = 'urban';
public const SUBURBAN = 'suburban';
public const RURAL = 'rural';

protected static $choices = [
self::URBAN => 'station.area.urban',
self::SUBURBAN => 'station.area.suburban',
self::RURAL => 'station.area.rural',
];
}
18 changes: 18 additions & 0 deletions src/DBAL/Types/StationType.php
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace App\DBAL\Types;

use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;

final class StationType extends AbstractEnumType
{
public const TRAFFIC = 'traffic';
public const BACKGROUND = 'background';
public const INDUSTRIAL= 'industrial';

protected static $choices = [
self::TRAFFIC => 'station.type.traffic',
self::BACKGROUND => 'station.type.background',
self::INDUSTRIAL => 'station.type.industrial',
];
}