package util

type Direction struct {
	Namezh     string
	Name       string
	Center     float64
	DirectionA float64
	DirectionB float64
}

var ArrWindSpeed [19][2]float64
var mapWindGrade map[int]string
var arrDirection []Direction

func GetWindGrade(speed float64) (string, int) {
	var grade int
	for i, v := range ArrWindSpeed {
		if v[0] <= speed && speed <= v[1] {
			grade = i
			break
		}
	}
	if str, ok := mapWindGrade[grade]; ok {
		return str, grade
	}
	return "", grade
}

func GetWindDirection(direction float64) Direction {
	for _, v := range arrDirection {
		if v.Center != 0 {
			if direction > v.DirectionA && direction <= v.DirectionB {
				return v
			}
		} else {
			if direction > v.DirectionA || direction <= v.DirectionB {
				return v
			}
		}
	}
	return Direction{}
}

func init() {
	//风力等级范围
	ArrWindSpeed = [19][2]float64{
		{0.0, 0.2}, {0.3, 1.5}, {1.6, 3.3}, {3.4, 5.4}, {5.5, 7.9}, {8.0, 10.7},
		{10.8, 13.8}, {13.9, 17.1}, {17.2, 20.7}, {20.8, 24.4}, {24.5, 28.4}, {28.5, 32.6},
		{32.7, 36.9}, {37, 41}, {42, 45}, {46, 51}, {52, 59}, {60, 61.2}, {61.2, 102400},
	}
	//风力等级描述
	mapWindGrade = make(map[int]string)
	mapWindGrade[0] = "无风"
	mapWindGrade[1] = "软风"
	mapWindGrade[2] = "轻风"
	mapWindGrade[3] = "微风"
	mapWindGrade[4] = "和风"
	mapWindGrade[5] = "清劲风"
	mapWindGrade[6] = "强风"
	mapWindGrade[7] = "疾风"
	mapWindGrade[8] = "大风"
	mapWindGrade[9] = "烈风"
	mapWindGrade[10] = "狂风"
	mapWindGrade[11] = "暴风"
	mapWindGrade[12] = "台风"
	mapWindGrade[13] = "台风"
	mapWindGrade[14] = "台风"
	mapWindGrade[15] = "台风"
	mapWindGrade[16] = "台风"
	mapWindGrade[17] = "台风"
	mapWindGrade[18] = "台风"

	//风向描述及度数
	arrDirection = make([]Direction, 8, 8)
	arrDirection[0] = Direction{Namezh: "北", Name: "N", Center: 0, DirectionA: 337.5, DirectionB: 22.5}
	arrDirection[1] = Direction{Namezh: "东北", Name: "NE", Center: 45, DirectionA: 22.5, DirectionB: 67.5}
	arrDirection[2] = Direction{Namezh: "东", Name: "E", Center: 90, DirectionA: 67.5, DirectionB: 112.5}
	arrDirection[3] = Direction{Namezh: "东南", Name: "SN", Center: 135, DirectionA: 112.5, DirectionB: 157.5}
	arrDirection[4] = Direction{Namezh: "南", Name: "S", Center: 180, DirectionA: 157.5, DirectionB: 202.5}
	arrDirection[5] = Direction{Namezh: "西南", Name: "SW", Center: 225, DirectionA: 202.5, DirectionB: 247.5}
	arrDirection[6] = Direction{Namezh: "西", Name: "W", Center: 270, DirectionA: 247.5, DirectionB: 292.5}
	arrDirection[7] = Direction{Namezh: "西北", Name: "NW", Center: 315, DirectionA: 292.5, DirectionB: 337.5}
}
