#!/usr/bin/env python3 """ Test SLG Processor with sample SA4CPS data Simple test to validate .slg_v2 file processing """ import asyncio import sys import os from pathlib import Path # Add src directory to path sys.path.append(str(Path(__file__).parent.parent / "src")) from slg_processor import SLGProcessor async def test_sample_file(): """Test processing the sample .slg_v2 file""" print("๐Ÿงช Testing SLG Processor with sample file") print("=" * 45) # Path to sample file sample_file = Path(__file__).parent / "ORDCELPE_20250907_8947167363.sgl_v2" if not sample_file.exists(): print(f"โŒ Sample file not found: {sample_file}") return processor = SLGProcessor() try: # Process the file records = await processor.process_file(str(sample_file), sample_file.name) print(f"โœ… File processed successfully") print(f"๐Ÿ“Š Records extracted: {len(records)}") if records: # Show first few records print(f"\n๐Ÿ“‹ Sample Records:") for i, record in enumerate(records[:3]): print(f" {i+1}. {record['timestamp']} - {record['value']} {record['unit']} (Meter: {record['meter_id']})") if len(records) > 3: print(f" ... and {len(records) - 3} more records") # Show statistics total_energy = sum(r['value'] for r in records) print(f"\n๐Ÿ“ˆ Statistics:") print(f" Total Energy: {total_energy:.3f} kW") print(f" Average: {total_energy/len(records):.3f} kW") print(f" Time Range: {records[0]['timestamp']} to {records[-1]['timestamp']}") else: print("โš ๏ธ No records extracted from file") except Exception as e: print(f"โŒ Error processing file: {e}") import traceback traceback.print_exc() def validate_environment(): """Validate test environment""" print("๐Ÿ”ง Validating Test Environment") print("-" * 35) # Check if sample file exists sample_file = Path(__file__).parent / "ORDCELPE_20250907_8947167363.sgl_v2" if sample_file.exists(): print(f"โœ… Sample file found: {sample_file.name}") print(f" Size: {sample_file.stat().st_size} bytes") else: print(f"โŒ Sample file missing: {sample_file}") # Check source files src_dir = Path(__file__).parent.parent / "src" required_files = ["main.py", "slg_processor.py", "config.py", "ftp_monitor.py", "database.py"] for filename in required_files: file_path = src_dir / filename if file_path.exists(): print(f"โœ… Source file: {filename}") else: print(f"โŒ Missing: {filename}") async def main(): """Main test function""" print("๐Ÿš€ SA4CPS Data Ingestion Service - Test Suite") print("=" * 50) validate_environment() print() await test_sample_file() print("\n" + "=" * 50) print("โœ… Test suite completed") if __name__ == "__main__": asyncio.run(main())