Data ingestion service tests

This commit is contained in:
rafaeldpsilva
2025-09-10 15:47:28 +01:00
parent b7e734e0d2
commit b2a5b3d229
5 changed files with 3008 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
#!/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())