kerykeion.aspects.aspects_utils

This is part of Kerykeion (C) 2024 Giacomo Battaglia

  1# -*- coding: utf-8 -*-
  2"""
  3    This is part of Kerykeion (C) 2024 Giacomo Battaglia
  4"""
  5# TODO: Better documentation and unit tests
  6
  7from kerykeion import AstrologicalSubject
  8from kerykeion.settings import KerykeionSettingsModel
  9from swisseph import difdeg2n
 10from typing import Union
 11
 12
 13def get_aspect_from_two_points(aspects_settings: dict, point_one: Union[float, int], point_two: Union[float, int]):
 14    """
 15    Utility function.
 16    It calculates the aspects between the 2 points.
 17    Args: first point, second point.
 18    """
 19
 20    distance = abs(difdeg2n(point_one, point_two))
 21    diff = abs(point_one - point_two)
 22
 23    if int(distance) <= aspects_settings[0]["orb"]:
 24        name = aspects_settings[0]["name"]
 25        aspect_degrees = aspects_settings[0]["degree"]
 26        verdict = True
 27        aid = 0
 28
 29    elif (
 30        (aspects_settings[1]["degree"] - aspects_settings[1]["orb"])
 31        <= int(distance)
 32        <= (aspects_settings[1]["degree"] + aspects_settings[1]["orb"])
 33    ):
 34        name = aspects_settings[1]["name"]
 35        aspect_degrees = aspects_settings[1]["degree"]
 36        verdict = True
 37        aid = 1
 38
 39    elif (
 40        (aspects_settings[2]["degree"] - aspects_settings[2]["orb"])
 41        <= int(distance)
 42        <= (aspects_settings[2]["degree"] + aspects_settings[2]["orb"])
 43    ):
 44        name = aspects_settings[2]["name"]
 45        aspect_degrees = aspects_settings[2]["degree"]
 46        verdict = True
 47        aid = 2
 48
 49    elif (
 50        (aspects_settings[3]["degree"] - aspects_settings[3]["orb"])
 51        <= int(distance)
 52        <= (aspects_settings[3]["degree"] + aspects_settings[3]["orb"])
 53    ):
 54        name = aspects_settings[3]["name"]
 55        aspect_degrees = aspects_settings[3]["degree"]
 56        verdict = True
 57        aid = 3
 58
 59    elif (
 60        (aspects_settings[4]["degree"] - aspects_settings[4]["orb"])
 61        <= int(distance)
 62        <= (aspects_settings[4]["degree"] + aspects_settings[4]["orb"])
 63    ):
 64        name = aspects_settings[4]["name"]
 65        aspect_degrees = aspects_settings[4]["degree"]
 66        verdict = True
 67        aid = 4
 68
 69    elif (
 70        (aspects_settings[5]["degree"] - aspects_settings[5]["orb"])
 71        <= int(distance)
 72        <= (aspects_settings[5]["degree"] + aspects_settings[5]["orb"])
 73    ):
 74        name = aspects_settings[5]["name"]
 75        aspect_degrees = aspects_settings[5]["degree"]
 76        verdict = True
 77        aid = 5
 78
 79    elif (
 80        (aspects_settings[6]["degree"] - aspects_settings[6]["orb"])
 81        <= int(distance)
 82        <= (aspects_settings[6]["degree"] + aspects_settings[6]["orb"])
 83    ):
 84        name = aspects_settings[6]["name"]
 85        aspect_degrees = aspects_settings[6]["degree"]
 86        verdict = True
 87        aid = 6
 88
 89    elif (
 90        (aspects_settings[7]["degree"] - aspects_settings[7]["orb"])
 91        <= int(distance)
 92        <= (aspects_settings[7]["degree"] + aspects_settings[7]["orb"])
 93    ):
 94        name = aspects_settings[7]["name"]
 95        aspect_degrees = aspects_settings[7]["degree"]
 96        verdict = True
 97        aid = 7
 98
 99    elif (
100        (aspects_settings[8]["degree"] - aspects_settings[8]["orb"])
101        <= int(distance)
102        <= (aspects_settings[8]["degree"] + aspects_settings[8]["orb"])
103    ):
104        name = aspects_settings[8]["name"]
105        aspect_degrees = aspects_settings[8]["degree"]
106        verdict = True
107        aid = 8
108
109    elif (
110        (aspects_settings[9]["degree"] - aspects_settings[9]["orb"])
111        <= int(distance)
112        <= (aspects_settings[9]["degree"] + aspects_settings[9]["orb"])
113    ):
114        name = aspects_settings[9]["name"]
115        aspect_degrees = aspects_settings[9]["degree"]
116        verdict = True
117        aid = 9
118
119    elif (
120        (aspects_settings[10]["degree"] - aspects_settings[10]["orb"])
121        <= int(distance)
122        <= (aspects_settings[10]["degree"] + aspects_settings[10]["orb"])
123    ):
124        name = aspects_settings[10]["name"]
125        aspect_degrees = aspects_settings[10]["degree"]
126        verdict = True
127        aid = 10
128
129    else:
130        verdict = False
131        name = None
132        distance = 0
133        aspect_degrees = 0
134        color = None
135        aid = None
136
137    return (
138        verdict,
139        name,
140        distance - aspect_degrees,
141        aspect_degrees,
142        aid,
143        diff,
144    )
145
146
147def planet_id_decoder(planets_settings: dict, name: str):
148    """
149    Check if the name of the planet is the same in the settings and return
150    the correct id for the planet.
151    """
152    str_name = str(name)
153    for planet in planets_settings:
154        if planet["name"] == str_name:
155            result = planet["id"]
156            return result
157
158
159def get_active_points_list(subject: AstrologicalSubject, settings: Union[KerykeionSettingsModel, dict]) -> list:
160    """
161    Given an astrological subject and the settings, return a list of the active points.
162    Args:
163        subject (AstrologicalSubject): The astrological subject to get the active points from.
164        settings (Union[KerykeionSettingsModel, dict]): Settings model o dictionary.
165
166    Returns:
167        list: List of the active points.
168    """
169    point_list = []
170    for planet in settings["celestial_points"]:
171        if planet["is_active"] == True:
172            point_list.append(subject[planet["name"].lower()])
173
174    return point_list
def get_aspect_from_two_points( aspects_settings: dict, point_one: Union[float, int], point_two: Union[float, int]):
 14def get_aspect_from_two_points(aspects_settings: dict, point_one: Union[float, int], point_two: Union[float, int]):
 15    """
 16    Utility function.
 17    It calculates the aspects between the 2 points.
 18    Args: first point, second point.
 19    """
 20
 21    distance = abs(difdeg2n(point_one, point_two))
 22    diff = abs(point_one - point_two)
 23
 24    if int(distance) <= aspects_settings[0]["orb"]:
 25        name = aspects_settings[0]["name"]
 26        aspect_degrees = aspects_settings[0]["degree"]
 27        verdict = True
 28        aid = 0
 29
 30    elif (
 31        (aspects_settings[1]["degree"] - aspects_settings[1]["orb"])
 32        <= int(distance)
 33        <= (aspects_settings[1]["degree"] + aspects_settings[1]["orb"])
 34    ):
 35        name = aspects_settings[1]["name"]
 36        aspect_degrees = aspects_settings[1]["degree"]
 37        verdict = True
 38        aid = 1
 39
 40    elif (
 41        (aspects_settings[2]["degree"] - aspects_settings[2]["orb"])
 42        <= int(distance)
 43        <= (aspects_settings[2]["degree"] + aspects_settings[2]["orb"])
 44    ):
 45        name = aspects_settings[2]["name"]
 46        aspect_degrees = aspects_settings[2]["degree"]
 47        verdict = True
 48        aid = 2
 49
 50    elif (
 51        (aspects_settings[3]["degree"] - aspects_settings[3]["orb"])
 52        <= int(distance)
 53        <= (aspects_settings[3]["degree"] + aspects_settings[3]["orb"])
 54    ):
 55        name = aspects_settings[3]["name"]
 56        aspect_degrees = aspects_settings[3]["degree"]
 57        verdict = True
 58        aid = 3
 59
 60    elif (
 61        (aspects_settings[4]["degree"] - aspects_settings[4]["orb"])
 62        <= int(distance)
 63        <= (aspects_settings[4]["degree"] + aspects_settings[4]["orb"])
 64    ):
 65        name = aspects_settings[4]["name"]
 66        aspect_degrees = aspects_settings[4]["degree"]
 67        verdict = True
 68        aid = 4
 69
 70    elif (
 71        (aspects_settings[5]["degree"] - aspects_settings[5]["orb"])
 72        <= int(distance)
 73        <= (aspects_settings[5]["degree"] + aspects_settings[5]["orb"])
 74    ):
 75        name = aspects_settings[5]["name"]
 76        aspect_degrees = aspects_settings[5]["degree"]
 77        verdict = True
 78        aid = 5
 79
 80    elif (
 81        (aspects_settings[6]["degree"] - aspects_settings[6]["orb"])
 82        <= int(distance)
 83        <= (aspects_settings[6]["degree"] + aspects_settings[6]["orb"])
 84    ):
 85        name = aspects_settings[6]["name"]
 86        aspect_degrees = aspects_settings[6]["degree"]
 87        verdict = True
 88        aid = 6
 89
 90    elif (
 91        (aspects_settings[7]["degree"] - aspects_settings[7]["orb"])
 92        <= int(distance)
 93        <= (aspects_settings[7]["degree"] + aspects_settings[7]["orb"])
 94    ):
 95        name = aspects_settings[7]["name"]
 96        aspect_degrees = aspects_settings[7]["degree"]
 97        verdict = True
 98        aid = 7
 99
