Spaces:
Sleeping
Sleeping
File size: 1,344 Bytes
90de23d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import logging
import pprint
from enum import Enum
from math import acos, cos, radians, sin
import yaml
def parse_configs(configs_path: str) -> dict:
"""Parse configs from the YAML file.
Args:
configs_path (str): Path to the YAML file
Returns:
dict: Parsed configs
"""
configs = yaml.safe_load(open(configs_path, "r"))
logger.info(f"Configs: {pprint.pformat(configs)}")
return configs
def get_distance(source_country: list[float], target_country: list[float]) -> float:
"""Calculate the distance between two countries.
Args:
source_country (list[float]): Source country coordinates
target_country (list[float]): Target country coordinates
Returns:
float: Distance in KM
"""
source_lat = radians(source_country[0])
source_long = radians(source_country[1])
target_lat = radians(target_country[0])
target_long = radians(target_country[1])
dist = 6371.01 * acos(
sin(source_lat) * sin(target_lat)
+ cos(source_lat) * cos(target_lat) * cos(source_long - target_long)
)
return dist
class HintType(Enum):
AUDIO = "Audio"
TEXT = "Text"
IMAGE = "Image"
CONFIGS_PATH = "configs.yaml"
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__file__)
configs = parse_configs(CONFIGS_PATH)
|