# The AshtakaVarga calculation is made using method provided in below webpage:
# Webpage: https://www.thevedichoroscope.com/asthvarga-lessons/asthvarga-lessons-1/

import parashara.mod_astrodata as data
import parashara.mod_general as gen

# Bhinna ashtaka varga mappings
BAV_BinduMatrix = {
    "Sun": {"Sun": [1, 2, 4, 7, 8, 9, 10, 11],  # Sun is benefic from suns 1st, 2nd, 4th, ... 11th houses
            # Sun is benefic from Moon in following positions 3,6,10,11.
            "Moon": [3, 6, 10, 11],
            "Mars": [1, 2, 4, 7, 8, 9, 10, 11],
            "Mercury": [3, 5, 6, 9, 10, 11, 12],
            "Jupiter": [5, 6, 9, 11],
            "Venus": [6, 7, 12],
            "Saturn": [1, 2, 4, 7, 8, 9, 10, 11],
            "Ascendant": [3, 4, 6, 10, 11, 12]
            },
    "Moon": {"Sun": [3, 6, 7, 8, 10, 11],
             "Moon": [1, 3, 6, 7, 10, 11],
             "Mars": [2, 3, 5, 6, 9, 10, 11],
             "Mercury": [1, 3, 4, 5, 7, 8, 10, 11],
             "Jupiter": [1, 4, 7, 8, 10, 11, 12],
             "Venus": [3, 4, 5, 7, 9, 10, 11],
             "Saturn": [3, 5, 6, 11],
             "Ascendant": [3, 6, 10, 11]
             },
    "Mars": {"Sun": [3, 5, 6, 10, 11],
             "Moon": [3, 6, 11],
             "Mars": [1, 2, 4, 7, 8, 10, 11],
             "Mercury": [3, 5, 6, 11],
             "Jupiter": [6, 10, 11, 12],
             "Venus": [6, 8, 11, 12],
             "Saturn": [1, 4, 7, 8, 9, 10, 11],
             "Ascendant": [1, 3, 6, 10, 11]
             },
    "Mercury": {"Sun": [5, 6, 9, 11, 12],
                "Moon": [2, 4, 6, 8, 10, 11],
                "Mars": [1, 2, 4, 7, 8, 9, 10, 11],
                "Mercury": [1, 3, 5, 6, 9, 10, 11, 12],
                "Jupiter": [6, 8, 11, 12],
                "Venus": [1, 2, 3, 4, 5, 8, 9, 11],
                "Saturn": [1, 2, 4, 7, 8, 9, 10, 11],
                "Ascendant": [1, 2, 4, 6, 8, 10, 11]
                },
    "Jupiter": {"Sun": [1, 2, 3, 4, 7, 8, 9, 10, 11],
                "Moon": [2, 5, 7, 9, 11],
                "Mars": [1, 2, 4, 7, 8, 10, 11],
                "Mercury": [1, 2, 4, 5, 6, 9, 10, 11],
                "Jupiter": [1, 2, 3, 4, 7, 8, 10, 11],
                "Venus": [2, 5, 6, 9, 10, 11],
                "Saturn": [3, 5, 6, 12],
                "Ascendant": [1, 2, 4, 5, 6, 7, 9, 10, 11]
                },
    "Venus": {"Sun": [8, 11, 12],
              "Moon": [1, 2, 3, 4, 5, 8, 9, 11, 12],
              "Mars": [3, 5, 6, 9, 11, 12],
              "Mercury": [3, 5, 6, 9, 11],
              "Jupiter": [5, 8, 9, 10, 11],
              "Venus": [1, 2, 3, 4, 5, 8, 9, 10, 11],
              "Saturn": [3, 4, 5, 8, 9, 10, 11],
              "Ascendant": [1, 2, 3, 4, 5, 8, 9, 11]
              },
    "Saturn": {"Sun": [1, 2, 4, 7, 8, 10, 11],
               "Moon": [3, 6, 11],
               "Mars": [3, 5, 6, 10, 11, 12],
               "Mercury": [6, 8, 9, 10, 11, 12],
               "Jupiter": [5, 6, 11, 12],
               "Venus": [6, 11, 12],
               "Saturn": [3, 5, 6, 11],
               "Ascendant": [1, 3, 4, 6, 10, 11]
               }
}


def compute_AshtakaVargas():
    BhinnaAshtakaVargaPoints = {"Sun": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                "Moon": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                "Mars": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                "Mercury": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                "Jupiter": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                "Venus": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                "Saturn": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                "Ascendant": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                "Total": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
                                }
    rashi_house_mapping = {
        k: None for k in range(1, 13)
    }
    house_rashi_mapping = {
        k: None for k in range(1, 13)
    }
    D1 = data.charts["D1"]
    for house in D1['houses']:
        rashi_house_mapping[house['sign-num']] = house['house-num']
        house_rashi_mapping[house['house-num']] = house['sign-num']
    for planet in BAV_BinduMatrix:
        planet_BAV_points = BhinnaAshtakaVargaPoints[planet]
        for refPlanet in BAV_BinduMatrix[planet]:
            refplanet_housenum = None
            if (refPlanet == "Ascendant"):
                refplanet_housenum = 1
            else:
                refplanet_housenum = data.charts["D1"]["planets"][refPlanet]["house-num"]

            for nth in BAV_BinduMatrix[planet][refPlanet]:
                index = gen.compute_nthsign(refplanet_housenum, nth)
                sign_index = house_rashi_mapping[index] - 1
                planet_BAV_points[sign_index] += 1
    for rashi_num in range(12):
        BhinnaAshtakaVargaPoints["Total"][rashi_num] = (BhinnaAshtakaVargaPoints["Sun"][rashi_num] +
                                                        BhinnaAshtakaVargaPoints["Moon"][rashi_num] +
                                                        BhinnaAshtakaVargaPoints["Mars"][rashi_num] +
                                                        BhinnaAshtakaVargaPoints["Mercury"][rashi_num] +
                                                        BhinnaAshtakaVargaPoints["Jupiter"][rashi_num] +
                                                        BhinnaAshtakaVargaPoints["Venus"][rashi_num] +
                                                        BhinnaAshtakaVargaPoints["Saturn"][rashi_num])
    data.charts["AshtakaVarga"] = BhinnaAshtakaVargaPoints.copy()
    return


if __name__ == '__main__':
    compute_AshtakaVargas()
