Spaces:
Runtime error
Runtime error
| import pandas as pd | |
| import json | |
| import sys | |
| import os | |
| # Add project root to path | |
| project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '.')) | |
| if project_root not in sys.path: | |
| sys.path.append(project_root) | |
| from kp_core.kp_engine import KPEngine | |
| from kp_core.analysis_engine import AnalysisEngine | |
| def test_debilitation_implementation(): | |
| """Test the debilitation rules implementation using the critical Saturn case""" | |
| print("π¬ TESTING CLASSICAL KP DEBILITATION IMPLEMENTATION") | |
| print("="*65) | |
| # Load the critical match data | |
| with open('match_archive/2025-06-29_dind_vs_tri.json', 'r') as f: | |
| match_data = json.load(f) | |
| # Parse planets data directly from match data | |
| planets_data = json.loads(match_data['planets_df']) | |
| # Get match details for engine initialization | |
| match_details = match_data['match_details'] | |
| dt_str = match_details['datetime_utc'] | |
| lat = match_details['lat'] | |
| lon = match_details['lon'] | |
| # Convert datetime string to datetime object | |
| from datetime import datetime | |
| dt = datetime.fromisoformat(dt_str.replace('Z', '+00:00')) | |
| # Initialize engines | |
| engine = KPEngine(dt, lat, lon) | |
| # Override with saved data | |
| engine.planets = pd.DataFrame(planets_data['data'], | |
| columns=planets_data['columns'], | |
| index=planets_data['index']) | |
| analyzer = AnalysisEngine(engine, "Asc", "Desc") | |
| print("1. ORIGINAL VS CORRECTED SATURN ANALYSIS:") | |
| print("-" * 50) | |
| # Test Saturn specifically | |
| saturn_info = engine.planets.loc['Saturn'] | |
| print(f"Saturn Position: {saturn_info['longitude']:.2f}Β° {saturn_info['sign']}") | |
| print(f"Saturn Significators: {', '.join(map(str, [s[0] for s in analyzer.get_significators('Saturn')]))}") | |
| # Calculate base score (without corrections) | |
| base_score = analyzer._calculate_base_score('Saturn') | |
| print(f"Base Score (no corrections): {base_score:+.4f}") | |
| # Calculate corrected score | |
| corrected_score = analyzer.calculate_planet_score('Saturn') | |
| print(f"Corrected Score (with rules): {corrected_score:+.4f}") | |
| correction_amount = corrected_score - base_score | |
| print(f"Total Correction Applied: {correction_amount:+.4f}") | |
| if corrected_score > 0 and base_score < 0: | |
| print("β SUCCESS: Saturn flipped from negative to positive!") | |
| elif corrected_score > base_score: | |
| print("π Saturn became more positive") | |
| else: | |
| print("β No improvement detected") | |
| print() | |
| print("2. BREAKDOWN OF DEBILITATION CORRECTIONS:") | |
| print("-" * 50) | |
| # Get detailed breakdown | |
| correction_breakdown = analyzer._apply_debilitation_rules('Saturn', base_score) | |
| print(f"Total Debilitation Correction: {correction_breakdown:+.4f}") | |
| # Test other key planets for comparison | |
| print() | |
| print("3. KEY PLANETS COMPARISON:") | |
| print("-" * 50) | |
| key_planets = ['Mars', 'Venus', 'Jupiter', 'Mercury'] | |
| for planet in key_planets: | |
| if planet in engine.planets.index: | |
| score = analyzer.calculate_planet_score(planet) | |
| base = analyzer._calculate_base_score(planet) | |
| correction = score - base | |
| print(f"{planet:8}: Base {base:+.4f} β Final {score:+.4f} (Ξ {correction:+.4f})") | |
| print() | |
| print("4. TIMELINE IMPACT SIMULATION:") | |
| print("-" * 50) | |
| # Load timeline to test impact | |
| asc_timeline_str = match_data['asc_timeline_df'] | |
| asc_timeline_data = json.loads(asc_timeline_str) | |
| asc_df = pd.DataFrame(asc_timeline_data['data'], | |
| columns=asc_timeline_data['columns'], | |
| index=asc_timeline_data['index']) | |
| # Convert timestamps | |
| asc_df['Start_IST'] = pd.to_datetime(asc_df['Start Time'], unit='ms').dt.tz_localize('UTC').dt.tz_convert('Asia/Kolkata').dt.strftime('%H:%M:%S') | |
| asc_df['End_IST'] = pd.to_datetime(asc_df['End Time'], unit='ms').dt.tz_localize('UTC').dt.tz_convert('Asia/Kolkata').dt.strftime('%H:%M:%S') | |
| # Find Saturn periods in critical timeframe | |
| saturn_periods = asc_df[(asc_df['NL_Planet'] == 'Sa') | (asc_df['SL_Planet'] == 'Sa') | (asc_df['SSL_Planet'] == 'Sa')] | |
| critical_periods = saturn_periods[(saturn_periods['Start_IST'] >= '22:15:00') & | |
| (saturn_periods['Start_IST'] <= '22:39:00')] | |
| print(f"Found {len(critical_periods)} Saturn periods in critical timeframe (22:15-22:39)") | |
| for idx, row in critical_periods.iterrows(): | |
| # Recalculate score with new system | |
| ssl_planet = row['SSL_Planet'] | |
| if ssl_planet == 'Sa': # Saturn is SSL | |
| new_score = corrected_score | |
| else: | |
| new_score = analyzer.calculate_planet_score(ssl_planet) | |
| original_score = row['Score'] | |
| print(f"Period {idx}: {row['Start_IST']}-{row['End_IST']}") | |
| print(f" SSL Planet: {ssl_planet}") | |
| print(f" Original Score: {original_score:+.4f}") | |
| print(f" New Score: {new_score:+.4f}") | |
| print(f" Change: {new_score - original_score:+.4f}") | |
| # Check verdict change | |
| old_verdict = "Pro-Desc" if original_score < -0.1 else "Neutral" if abs(original_score) < 0.1 else "Pro-Asc" | |
| new_verdict = "Pro-Desc" if new_score < -0.1 else "Neutral" if abs(new_score) < 0.1 else "Pro-Asc" | |
| if old_verdict != new_verdict: | |
| print(f" π VERDICT CHANGE: {old_verdict} β {new_verdict}") | |
| print() | |
| print("5. IMPLEMENTATION STATUS:") | |
| print("-" * 50) | |
| if correction_amount > 0.5: | |
| print("β CLASSICAL KP RULES SUCCESSFULLY IMPLEMENTED") | |
| print(" - Saturn shows strong positive correction") | |
| print(" - Neecha Bhanga principles working correctly") | |
| print(" - Match outcome discrepancy should be resolved") | |
| elif correction_amount > 0.2: | |
| print("β DEBILITATION RULES IMPLEMENTED") | |
| print(" - Saturn shows moderate correction") | |
| print(" - Partial resolution of discrepancy") | |
| else: | |
| print("β οΈ IMPLEMENTATION NEEDS REVIEW") | |
| print(" - Correction amount insufficient") | |
| print(" - May need parameter adjustment") | |
| print(f"\nFinal Saturn Score: {corrected_score:+.4f}") | |
| print("Test completed successfully!") | |
| if __name__ == "__main__": | |
| test_debilitation_implementation() |