
    6h_                     R    d dl Zd dlZd dlmZ d dlmZ d dlmZ	 g dZ
d Zd Zd Zy)    N)datetime)                  c           	         t        t        | j                  d            \  }}}t        t        |j                  d            \  }}	||	dz  z   }
|
t        |      z
  }t	        j
                  ||||      }t	        j                  d       t	        j                  |t        j                        d   }|d   }t	        j                  |t        j                        d   }|d   }t	        j                  |t        j                        d   }|d   }t	        j                  |t        j                        d   }|d   }t	        j                  |||d      \  }}|d   }t        ||      }t        ||      }t        ||      }t        ||      }i }t        dd      D ]  }||z   dz
  d	z  dz   ||<    |j                  ||      }t!        |      }i } d
}!d}"|t"        v rd| | d<   d}!|"dz  }"|t"        v r/d| ddj%                  t        t&        |             | d<   d}!|"dz  }"t)        ||z
        dk  st)        ||z
        dkD  rd| d| | d<   d}!|"dz  }"n||k(  rd| | d<   d}!|"dz  }"t)        ||z
        dk  st)        ||z
        dkD  r&t        |dz        dz   }#|#dk(  rd| d| d<   d}!|"d z  }"d!}$|"dk(  rd"}$n|"dk  rd#|" d$}$n|"d%k  rd#|" d&}$nd#|" d'}$| |!|$|"d(S ))a  
    Calculate Mangal Dosh (Mars Affliction) based on birth details
    
    Parameters:
    dob (str): Date of birth in DD/MM/YYYY format
    tob (str): Time of birth in HH:MM format
    latitude (float): Latitude of birth place
    longitude (float): Longitude of birth place
    timezone (float): Timezone offset in hours
    
    Returns:
    dict: Mangal Dosh analysis results
    /:g      N@Nr      Pr      r	   Fz&Mangal dosh from lagna, mars in house lagnaT   z+Mangal dosh from moon lagna, mars in house z, aspecting the houses z, moon   
   i^  zEMangal dosh along with mars-saturn association/aspect, mars in house z and saturn in house saturn   z>Mangal dosh along with mars-saturn conjunction, both in house    r   z%Rahu transforming into mars in house z in the sign of Scorpiorahur    z&No Mangal Dosh detected in your chart.zYou are z8% manglik, which is considered mild. No remedies needed.2   z<% manglik, which is moderate. Some simple remedies may help.z/% manglik. It is good to consult an astrologer.)factorsis_dosha_presentbot_responsescore)mapintsplitfloatswejuldayset_ephe_pathcalc_utMARSMOONSATURN	MEAN_NODEhouses	get_houserangegetget_mars_aspectsMANGAL_HOUSESjoinstrabs)%dobtoblatitude	longitudetimezonedaymonthyearhourminutedecimal_timeut_hourjdmars_pos	mars_longmoon_pos	moon_long
saturn_possaturn_longrahu_pos	rahu_longhouse_cuspsascmcasc_deg
mars_house
moon_housesaturn_house
rahu_housemoon_lagna_housesimars_moon_housemars_aspectsr   r   r   	rahu_signr   s%                                        !D:\jyotish\support\mangal_dosh.pycalculate_mangal_doshrU      s    3		#/CsCIIcN+LD&&4-'L U8_,G	D%g	.B d {{2sxx(+HI{{2sxx(+HIR,Q/JQ-K{{2s}}-a0HI B)TBKAhG 9k2J9k2J[+6L9k2J 1b\ *Q 2b81<!  (++J
CO $J/L GE ]"CJ<P -'GGXXoptpypyz}  B  DP  {Q  qR  pS  T 9{"#b(C	K0G,H3,Ncdnco  pE  FR  ES  T	|	#\]g\hi 9y !B&#i).C*Ds*J	B'!+	> Ej\QhiGFO#QJE Lz?	!%(`a	!%(de!%(WX ,$	     c                     t        d      D ]=  }||   }||dz   dz     }||k  r|dz  }| }||k  r|dz  }||cxk  r|k  s5n 8|dz   c S  y)z
    Determine which house a planet is in based on its longitude
    
    Parameters:
    planet_long (float): Planet's longitude
    house_cusps (list): List of house cusps longitudes
    
    Returns:
    int: House number (1-12)
    r	   r   ih  )r,   )planet_longrH   rP   startendposs         rT   r+   r+      sm     2YA1Q3"*%;3JC;3JCC#q5L  rV   c                     g }|j                  | dz   dz  xs d       |j                  | dz   dz  xs d       |j                  | dz   dz  xs d       |S )z
    Get houses aspected by Mars based on its house position
    
    Parameters:
    mars_house (int): House position of Mars (1-12)
    
    Returns:
    list: List of houses aspected by Mars
       r	      r   )append)rK   aspectss     rT   r.   r.      s\     GNNJNb(.B/NNJNb(.B/NNJNb(.B/NrV   )swissephr"   mathr   support.mod_constantsmod_constantscsupport.mod_generalmod_generalgenr/   rU   r+   r.    rV   rT   <module>rj      s.       ! ! $pd2rV   