using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AQINEW
{
public class NewAQI
{
#region 浓度标准及aqi标准
//中国浓度标准SO2
int[] BPSO2 = new int[] { 0, 150, 500, 650, 800, 1600, 2100, 2620 };
//中国浓度标准NO2
int[] BPNO2 = new int[] { 0, 100, 200, 700, 1200, 2340, 3090, 3840 };
//中国浓度标准PM25
int[] BPPM25 = new int[] { 0, 35, 75, 115, 150, 250, 350, 500 };
//中国浓度标准CO
int[] BPCO = new int[] { 0, 5, 10, 35, 60, 90, 120, 150 };
//中国浓度标准O3
int[] BPO3 = new int[] { 0, 160, 200, 300, 400, 800, 1000, 1200 };
//中国浓度标准PM10
int[] BPPM10 = new int[] { 0, 50, 150, 250, 350, 420, 500, 600 };
//中国AQI标准
int[] IAQI = new int[] { 0, 50, 100, 150, 200, 300, 400, 500 };
#endregion
int IAQIH, IAQIL, BPH, BPL;
public int GetIAQI(double CP, string ElementName)
{
int currentCP = Convert.ToInt32(CP);
getRangle(CP, ElementName);
double chu = Convert.ToDouble(IAQIH - IAQIL) / Convert.ToDouble(BPH - BPL);
int CurrentAqi = Convert.ToInt32(chu * (currentCP - BPL) + IAQIL);
return Convert.ToInt32(CurrentAqi);
}
int[] NongDu;
/// <summary>
/// 测量范围判定
/// </summary>
/// <param name="Element"></param>
private void getRangle(double CP, string Element)
{
//浓度范围
switch (Element)
{
case "SO2":
NongDu = BPSO2;
break;
case "NO2":
NongDu = BPNO2;
break;
case "PM25":
NongDu = BPPM25;
break;
case "CO":
NongDu = BPCO;
break;
case "O3":
NongDu = BPO3;
break;
case "PM10":
NongDu = BPPM10;
break;
}
//AQI范围
for (int i = 0; i < NongDu.Length - 1; i++)
{
if (CP >= NongDu[i] && CP <= NongDu[i + 1])
{
IAQIH = IAQI[i + 1];
IAQIL = IAQI[i];
BPH = NongDu[i + 1];
BPL = NongDu[i];
break;
}
}
}
Dictionary<string, string> mydic = new Dictionary<string, string>();
/// <summary>
/// 获取首要污染物 以及首要污染物的值
/// </summary>
/// <returns></returns>
public string GetMaxWuranwu(Dictionary<string, string> dic)
{
Dictionary<string, int> mydicNew = new Dictionary<string, int>();
//循环
foreach (KeyValuePair<string, string> item in dic)
{
int Current = GetIAQI(Convert.ToDouble(item.Value), item.Key);
mydicNew.Add(item.Key, Current);
}
int Num = 0;
string Shouyao = "";
foreach (KeyValuePair<string, int> item in mydicNew)
{
int AqiNUM = Convert.ToInt32(item.Value);
if (AqiNUM > Num)
{
Num = AqiNUM;
Shouyao = item.Key;
}
}
return Shouyao + "," + Num;
}
}
}