from gait_analysis import EnhancedGaitAnalyzer import os import json from generate_report import generate_markdown_report from datetime import datetime def main(): # Path to test.mp4 # The script is in backend/, test.mp4 is in root/ (../test.mp4) video_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "atmin.mp4")) print(f"Looking for video at: {video_path}") if not os.path.exists(video_path): print("Error: test.mp4 not found!") return print("Initializing EnhancedGaitAnalyzer...") analyzer = EnhancedGaitAnalyzer(age=4) # Assuming age 4 for test print("Processing video... this might take a moment.") try: results = analyzer.process_video(video_path) # Generate report timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") report_filename = f"gait_analysis_report_{timestamp}.md" report_path = os.path.join(os.path.dirname(video_path), report_filename) generate_markdown_report(results, video_path, report_path) # Helper function to safely format numbers def fmt(value, decimals=2): """Format numeric value or return N/A""" if value == 'N/A' or value is None: return 'N/A' try: return f"{float(value):.{decimals}f}" except (ValueError, TypeError): return 'N/A' # Extract new observation outputs summary = results.get("summary", {}) observations = results.get("observations", {}) strategies = results.get("compensatory_strategies", []) reflex_influence = results.get("reflex_influence", "None observed") safety_note = results.get("safety_note", "") weight_dist = results.get("weight_distribution", {}) postural_strength = results.get("postural_strength", {}) clinical_notes = results.get("clinical_notes", []) print("\n" + "="*60) print("CLINICAL GAIT ANALYSIS RESULTS") print("="*60) # 1. Walking Condition walking_condition = summary.get("walking_condition", "Not specified") print(f"\n🚶 WALKING CONDITION: {walking_condition.upper()}") # 2. Observed Movement Patterns print(f"\n� OBSERVED MOVEMENT PATTERNS:") print(f" Trunk: {observations.get('trunk', 'N/A')}") print(f" Head & Neck: {observations.get('head_neck', 'N/A')}") print(f" Arms & Hands: {observations.get('arms_hands', 'N/A')}") print(f" Lower Limbs: {observations.get('lower_limbs', 'N/A')}") print(f" Symmetry: {observations.get('symmetry', 'N/A')}") # 3. Compensatory Strategies print(f"\n💡 COMPENSATORY STRATEGIES:") if strategies: for strategy in strategies: print(f" - {strategy}") else: print(" - None identified") print(f"\n📝 CLINICAL NOTES:") if clinical_notes: for note in clinical_notes: print(f" - {note}") else: print(" - None noted") # 4. Integrated Movement Summary asymmetry = summary.get("phase_asymmetry_percent", 0) stability = summary.get("stability_score", 0) strength = summary.get("strength_score", 0) weight_shift = summary.get("weight_shift_score", 0) gait_quality = summary.get("overall_gait_quality", "unknown") print(f"\n📋 INTEGRATED MOVEMENT SUMMARY:") print(f" Walking Condition: {walking_condition.upper()}") print(f" Overall Gait Quality: {gait_quality.upper()}") print(f" Stability Score: {stability:.0f}/100 | Strength Score: {strength:.0f}/100 | Weight Shift Score: {weight_shift:.0f}/100") print(f" Movement symmetry shows a {asymmetry:.1f}% phase variance.") if reflex_influence: print(f"\n {reflex_influence}") if safety_note: print(f"\n ⚠️ {safety_note}") print("\n" + "="*60) print("NOTE: This is NOT a medical diagnosis. Consult a healthcare") print("professional for proper assessment and treatment.") print("="*60 + "\n") except Exception as e: print(f"An error occurred during processing: {e}") import traceback traceback.print_exc() if __name__ == "__main__": main()