100    elif (
101        (aspects_settings[8]["degree"] - aspects_settings[8]["orb"])
102        <= int(distance)
103        <= (aspects_settings[8]["degree"] + aspects_settings[8]["orb"])
104    ):
105        name = aspects_settings[8]["name"]
106        aspect_degrees = aspects_settings[8]["degree"]
107        verdict = True
108        aid = 8
109
110    elif (
111        (aspects_settings[9]["degree"] - aspects_settings[9]["orb"])
112        <= int(distance)
113        <= (aspects_settings[9]["degree"] + aspects_settings[9]["orb"])
114    ):
115        name = aspects_settings[9]["name"]
116        aspect_degrees = aspects_settings[9]["degree"]
117        verdict = True
118        aid = 9
119
120    elif (
121        (aspects_settings[10]["degree"] - aspects_settings[10]["orb"])
122        <= int(distance)
123        <= (aspects_settings[10]["degree"] + aspects_settings[10]["orb"])
124    ):
125        name = aspects_settings[10]["name"]
126        aspect_degrees = aspects_settings[10]["degree"]
127        verdict = True
128        aid = 10
129
130    else:
131        verdict = False
132        name = None
133        distance = 0
134        aspect_degrees = 0
135        color = None
136        aid = None
137
138    return (
139        verdict,
140        name,
141        distance - aspect_degrees,
142        aspect_degrees,
143        aid,
144        diff,
145    )

