Skip to content
Permalink
Branch: master
Find file Copy path
1 contributor

Users who have contributed to this file

31 lines (25 sloc) 704 Bytes
<?php
$data = json_decode(file_get_contents(__DIR__ . '/../data/air.json'), true);
$lines = [];
function getLabel(int $index): string {
if($index <= 50) {
return 'good';
} elseif($index <= 100) {
return 'moderate';
} elseif ($index <= 150) {
return 'unhealthy for sensitive';
} elseif ($index <= 200) {
return 'unhealthy';
} elseif ($index <= 300) {
return 'very unhealthy';
}
return 'hazardous';
}
foreach ($data['data'] as $row) {
$lines[] = sprintf('%s;%s;%s',
$row['lat'],
$row['lon'],
getLabel((int) $row['aqi'])
);
}
file_put_contents(__DIR__ . '/../data/air.csv', implode(PHP_EOL, $lines));
You can’t perform that action at this time.