import pandas as pd
import matplotlib.pyplot as plt

# Clean column names
df1.columns = df1.columns.str.strip()
df2.columns = df2.columns.str.strip()

# Drop junk columns (keep only the first 9)
df1 = df1.iloc[:, :9]
df2 = df2.iloc[:, :9]

# Drop header rows that accidentally got into the data
df1 = df1[~df1["DATE"].astype(str).str.contains("DATE")]
df2 = df2[~df2["DATE"].astype(str).str.contains("DATE")]

# Create combined datetime column
df1["DATETIME"] = pd.to_datetime(df1["DATE"] + " " + df1["TIME"])
df2["DATETIME"] = pd.to_datetime(df2["DATE"] + " " + df2["TIME"])


# Calculate average reading interval (in minutes)
df1["DELTA"] = df1["DATETIME"].diff().dt.total_seconds()
df2["DELTA"] = df2["DATETIME"].diff().dt.total_seconds()
print("Avg interval File 1 (minutes):", round(df1["DELTA"].mean() / 60))
print("Avg interval File 2 (minutes):", round(df2["DELTA"].mean() / 60))

# Plot temperatures
plt.figure(figsize=(10, 5))
plt.plot(df1["DATETIME"], df1["ATH_T"], label="ATH_T (File 1)", marker='o')
plt.plot(df1["DATETIME"], df1["BMP_T"], label="BMP_T (File 1)", marker='x')
plt.plot(df2["DATETIME"], df2["ATH_T"], label="ATH_T (File 2)", marker='o')
plt.plot(df2["DATETIME"], df2["BMP_T"], label="BMP_T (File 2)", marker='x')
plt.xlabel("Time")
plt.ylabel("Temperature (°C)")
plt.title("Overlay of ATH_T and BMP_T")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.xticks(rotation=45)
plt.show()

# Plot humidity
plt.figure(figsize=(10, 5))
plt.plot(df1["DATETIME"], df1["ATH_H"], label="ATH_H (File 1)", marker='o')
plt.plot(df2["DATETIME"], df2["ATH_H"], label="ATH_H (File 2)", marker='x')
plt.xlabel("Time")
plt.ylabel("Humidity (%)")
plt.title("Overlay of ATH_H")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.xticks(rotation=45)
plt.show()

