Mongo
client_default: MongoClient = MongoClient(‘mongodb://localhost:27017/’) db_default = client_default[‘eos’] db_config_default = db_config_servers_by_name[“default”]
MongoPool
MongoPool (_cnt:int=0, meta:tspace.data.core.ObservationMeta, db_config:tspace.config.db.DBConfig, doc_query:dict=<factory>, codec_option:bson.codec_options.CodecOptions, query:Optional[tspace.data.core.PoolQuery]=None, coll_name:Optional[str]=None, collection:Optional[pymongo.collection.Collection]=None, client:Optional[pymongo.mongo_client.MongoClient]=None, logger:Optional[logging.Logger]=None, dict_logger:Optional[dict]=None)
*A MongoDB store for storing data in a time series collection.
features:
timeseries interfacing pandas.DataFrame
multikey index for fast query
typed hints
The key leads to a config with db_name and collection name with a switch for record or episode.
Attributes:
- meta: ObservationMeta, meta information of the observation
- db_config: DBConfig, database configuration
- doc_query: dict, query dict for mongodb
- codec_option: CodecOptions, codec options for mongodb
- query: PoolQuery, query for mongodb
- coll_name: str, collection name
- collection: Collection, collection for mongodb
- client: MongoClient, client for mongodb
- logger: logging.Logger, logger for mongodb
- dict_logger: dict, dict for logging*
MongoPool.__post_init__
MongoPool.__post_init__ ()
User weakref finalizer to make sure close is called when the object is destroyed
MongoPool.load
MongoPool.load ()
*Initialize the pool interface
This function should: - connect to db - init*
MongoPool.find_item
MongoPool.find_item (doc_id:int)
Find a record by id.
MongoPool.close
MongoPool.close ()
close the pool, for destructor
MongoPool.parse_query
MongoPool.parse_query (query:tspace.data.core.PoolQuery)
One-Trick Pony: check query is valid or not return dict as mongo document query filter if query is None, return empty dict
MongoPool.store_record
MongoPool.store_record (episode:pandas.core.frame.DataFrame)
Deposit the records of an episode into the db.
MongoPool.store_episode
MongoPool.store_episode (episode:pandas.core.frame.DataFrame)
Deposit a DataFrame of an episode into the db.
MongoPool.store
MongoPool.store (episode:pandas.core.frame.DataFrame)
*Deposit the records of an episode into the db.
Based on the type of the db collection, store the episode as a set of records or as a complete episode.*
MongoPool.find
MongoPool.find (query:tspace.data.core.PoolQuery)
Find records by a query object.
MongoPool.delete
MongoPool.delete (item_id)
Delete a record by item id.
MongoPool._count
MongoPool._count (query:Optional[tspace.data.core.PoolQuery]=None)
*Count the number of records in the db.
for episode/record document*
MongoPool.sample
MongoPool.sample (size:int=4, query:Optional[tspace.data.core.PoolQuery]=None)
*Sample a batch of records from the db.
db.hyperparameters_collection.aggregate([ {“\(match": {"start_time": {"\)exists”: False}}}, {“$sample”: {“size”: 1}}])
if PoolQuery doesn’t contain ‘timestamp_start’ and ‘timestamp_end’, the full episode is retrieved.*
Type | Default | Details | |
---|---|---|---|
size | int | 4 | batch size, default 4 |
query | Optional[PoolQuery] | None | |
Returns | Optional[pd.DataFrame] | samples as one multi-indexed Pandas DataFrame |