from apc_perf import ApcPerfdata
import matplotlib.pyplot as plt
from typing import Collection
from dataclasses import dataclass
from collections import defaultdict
import numpy as np

def plot_prop_op_points(apc_data: ApcPerfdata, rpm: float):
    rpm_series = apc_data.rpm_series[rpm]
    
    speeds = [op.speed for op in rpm_series]
    thrusts = [op.thrust for op in rpm_series]
    torques = [op.torque for op in rpm_series]
    
    fig, ax1 = plt.subplots(figsize=(10, 6))

    ax1.plot(speeds, thrusts, label="Thrust", marker='o', color='tab:blue')
    ax1.set_xlabel("Speed")
    ax1.set_ylabel("Thrust", color='tab:blue')
    ax1.tick_params(axis='y', labelcolor='tab:blue')
    
    ax2 = ax1.twinx()
    ax2.plot(speeds, torques, label="Torque", marker='s', color='tab:orange')
    ax2.set_ylabel("Torque", color='tab:orange')
    ax2.tick_params(axis='y', labelcolor='tab:orange')
    
    plt.title(f"PropOppoint Variables vs Speed at RPM {rpm}")

    fig.tight_layout()
    plt.show()

p = ApcPerfdata.from_file('./data/PERFILES2/PER3_10x3.dat')
plot_prop_op_points(p, 1000)
