def get_user_normalized_data_in_range( user_id: ObjectId, start_date: dt = None, end_date: dt = None) -> Generator[BaseData, None, None]: query = {"user_id": user_id} if start_date or end_date: query["date"] = {} if start_date: query["date"]["$gte"] = start_date if end_date: query["date"]["$lt"] = end_date raw_data_results = mongo_crud_wrapper.get_by_query(COLLECTION_NAME, query) return (NormalizedData.from_doc(result) for result in raw_data_results)
def get_bulk_by_user(user_id: ObjectId) -> Generator[BaseData, None, None]: query = {"user_id": user_id} raw_data_results = mongo_crud_wrapper.get_by_query(COLLECTION_NAME, query) return (NormalizedData.from_doc(result) for result in raw_data_results)
def create(raw_data: NormalizedData) -> BaseData: raw_data_doc = raw_data.to_doc() mongo_crud_wrapper.create(COLLECTION_NAME, raw_data_doc) return NormalizedData.from_doc(raw_data_doc)
def get(raw_data_id: ObjectId) -> BaseData: raw_data_id_doc = mongo_crud_wrapper.get(COLLECTION_NAME, raw_data_id) return NormalizedData.from_doc(raw_data_id_doc)
def test_get_doc(normalized_data: NormalizedData, object_id): normalized_data.uid = object_id normalized_data_doc = normalized_data.to_doc() data_obj = NormalizedData.from_doc(normalized_data_doc) assert data_obj == normalized_data