Beispiel #1
0
def db_open(file_name):
    rec = lib.Recorder(inject_sim_id=False)
    prefix, ext = os.path.splitext(file_name)
    if ext == '.h5':
        db = lib.Hdf5Back(file_name)
    elif ext == '.sqlite':
        db = lib.SqliteBack(file_name)
    else:
        raise ValueError('Unsupported file type')
    rec.register_backend(db)
    yield (rec, db)
    rec.flush()
    db.close()
    rec.close()
Beispiel #2
0
def agent_annotations_as_json(state, spec):
    """Returns the agent annotations as a JSON string."""
    if state.si is None:
        rec = lib.Recorder()
        ti = lib.Timer()
        ctx = lib.Context(ti, rec)
    else:
        ctx = state.si.context
    agent = lib.DynamicModule.make(ctx, spec)
    anno = agent.annotations
    writer = FastWriter()
    data = writer.write(anno)
    ctx.del_agent(agent)
    return data
Beispiel #3
0
    def __init__(self, db, write=True):
        """Parameters
        ----------
        db : database
        write : bool, optional
            Flag for whether metrics should be written to the database.

        Attributes
        ----------
        metrics : dict
            Metric instances bound the evaluator's database.
        rawcache : dict
            Results of querying metrics with given conditions.
        """
        self.write = write
        self.metrics = {}
        self.rawcache = {}
        self.db = db
        self.recorder = rec = lib.Recorder(inject_sim_id=False)
        rec.register_backend(db)
        self.known_tables = db.tables
Beispiel #4
0
def make_rec_back(inject_sim_id=False):
    """Makes a new recorder and backend."""
    rec = lib.Recorder(inject_sim_id=inject_sim_id)
    back = memback.MemBack()
    rec.register_backend(back)
    return rec, back