2022-01-23 13:45:56 +01:00
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
VALUES = ["low", "mid", "high"]
|
2022-01-15 17:40:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
def production_year_to_value(production_year):
|
|
|
|
return VALUES[["Dawno", "Średnio", "Niedawno"].index(production_year)]
|
|
|
|
|
2022-01-23 13:45:56 +01:00
|
|
|
|
2022-01-15 17:40:16 +01:00
|
|
|
def mileage_to_value(mileage):
|
|
|
|
return VALUES[["Niski", "Średni", "Duży"].index(mileage)]
|
|
|
|
|
2022-01-23 13:45:56 +01:00
|
|
|
|
2022-01-15 17:40:16 +01:00
|
|
|
def engine_capacity_to_value(engine_capacity):
|
|
|
|
return VALUES[["Mała", "Średnia", "Ogromna"].index(engine_capacity)]
|
|
|
|
|
2022-01-23 13:45:56 +01:00
|
|
|
|
2022-01-15 17:40:16 +01:00
|
|
|
def combustion_to_value(combustion):
|
|
|
|
return VALUES[["Niskie", "Średnie", "Wysokie"].index(combustion)]
|
|
|
|
|
|
|
|
|
|
|
|
def map_query_params(query_params):
|
|
|
|
values = {}
|
2022-01-23 13:45:56 +01:00
|
|
|
params = ["production_year", "mileage", "engine_capacity", "combustion"]
|
|
|
|
funcs = [
|
|
|
|
production_year_to_value,
|
|
|
|
mileage_to_value,
|
|
|
|
engine_capacity_to_value,
|
|
|
|
combustion_to_value,
|
|
|
|
]
|
2022-01-15 17:40:16 +01:00
|
|
|
for param, func in zip(params, funcs):
|
2022-01-23 13:45:56 +01:00
|
|
|
if query_param := query_params.get(param):
|
2022-01-15 17:40:16 +01:00
|
|
|
values[param] = func(query_param)
|
|
|
|
return values
|
2022-01-23 13:45:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
def set_settings_values(data):
|
|
|
|
settings.PRODUCTION_YEAR = get_values(data["production_year"])
|
|
|
|
settings.MILEAGE = get_values(data["mileage"])
|
|
|
|
settings.ENGINE_CAPACITY = get_values(data["engine_capacity"])
|
|
|
|
settings.COMBUSTION = get_values(data["combustion"])
|
|
|
|
settings.COMPARATOR = float(data["comparator"]["items"][0]["value"])
|
|
|
|
|
|
|
|
|
|
|
|
def get_values(label):
|
|
|
|
low = list(map(float, label["items"][0]["value"].split(",")))
|
|
|
|
mid = list(map(float, label["items"][1]["value"].split(",")))
|
|
|
|
high = list(map(float, label["items"][2]["value"].split(",")))
|
|
|
|
return {"low": low, "mid": mid, "high": high}
|