Air Quality Index Calculator - is a tool for calculating Air Quality Index for PM2.5, PM19, CO, SO2, NO2, O3 (ozone)
composer require russelomua/aqi-calculatorNow require PHP 8.1 or higher Fully incompatible with v1, see Usage section for more details
// Must contains min 2 values of measurements
// good to use 12 or 24 values for PM25 and PM10
$concentrations = [13, 16, 10, 21, 74, 64, 53, 82, 90, 75, 80, 50];
$nowCast = new \AirQuality\NowCast($concentrations);
// NowCast value only
echo $nowCast->getValue();
$pollutant = new \AirQuality\Pollutants\PM25Pollutant();
$calculator = $nowCast->createCalculator($pollutant);
// Full quality object
$quality = $calculator->getQuality();
// Index only quality object
$index = $calculator->getIndex();
// NowCast
echo $quality->nowCast;
// AQI
echo $quality->index->value;
// AQI category enum
// has methods for getting category name and color
echo $quality->index->category?->value;
echo $quality->index->category?->getName();
echo $quality->index->category?->getHexColor();
// Or all together
var_dump($quality->jsonSerialize());