Skip to content

Optimizations : how Sensor, PreAmplifier, DataLogger, Equipments are resolved

Perhaps initialise an dict containing each of the type of equipments in a private field ? : https://docs.pydantic.dev/latest/concepts/models/#private-model-attributes

Have something like this :

    @staticmethod
    def resolve_equipment_list(obj: Epoch) -> dict:
        """
        Preprocess equipments so that resolve_{sensor|preamp|etc} will
        be able to pick only what's necessary
        """
        sensor = pre_amplifier = data_logger = None
        others = []
        for installation in obj.equipments.all():
            match installation.equipment.equipment_type:
                case EquipmentType.OTHER:
                    others.append(installation)
                case EquipmentType.SENSOR:
                    sensor = installation
                case EquipmentType.PREAMPLIFIER:
                    pre_amplifier = installation
                case EquipmentType.DATALOGGER:
                    data_logger = installation
        return {
            "sensor": sensor,
            "pre_amplifier": pre_amplifier,
            "data_logger": data_logger,
            "others": others,
        }
Edited by Simon Panay
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information