import time

class PowerAuditor:
    def __init__(self, yolo_flops=8.5):
        self.yolo_flops = yolo_flops
        self.total_saved_flops = 0.0
        self.active_frames = 0
        self.idle_frames = 0
        self.start_time = time.time()

    def record(self, active):
        if active:
            self.active_frames += 1
        else:
            self.idle_frames += 1
            self.total_saved_flops += self.yolo_flops

    def get_metrics(self):
        total = self.active_frames + self.idle_frames
        rate = (self.idle_frames / total * 100) if total > 0 else 0
        return {
            "saved_flops": round(self.total_saved_flops, 2),
            "reduction_rate": round(rate, 1),
            "active_count": self.active_frames,
            "idle_count": self.idle_frames,
            "runtime": round(time.time() - self.start_time, 1)
        }