Created
April 2, 2025 03:39
-
-
Save fqx/807aa8cb7d280814d0369ba57fd08f4d to your computer and use it in GitHub Desktop.
a python script to analyze cleaning effectiveness of filter cleaning using ilo sensor data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| import numpy as np | |
| from datetime import datetime | |
| import pytz | |
| # Read the CSV file | |
| df = pd.read_csv('~/Downloads/history.csv') | |
| # Convert last_changed to datetime (keeping the timezone information) | |
| df['last_changed'] = pd.to_datetime(df['last_changed']) | |
| # Create separate dataframes for each sensor | |
| fan_df = df[df['entity_id'] == 'sensor.hp_ilo_fan_1_speed'].copy() | |
| cpu_df = df[df['entity_id'] == 'sensor.hp_ilo_cpu_temperature'].copy() | |
| inlet_df = df[df['entity_id'] == 'sensor.hp_ilo_inlet_ambient'].copy() | |
| exhaust_df = df[df['entity_id'] == 'sensor.hp_ilo_system_exhaust_temperature'].copy() | |
| # Convert state to numeric | |
| fan_df['state'] = pd.to_numeric(fan_df['state']) | |
| cpu_df['state'] = pd.to_numeric(cpu_df['state']) | |
| inlet_df['state'] = pd.to_numeric(inlet_df['state']) | |
| exhaust_df['state'] = pd.to_numeric(exhaust_df['state']) | |
| # Define cleaning time (with UTC timezone) | |
| cleaning_time = pd.to_datetime('2025-03-28 20:00:00').tz_localize('Asia/Shanghai') | |
| # Rename state columns and drop unnecessary columns | |
| fan_df = fan_df[['last_changed', 'state']].rename(columns={'state': 'fan_speed'}) | |
| inlet_df = inlet_df[['last_changed', 'state']].rename(columns={'state': 'inlet_temp'}) | |
| exhaust_df = exhaust_df[['last_changed', 'state']].rename(columns={'state': 'exhaust_temp'}) | |
| cpu_df = cpu_df[['last_changed', 'state']].rename(columns={'state': 'cpu_temp'}) | |
| # Merge all data | |
| # First merge fan and inlet | |
| merged_df = pd.merge_asof( | |
| fan_df.sort_values('last_changed'), | |
| inlet_df.sort_values('last_changed'), | |
| on='last_changed', | |
| tolerance=pd.Timedelta('5min') | |
| ) | |
| # Then merge exhaust | |
| merged_df = pd.merge_asof( | |
| merged_df, | |
| exhaust_df.sort_values('last_changed'), | |
| on='last_changed', | |
| tolerance=pd.Timedelta('5min') | |
| ) | |
| # Then merge CPU | |
| merged_df = pd.merge_asof( | |
| merged_df, | |
| cpu_df.sort_values('last_changed'), | |
| on='last_changed', | |
| tolerance=pd.Timedelta('5min') | |
| ) | |
| # Add period column after merging | |
| merged_df['period'] = merged_df['last_changed'].apply( | |
| lambda x: 'After Cleaning' if x > cleaning_time else 'Before Cleaning' | |
| ) | |
| # Print column names for debugging | |
| print("Available columns:", merged_df.columns.tolist()) | |
| # Calculate temperature difference and efficiency metrics | |
| merged_df['delta_T'] = merged_df['exhaust_temp'] - merged_df['inlet_temp'] | |
| merged_df['cooling_efficiency'] = merged_df['delta_T'] / merged_df['fan_speed'] | |
| # Create plots | |
| fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(20, 15)) | |
| # Plot 1: Time series of all metrics | |
| ax1.plot(merged_df['last_changed'], merged_df['fan_speed'], label='Fan Speed') | |
| ax1.plot(merged_df['last_changed'], merged_df['inlet_temp'], label='Inlet Temp') | |
| ax1.plot(merged_df['last_changed'], merged_df['exhaust_temp'], label='Exhaust Temp') | |
| ax1.plot(merged_df['last_changed'], merged_df['cpu_temp'], label='CPU Temp') | |
| ax1.axvline(x=cleaning_time, color='r', linestyle='--', label='Cleaning Time') | |
| ax1.legend() | |
| ax1.set_title('Time Series of All Metrics') | |
| ax1.tick_params(axis='x', rotation=45) | |
| ax1.grid(True) | |
| # Plot 2: Fan Speed vs Inlet Temperature | |
| sns.scatterplot(data=merged_df, | |
| x='inlet_temp', | |
| y='fan_speed', | |
| hue='period', | |
| alpha=0.6, | |
| ax=ax2) | |
| ax2.set_title('Fan Speed vs Inlet Temperature') | |
| ax2.grid(True) | |
| # Plot 3: Temperature Difference vs Fan Speed | |
| sns.scatterplot(data=merged_df, | |
| x='fan_speed', | |
| y='delta_T', | |
| hue='period', | |
| alpha=0.6, | |
| ax=ax3) | |
| ax3.set_title('Temperature Difference vs Fan Speed') | |
| ax3.grid(True) | |
| # Plot 4: Cooling Efficiency Over Time | |
| scatter = ax4.scatter(merged_df['last_changed'], merged_df['cooling_efficiency'], | |
| c=merged_df['cpu_temp'], cmap='viridis', alpha=0.6) | |
| ax4.axvline(x=cleaning_time, color='r', linestyle='--', label='Cleaning Time') | |
| ax4.set_title('Cooling Efficiency Over Time (color = CPU Temperature)') | |
| ax4.tick_params(axis='x', rotation=45) | |
| ax4.grid(True) | |
| plt.colorbar(scatter, ax=ax4, label='CPU Temperature') | |
| plt.tight_layout() | |
| plt.show() | |
| # Print comprehensive statistics | |
| print("\nComprehensive Statistics for both periods:") | |
| for period in ['Before Cleaning', 'After Cleaning']: | |
| period_data = merged_df[merged_df['period'] == period] | |
| if len(period_data) > 0: | |
| print(f"\n{period}:") | |
| print(f"Number of data points: {len(period_data)}") | |
| print(f"Average fan speed: {period_data['fan_speed'].mean():.2f}") | |
| print(f"Average inlet temperature: {period_data['inlet_temp'].mean():.2f}") | |
| print(f"Average exhaust temperature: {period_data['exhaust_temp'].mean():.2f}") | |
| print(f"Average CPU temperature: {period_data['cpu_temp'].mean():.2f}") | |
| print(f"Average temperature difference (Exhaust - Inlet): {period_data['delta_T'].mean():.2f}") | |
| print(f"Average cooling efficiency (ΔT/Fan Speed): {period_data['cooling_efficiency'].mean():.3f}") | |
| print("\nTemperature Ranges:") | |
| print(f"Inlet: {period_data['inlet_temp'].min():.1f} - {period_data['inlet_temp'].max():.1f}") | |
| print(f"Exhaust: {period_data['exhaust_temp'].min():.1f} - {period_data['exhaust_temp'].max():.1f}") | |
| print(f"CPU: {period_data['cpu_temp'].min():.1f} - {period_data['cpu_temp'].max():.1f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment