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

Ignore Versoix VD in dataset #49

Merged
merged 1 commit into from
May 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/Console/UpdateZipcodeDatasetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function fetchDataset(): void

// Open the destination file for writing in binary mode
$fileHandler = fopen('/tmp/dataset.zip', 'wb');
if (!$fileHandler) {
if (! $fileHandler) {
throw new RuntimeException("Failed to open file for writing: '/tmp/dataset.zip'");
}

Expand All @@ -100,7 +100,7 @@ protected function fetchDataset(): void
foreach ($iterator as $file) {
if ($file->isFile() && pathinfo($file->getPathname(), PATHINFO_EXTENSION) === 'csv') {
$destinationFile = self::PATH_TO_CSV;
if (!rename($file->getPathname(), $destinationFile)) {
if (! rename($file->getPathname(), $destinationFile)) {
// Handle potential errors during move operation
throw new \Exception("Error moving file: " . $file->getPathname());
}
Expand Down Expand Up @@ -130,10 +130,18 @@ protected function generateZipcodesFiles(TabularDataReader $records): void
$data = [];

foreach ($records as $zipcodeRecord) {
$city = $zipcodeRecord['Ortschaftsname'];
$zipcode = (int)$zipcodeRecord['PLZ'];
$canton = $zipcodeRecord['Kantonskürzel'];

if ($this->shouldRecordBeIgnored($city, $zipcode, $canton)) {
continue;
}

$data[] = [
'city' => $zipcodeRecord['Ortschaftsname'],
'zipcode' => (int) $zipcodeRecord['PLZ'],
'canton' => $zipcodeRecord['Kantonskürzel'],
'city' => $city,
'zipcode' => $zipcode,
'canton' => $canton,
];
}

Expand All @@ -145,4 +153,13 @@ protected function cleanup(): void
unlink('/tmp/dataset.zip');
unlink(self::PATH_TO_CSV);
}

protected function shouldRecordBeIgnored(string $city, int $zipcode, string $canton): bool
{
if ($zipcode === 1290 && $city === 'Versoix' && $canton === 'VD') {
return true;
}

return false;
}
}
5 changes: 0 additions & 5 deletions src/data/cities.json
Original file line number Diff line number Diff line change
Expand Up @@ -23604,11 +23604,6 @@
"zipcode": 1274,
"canton": "VD"
},
{
"city": "Versoix",
"zipcode": 1290,
"canton": "VD"
},
{
"city": "Mies",
"zipcode": 1295,
Expand Down
Loading