package com.gyee.runeconomy.service.WindDirection;

public class Deviation {
    // 计算风速偏差率
    public static double calculateSpeedDeviation(double fanSpeed, double towerSpeed) {
        if (towerSpeed == 0) {
            towerSpeed = 1;
        }
        double deviation = Math.abs(towerSpeed - fanSpeed) / towerSpeed * 100;
        return Double.parseDouble(String.format("%.2f", deviation));  // 保留两位小数
    }

    // 计算风向差值
    public static double calculateDirectionDeviation(double fanDirection, double towerDirection) {
        double difference = Math.abs(towerDirection - fanDirection);
        if (difference > 180) {
            difference = 360 - difference;
        }
        return Double.parseDouble(String.format("%.2f", difference));  // 保留两位小数
    }

}
