Files
AlarmAnalysis/test_changes.py
andy f08a1a9bf5 Initial commit: alarm analysis project
Python project for analyzing alarm data from building monitoring systems.
Includes alarm analyzer, plotting, tests, and source data files.
2026-02-26 09:03:54 -05:00

74 lines
2.7 KiB
Python

#!/usr/bin/env python
# Test script to validate the changes made to alarm_analyzer.py
import sys
import os
import pandas as pd
def test_code_structure():
"""Test that the modified code has the correct structure"""
# Read the file to check if our changes were applied correctly
with open('alarm_analyzer.py', 'r') as f:
content = f.read()
print("Testing if new methods were added correctly...")
# Check if the add_sensor_info_to_alarms method exists
if 'def add_sensor_info_to_alarms(self)' in content:
print("[OK] add_sensor_info_to_alarms method exists")
else:
print("[ERROR] add_sensor_info_to_alarms method missing")
# Check if the load_data method was updated
if 'header=4' in content and 'Remote SN' in content:
print("[OK] load_data method updated with proper header reading")
else:
print("[ERROR] load_data method not properly updated")
# Check if sensor info is added to paired events
if 'Sensor_Name' in content and 'Sensor_Group' in content and 'Sensor_Type' in content:
print("[OK] Sensor information added to paired events")
else:
print("[ERROR] Sensor information not properly added to paired events")
# Check if group-based analysis was added
if 'group_counts' in content and 'mtbf_by_group' in content:
print("[OK] Group-based analysis added to basic and advanced analysis")
else:
print("[ERROR] Group-based analysis not properly added")
# Check if group-based visualizations were added
if 'Group-Based Analysis Dashboard' in content:
print("[OK] Group-based visualizations added")
else:
print("[ERROR] Group-based visualizations not properly added")
# Check if group-based exports were added
if 'group_statistics.csv' in content:
print("[OK] Group-based exports added")
else:
print("[ERROR] Group-based exports not properly added")
print("\nAll structural changes have been validated!")
def test_logic():
"""Test the logic of the changes"""
print("\nTesting the logic of the changes...")
# Check that the updated main section uses the correct file name
with open('alarm_analyzer.py', 'r') as f:
content = f.read()
if 'SensorReport Cardinal 2025-12-23_processed.xlsx' in content:
print("[OK] Main section updated with correct sensor report file name")
else:
print("[ERROR] Main section not updated with correct sensor report file name")
print("Logic validation completed!")
if __name__ == "__main__":
print("Validating changes made to alarm_analyzer.py...")
test_code_structure()
test_logic()
print("\nValidation completed successfully!")