import os
from typing import Dict

import django
from dotenv import load_dotenv

load_dotenv()
django.setup()

from netbox_sensors.models import Transducer


def run_normalization():
    guia: Dict = {
        "Altitude": "alt",
        "CO₂": "co2",
        "Latitude": "lat",
        "Longitude": "lon",
        "NOx": "nox",
        "P00013-Altitude": "alt",
        "P00013-PM1": "pm1",
        "P00013-PM2.5": "pm2",
        "P00013-PM4": "pm4",
        "P00014-Altitude": "alt",
        "P00014-PM1": "pm1",
        "P00014PM2.5": "pm2",
        "P00014-PM4": "pm4",
        "P00015-PM2.5": "pm2",
        "P00015-PM4": "pm4",
        "PM1": "pm1",
        "PM10": "pm10",
        "PM2.5": "pm2",
        "PM4": "pm4",
        "Relative humidity": "h",
        "Temperature": "t",
        "VOC": "voc",
    }

    transducers = Transducer.objects.all()
    for transducer in transducers:
        if transducer.name in list(guia):
            guia_key = transducer.name
            transducer.name = guia[guia_key]
            transducer.alias = guia_key
            transducer.save()
    pass


if __name__ == "__main__":
    run_normalization()
