Skip to content

russelomua/AirQualityCalculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AirQualityCalculator v2

Version Dependents PHP Version Require License Codacy Badge Coverage Badge

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());

References

About

Tool for calculating Air Quality Index for PM2.5, PM19, CO, SO2, NO2, O3 (ozone)

Resources

License

Stars

3 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages