41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Self, Any, TypeVar
|
|
from Interfaces.Application.NucelarMonitorInterface import NucelarMonitorInterface
|
|
|
|
T = TypeVar('T')
|
|
|
|
class ModelsManager:
|
|
|
|
def __init__(self:Self, nucelar_monitor:NucelarMonitorInterface) -> None:
|
|
self.nucelar_monitor:NucelarMonitorInterface = nucelar_monitor
|
|
|
|
key:str
|
|
|
|
self.__models:dict[str, Any] = {}
|
|
|
|
for key in (
|
|
"default_models_files", "models_files",
|
|
"default_models", "models"
|
|
):
|
|
self.add(self.nucelar_monitor.settings.get(key, None, []), True)
|
|
|
|
def get(self:Self, Type:type[T], key:str) -> type[T]|None:
|
|
return self.__models.get(key, None) if key in self.__models and issubclass(self.__models[key], Type) else None
|
|
|
|
def add(self:Self,
|
|
inputs:dict[str, Any]|list[Any|None]|tuple[Any|None, ...]|str,
|
|
overwrite:bool = False
|
|
) -> None:
|
|
|
|
subinputs:dict[str, Any]
|
|
|
|
for subinputs in self.nucelar_monitor.files.load_json(inputs):
|
|
|
|
key:str
|
|
Model:type[T]
|
|
|
|
for key, Model in subinputs.items():
|
|
if overwrite or key not in self.__models:
|
|
self.__models[key] = Model |