#!/usr/bin/env python3 """ Demo script to show DTS API Test Suite capabilities without running a full DTS sequence. This demonstrates the monitoring and reporting features. """ import sys import time from dts_api_test_suite import DTSAPITester, TestConfig def demo_api_connectivity(): """Demo API connectivity testing""" print("šŸ” Demo: API Connectivity Test") print("=" * 50) tester = DTSAPITester() print("Testing API connection...") if tester.check_system_status(): print("āœ… API is accessible and PLC is connected") # Test getting current step progress print("\nTesting current step progress endpoint...") progress = tester.get_current_step_progress() if progress: current_mode = progress.get("current_mode", "unknown") timer_based = progress.get("timer_based_progress", False) print(f"šŸ“Š Current system mode: {current_mode}") print(f"ā±ļø Timer-based progress available: {timer_based}") if timer_based: timer_addr = progress.get("timer_address") timer_val = progress.get("current_timer_value") progress_pct = progress.get("progress_percent", 0) print(f" Timer R{timer_addr}: {timer_val} ({progress_pct}% progress)") else: print("āš ļø Could not get current step progress") return True else: print("āŒ API connectivity failed") return False def demo_dts_status_monitoring(): """Demo DTS status monitoring without starting DTS""" print("\nšŸ” Demo: DTS Status Monitoring") print("=" * 50) tester = DTSAPITester() # Check if there are any existing DTS tasks print("Checking for existing DTS tasks...") response, _ = tester._make_api_request("GET", "/dts/status") if response: latest_task = response.get("latest_task") total_tasks = response.get("total_tasks", 0) active_tasks = response.get("active_tasks", []) print(f"šŸ“‹ Total DTS tasks in history: {total_tasks}") print(f"šŸ”„ Active tasks: {len(active_tasks)}") if latest_task: task_id = latest_task.get("task_id", "unknown") status = latest_task.get("status", "unknown") current_step = latest_task.get("current_step", "unknown") progress = latest_task.get("progress_percent", 0) print(f"šŸ“Š Latest task: {task_id}") print(f" Status: {status}") print(f" Current step: {current_step}") print(f" Progress: {progress}%") if latest_task.get("timer_info"): timer_info = latest_task["timer_info"] print(f" Timer info: Mode {timer_info.get('current_mode')}, " f"Timer R{timer_info.get('timer_address', 'N/A')}") else: print("ā„¹ļø No previous DTS tasks found") else: print("āŒ Could not retrieve DTS status") def demo_configuration(): """Demo configuration options""" print("\nšŸ” Demo: Configuration Options") print("=" * 50) # Show default configuration config = TestConfig() print("Default configuration:") print(f" API URL: {config.API_BASE_URL}") print(f" Polling interval: {config.POLLING_INTERVAL}s") print(f" Request timeout: {config.REQUEST_TIMEOUT}s") print(f" Log file enabled: {config.LOG_FILE_ENABLED}") print(f" CSV export enabled: {config.CSV_EXPORT_ENABLED}") # Show expected screen durations print("\nExpected screen durations:") for mode, duration in config.EXPECTED_SCREEN_DURATIONS.items(): screen_names = {5: "Priming", 6: "Init", 8: "Fresh Water Flush"} screen_name = screen_names.get(int(mode), f"Mode {mode}") print(f" {screen_name}: {duration}s") def demo_api_endpoints(): """Demo available API endpoints""" print("\nšŸ” Demo: Available API Endpoints") print("=" * 50) tester = DTSAPITester() # Test config endpoint print("Testing API configuration endpoint...") response, _ = tester._make_api_request("GET", "/config") if response: api_version = response.get("api_version", "unknown") endpoints = response.get("endpoints", {}) print(f"šŸ“” API Version: {api_version}") print("šŸ“‹ Available endpoints:") # Show DTS-related endpoints dts_endpoints = {k: v for k, v in endpoints.items() if "dts" in k.lower()} for endpoint, description in dts_endpoints.items(): print(f" {endpoint}: {description}") else: print("āŒ Could not retrieve API configuration") def main(): """Run all demos""" print("šŸš€ DTS API Test Suite - Demo Mode") print("=" * 60) print("This demo shows the test suite capabilities without starting DTS") print("=" * 60) # Run demos success = True try: # Demo 1: API Connectivity if not demo_api_connectivity(): success = False # Demo 2: DTS Status Monitoring demo_dts_status_monitoring() # Demo 3: Configuration demo_configuration() # Demo 4: API Endpoints demo_api_endpoints() print("\n" + "=" * 60) if success: print("āœ… Demo completed successfully!") print("\nTo run actual DTS monitoring:") print(" python run_dts_test.py basic") print(" python dts_api_test_suite.py --verbose") else: print("āŒ Demo completed with issues") print("Check API server status and PLC connection") print("=" * 60) except KeyboardInterrupt: print("\nšŸ‘‹ Demo interrupted by user") except Exception as e: print(f"\nāŒ Demo error: {e}") success = False return 0 if success else 1 if __name__ == "__main__": sys.exit(main())