russelomua/aqi-calculator

2.0 2023-07-21 00:44 UTC

This package is auto-updated.

Last update: 2024-09-28 19:21:16 UTC


README

Version Dependents PHP Version Require License Codacy Badge Coverage Badge

空气质量指数计算器 - 是用于计算PM2.5、PM10、CO、SO2、NO2、O3(臭氧)空气质量指数的工具

安装

composer require russelomua/aqi-calculator

从v1升级

现在需要PHP 8.1或更高版本,与v1完全不兼容,请参阅使用部分以获取更多详细信息

使用方法

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

参考资料