Utility function. It calculates the aspects between the 2 points. Args: first point, second point.

def planet_id_decoder(planets_settings: dict, name: str):
148def planet_id_decoder(planets_settings: dict, name: str):
149    """
150    Check if the name of the planet is the same in the settings and return
151    the correct id for the planet.
152    """
153    str_name = str(name)
154    for planet in planets_settings:
155        if planet["name"] == str_name:
156            result = planet["id"]
157            return result

Check if the name of the planet is the same in the settings and return the correct id for the planet.

def get_active_points_list( subject: kerykeion.astrological_subject.AstrologicalSubject, settings: Union[kerykeion.kr_types.settings_models.KerykeionSettingsModel, dict]) -> list:
160def get_active_points_list(subject: AstrologicalSubject, settings: Union[KerykeionSettingsModel, dict]) -> list:
161    """
162    Given an astrological subject and the settings, return a list of the active points.
163    Args:
164        subject (AstrologicalSubject): The astrological subject to get the active points from.
165        settings (Union[KerykeionSettingsModel, dict]): Settings model o dictionary.
166
167    Returns:
168        list: List of the active points.
169    """
170    point_list = []
171    for planet in settings["celestial_points"]:
172        if planet["is_active"] == True:
173            point_list.append(subject[planet["name"].lower()])
174
175    return point_list

Given an astrological subject and the settings, return a list of the active points. Args: subject (AstrologicalSubject): The astrological subject to get the active points from. settings (Union[KerykeionSettingsModel, dict]): Settings model o dictionary.

Returns: list: List of the active points.