PHP code example of russelomua / aqi-calculator

1. Go to this page and download the library: Download russelomua/aqi-calculator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

russelomua / aqi-calculator example snippets


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