def _genmetricclass(f, name, depends, scheme): """Creates a new metric class with a given name, dependencies, and schema. Parameters ---------- name : str Metric name depends : list of lists (table name, tuple of indices, column name) Dependencies on other database tables (metrics or root metrics) scheme : list of tuples (column name, data type) Schema for metric """ if not isinstance(scheme, schemas.schema): scheme = schemas.schema(scheme) class Cls(Metric): dependencies = depends schema = scheme func = staticmethod(f) __doc__ = inspect.getdoc(f) def __init__(self, db): """Constructor for metric object in database.""" super(Cls, self).__init__(db) def __call__(self, frames, conds=None, known_tables=None, *args, **kwargs): """Computes metric for given input data and conditions.""" # FIXME test if I already exist in the db, read in if I do if known_tables is None: known_tables = self.db.tables() if self.name in known_tables: return self.db.query(self.name, conds=conds) return f(*frames) Cls.__name__ = str(name) register_metric(Cls) return Cls
count.name = 'Count' rtn = count.reset_index() return rtn del _dsdeps, _dsschema # Agents _agentsdeps = ['AgentEntry', 'AgentExit', 'DecomSchedule', 'Info'] _agentsschema = schemas.schema([ ('SimId', ts.UUID), ('AgentId', ts.INT), ('Kind', ts.STRING), ('Spec', ts.STRING), ('Prototype', ts.STRING), ('ParentId', ts.INT), ('Lifetime', ts.INT), ('EnterTime', ts.INT), ('ExitTime', ts.INT), ]) @metric(name='Agents', depends=_agentsdeps, schema=_agentsschema) def agents(entry, exit, decom, info): """Computes the Agents table. This is tricky because both the AgentExit table and the DecomSchedule table may not be present in the database. Furthermore, the Info table does not contain the AgentId column. This computation handles the calculation of the ExitTime in the face a significant amounts of missing data. """
count.name = 'Count' rtn = count.reset_index() return rtn del _dsdeps, _dsschema # Agents _agentsdeps = ['AgentEntry', 'AgentExit', 'DecomSchedule', 'Info'] _agentsschema = schemas.schema([ ('SimId', ts.UUID), ('AgentId', ts.INT), ('Kind', ts.STRING), ('Spec', ts.STRING), ('Prototype', ts.STRING), ('ParentId', ts.INT), ('Lifetime', ts.INT), ('EnterTime', ts.INT), ('ExitTime', ts.INT), ]) @metric(name='Agents', depends=_agentsdeps, schema=_agentsschema) def agents(entry, exit, decom, info): """Computes the Agents table. This is tricky because both the AgentExit table and the DecomSchedule table may not be present in the database. Furthermore, the Info table does not contain the AgentId column. This computation handles the calculation of the ExitTime in the face a significant amounts of missing data. """ mergeon = ['SimId', 'AgentId']