def get_usable_parameters(self): """ Use the `key` set for the table to determine the database and group of the activity, using that information to constrain the usable parameters. """ project = ([k, v, "project"] for k, v in ProjectParameter.static().items()) if self.key is None: return project database = ([k, v, "database"] for k, v in DatabaseParameter.static(self.key[0]).items()) # Determine if the activity is already part of a parameter group. query = (Group.select().join( ActivityParameter, on=(Group.name == ActivityParameter.group)).where( ActivityParameter.database == self.key[0], ActivityParameter.code == self.key[1]).distinct()) if query.exists(): group = query.get() # First, build a list for parameters in the same group activity = ([p.name, p.amount, "activity"] for p in ActivityParameter.select().where( ActivityParameter.group == group.name)) # Then extend the list with parameters from groups in the `order` # field additions = ([p.name, p.amount, "activity"] for p in ActivityParameter.select().where( ActivityParameter.group << group.order)) activity = itertools.chain(activity, additions) else: activity = [] return itertools.chain(project, database, activity)
def get_interpreter(self) -> Interpreter: """ Use the activity key to determine which symbols are added to the formula interpreter. """ interpreter = Interpreter() act = ActivityParameter.get_or_none(database=self.key[0], code=self.key[1]) if act: interpreter.symtable.update( ActivityParameter.static(act.group, full=True)) else: print("No parameter found for {}, creating one on formula save". format(self.key)) interpreter.symtable.update(ProjectParameter.static()) interpreter.symtable.update(DatabaseParameter.static(self.key[0])) return interpreter
def get_interpreter() -> Interpreter: interpreter = Interpreter() interpreter.symtable.update(ProjectParameter.static()) return interpreter
def get_usable_parameters(): return ([k, v, "project"] for k, v in ProjectParameter.static().items())