db_query / utils /azimuth_validation.py
DavMelchi's picture
Update Physical DB after azimuth validation
68d7c9d
import pandas as pd
from utils.convert_to_excel import save_dataframe
url = r"./physical_db/physical_database.csv"
df = pd.read_csv(url)
def validate_azimuth(group):
"""
Validates the azimuth ordering within a group.
This function checks if the azimuth values are strictly increasing when there are exactly three values.
To make sure that Sector 3 is higher than Sector 2 and Sector 2 is higher than Sector 1
Args:
group (pd.DataFrame): A DataFrame group containing an 'Azimut' column.
Returns:
bool: True if the azimuth values are strictly increasing when there are exactly three values, False otherwise.
"""
azimuths = group.get("Azimut", []).values
if len(azimuths) == 3 and not (azimuths[0] < azimuths[1] < azimuths[2]):
return False
return True
# Apply validation per 'code'
azimut_verification = df.groupby("CODE").apply(lambda x: validate_azimuth(x))
df["Azimut_verification"] = df["CODE"].map(azimut_verification)
save_dataframe(df, "azimut_verification")
# print(df)