import math


class PurpleEyeFusionAgent:
    def __init__(self, visual_data, env_data, expert_model):

        self.v = visual_data
        self.e = env_data
        self.m = expert_model

    def calculate_fused_risk(self):

        temp_stress = 1.0 - abs(self.e['temp'] - self.m.optimal_temp) / 15
        hum_stress = 1.0 if self.e['hum'] > self.m.optimal_hum else (self.e['hum'] / self.m.optimal_hum)
        env_risk = (max(0, temp_stress) + hum_stress) / 2

        fused_score = (self.v['area_ratio'] * 0.6) + (env_risk * 0.4)

        future_severity = self.v['area_ratio'] * math.exp(self.m.base_k * env_risk * 48)

        return {
            "current_fused_score": round(fused_score * 100, 2),
            "future_48h_severity": round(min(1.0, future_severity) * 100, 2),
            "env_risk_level": "高" if env_risk > 0.7 else "低"
        }

    def get_logistics_decision(self):

        q10 = 2.0
        remaining_hours = (72 * self.m.shelf_life_factor) / (q10 ** ((self.e['temp'] - 10) / 10))
        return round(max(0, remaining_hours), 1)