russelomua / aqi-calculator
description
2.0
2023-07-21 00:44 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^10
- vimeo/psalm: ^5.13
This package is auto-updated.
Last update: 2025-04-28 20:42:36 UTC
README
Air Quality Index Calculator - is a tool for calculating Air Quality Index for PM2.5, PM19, CO, SO2, NO2, O3 (ozone)
Installation
composer require russelomua/aqi-calculator
Upgrading from v1
Now require PHP 8.1 or higher Fully incompatible with v1, see Usage section for more details
Usage
// 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());