def create(cls, action): for klass in utils.all_subclasses(cls): if action.get('type', None) == klass.__name__: logger.info("Creating %s Animation", klass.__name__) return klass(action) logger.info("Defaulting to StaticAnimation for %s", action) return Static(action)
def CreateAction(action): """Function used to create a Action object from a json dictionary""" # Import this here to avoid cyclical dependencies.... # TODO: Fix these dependencies. from actions import Action for klass in utils.all_subclasses(Action): if action['type'] == klass.__name__: action['target'] = tuple(action['target']) return klass(**action) raise InvalidAction("%s is not a valid move." % json.dumps(action, indent=2))
from .base import AbstractDataset from utils import all_subclasses from utils import import_all_subclasses import_all_subclasses(__file__, __name__, AbstractDataset) DATASETS = {c.code():c for c in all_subclasses(AbstractDataset) if c.code() is not None} def dataset_factory(args): dataset = DATASETS[args.dataset_code] return dataset(args)
from .base import AbstractTrainer from utils import all_subclasses from utils import import_all_subclasses import_all_subclasses(__file__, __name__, AbstractTrainer) TRAINERS = { c.code(): c for c in all_subclasses(AbstractTrainer) if c.code() is not None } def trainer_factory(args, model, train_loader, val_loader, test_loader, export_root): trainer = TRAINERS[args.trainer_code] return trainer(args, model, train_loader, val_loader, test_loader, export_root)
from utils import all_subclasses from .asset import * from .base import BaseModel as _BaseModel from .campaign import * from .general import * from .groups import Group from .initiative import * from .label import * from .notifications import * from .shape import * from .signals import * from .user import * from .marker import * ALL_MODELS = [model for model in all_subclasses(_BaseModel)]
from utils import all_subclasses from .asset import * from .base import BaseModel as _BaseModel from .campaign import * from .general import * from .initiative import * from .label import * from .shape import * from .signals import * from .user import * from .marker import * ALL_MODELS = [ model for model in all_subclasses(_BaseModel) if not model.abstract ]
def loop_func(): files = os.listdir(absolutePath + r"\mods") modclass = all_subclasses(Mod) modclassname = [x.__name__ for x in modclass] # updates file in the \mods folder fileselect.menu("", files, mode="togg") modtype.menu("", modclassname, mode="sel") mod = currentMod.getcontent() if mod is None: modname.setval("NO MODULE LOADED") else: if modname.getval() == "NO MODULE LOADED": modname.setval(mod.name) elif modname.getval() != mod.name: # assigns ship name from input mod.name = modname.getval() def handleTank(): isValid = False tank = currentMod.getcontent() (pC, pS, pM, pLDR, eM, tDG) = tempElem.getcontent() content = materials[pC.getval()] structure = materials[pS.getval()] ldr = pLDR.getval() mass = pM.getval() warnings = "" if ldr > 0 and mass > 0 and structure.yieldstrength > 0: tank.set(content, mass * 1000, structure, ldr) modname.setval(tank.name) currentMod.setcontent(tank) warnings = "" isValid = True if mass <= 0: warnings += "!!Tank is empty!!\n" if ldr <= 0: warnings += "!!length/diameter is not valid!!\n" if structure.yieldstrength <= 0: warnings += "!!invalid structure!!\n" eM.graph(warnings) h = nan w = nan m = nan strm = nan if tank.h is not None: h = tank.h w = tank.w if tank.mass is not None: m = tank.mass if tank.strmass is not None: strm = tank.strmass diagram = " w = {:.1f}m".format(w) + "\n" diagram += " /-------\\" + "\n" diagram += " | |" + "\n" diagram += " | |" + "\n" diagram += " | |" + "h = {:.1f}m".format(h) + "\n" diagram += " | |" + "\n" diagram += " | |" + "\n" diagram += " \\-------/" + "\n" diagram += " mass {} t\n".format(m / 1000) tDG.graph(diagram) return isValid def handleEngine(): isValid = False engine = currentMod.getcontent() pT, pP, dG, eM = tempElem.getcontent() prop = mixtures[pP.getval()] thrust = pT.getval() if thrust > 0: engine.set(prop, thrust * 1000) modname.setval(engine.name) eM.clear() warnings = "" currentMod.setcontent(engine) isValid = True else: warnings = "!!Engine is not producing thrust!!" rad = engine.r if rad is None: rad = "!!invalid!!" else: rad = "r={:.1f}m".format(rad) engine_diagram = ( " /----\\" + "\n" + " | | {}".format(rad) + "\n" + " \\ /" + "\n" + " / \\" + "\n" + " / \\" + "\n" + " / \\" + "\n" ) if engine.propellant is not None: for prop in engine.propellant.composition: m_r = engine.propellant.mass_ratio_norm(prop) * engine.mdot p_n = prop.name engine_diagram += "{}:{:.2f}kg/s".format(p_n, m_r) + "\n" dG.graph(engine_diagram) eM.graph(warnings) return isValid def loadMod(): filedex = fileselect.getrigg() if filedex is not None: filepath = absolutePath + r"\mods\\" + str(files[filedex]) newMod = Ship.load(filepath) currentMod.setcontent(newMod) handleTemporary(newMod) updateDisplayed() else: "no file specified." def saveMod(): currentShipName = modname.getval() savepath = absolutePath + r"\mods\{}".format(currentShipName) (currentMod.getcontent()).save(savepath) def dontsave(): if currentMod.getcontent() is None: print("no module to save.") else: print("Module have errors.cannot save.") def newMod(): newMod = modclass[modtype.getval()]() currentMod.setcontent(newMod) handleTemporary(newMod) updateDisplayed() def delMod(): try: selected_name = files[fileselect.getrigg()] savepath = absolutePath + r"\mods\{}".format(selected_name) os.remove(savepath) except (IndexError, TypeError) as e: print("invalid selection. please select ship to delete first.") def handleTemporary(newMod): tpe = tempElem.getcontent() # delete all temporary element. just in case. if tpe is not None: editor.delete_element(*tpe) tempElem.setcontent(None) if isinstance(newMod, Engine): pT = editor.addelement("lu", h=0.1, w=0.24, type="value") pT.value("KN", pT.val, reversed=True) pP = editor.addelement("lu", h=0.8, w=0.24, type="menu") pP.menu(">", mixtureNames, mode="sel") dG = editor.addelement("lu", h=0.45, w=0.24) eM = editor.addelement("lu", h=0.45, w=0.24) (*tpe,) = (pT, pP, dG, eM) tempElem.setcontent(tpe) elif isinstance(newMod, Tank): pC = editor.addelement("lu", h=0.45, w=0.25, type="menu", t="Content") pC.menu(">", materialNames, mode="trig") pS = editor.addelement("lu", h=0.45, w=0.25, type="menu", t="Structure") pS.menu(">", materialNames, mode="trig") pM = editor.addelement("lu", h=0.1, w=0.25, type="value", t="mass") pM.value("t", pM.val, reversed=True) pM.bind("m") pLDR = editor.addelement("lu", h=0.1, w=0.25, type="value", t="L/D") pLDR.value("", pLDR.val) pLDR.bind("r") eM = editor.addelement("lu", h=0.2, w=0.25, t="Errors:") tDG = editor.addelement("lu", h=0.5, w=0.25, t="Diagram") (*tpe,) = (pC, pS, pM, pLDR, eM, tDG) tempElem.setcontent(tpe) def updateDisplayed(): return True load.button("LOAD", loadMod) new.button("NEW", newMod) delete.button("DEL", delMod) saving_valid = False mod = currentMod.getcontent() if tempElem.getcontent() is not None: if isinstance(mod, Engine): saving_valid = handleEngine() elif isinstance(mod, Tank): saving_valid = handleTank() if saving_valid: save.button("SAVE", saveMod) else: save.button(" ", dontsave)
def get_ranking_methods(cls): for r in all_subclasses(cls): if r not in (TournamentRanking, ): yield r
from utils import all_subclasses from .asset import * from .base import BaseModel as _BaseModel from .campaign import * from .general import * from .initiative import * from .label import * from .notifications import * from .shape import * from .signals import * from .user import * from .marker import * ALL_MODELS = [model for model in all_subclasses(_BaseModel) if not model.abstract]
from .base import BaseModel from utils import all_subclasses from utils import import_all_subclasses import_all_subclasses(__file__, __name__, BaseModel) MODELS = {c.code():c for c in all_subclasses(BaseModel) if c.code() is not None} def model_factory(args, num_items = None): model = MODELS[args.model_code] return model(args)
from .base import AbstractDataloader from datasets import dataset_factory from utils import all_subclasses from utils import import_all_subclasses import_all_subclasses(__file__, __name__, AbstractDataloader) DATALOADERS = { c.code(): c for c in all_subclasses(AbstractDataloader) if c.code() is not None } def dataloader_factory(args): dataset = dataset_factory(args) dataloader = DATALOADERS[args.dataloader_code] dataloader = dataloader(args, dataset) train, val, test = dataloader.get_pytorch_dataloaders() return train, val, test def get_dataloader(args): dataset = dataset_factory(args) dataloader = DATALOADERS[args.dataloader_code] dataloader = dataloader(args, dataset) return dataloader