在 Go 里计算 AQI
简而言之,写了个 aqi
,基本用法如下:
go install github.com/ringsaturn/aqi
package main
import (
"fmt"
"github.com/ringsaturn/aqi"
"github.com/ringsaturn/aqi/mep"
)
func main() {
algo := &mep.Algo{}
inputs := []*aqi.Var{
{
P: aqi.Pollutant_PM2_5_1H,
Value: 16,
},
{
P: aqi.Pollutant_PM10_1H,
Value: 88,
},
{
P: aqi.Pollutant_CO_1H,
Value: 0.2,
},
{
P: aqi.Pollutant_SO2_1H,
Value: 3,
},
{
P: aqi.Pollutant_NO2_1H,
Value: 11,
},
{
P: aqi.Pollutant_O3_1H,
Value: 75,
},
}
aqi, primaryPollutant, err := algo.Calc(inputs...)
if err != nil {
panic(err)
}
levelDesc, err := algo.AQIToDesc(aqi)
if err != nil {
panic(err)
}
fmt.Printf("aqi=%v as level=%v with primary pollutant as %v\n", aqi, levelDesc, primaryPollutant)
}
Output:
aqi=69 as level=良 with primary pollutant as [PM10_1H]
Read other posts