def get(self): uuid = request.args.get('uuid') if uuid is None: abort(401,message='enter valid uuid') return schema = schemas.Record() record,errors = schema.dump(mongo.db.record.find_one({'_id': ObjectId(uuid)})) #if errors: # abort(401, message=str(errors)) #-------------------------------------------------------------- schema = schemas.Sensor(many=True) accelerometres,errors = schema.dump(mongo.db.accelerometres.find({'ref': ObjectId(uuid)})) if errors: abort(401, message=str(errors)) #-------------------------------------------------------------- schema = schemas.Sensor(many=True) magnetometres,errors = schema.dump(mongo.db.magnetometres.find({'ref': ObjectId(uuid)})) if errors: abort(401, message=str(errors)) #-------------------------------------------------------------- schema = schemas.Sensor(many=True) gyrometres,errors = schema.dump(mongo.db.gyrometres.find({'ref': ObjectId(uuid)})) if errors: abort(401, message=str(errors)) #-------------------------------------------------------------- schema = schemas.RecordRequest() result,errors = schema.load(dict([('record', record), ('accelerometres', accelerometres), ('magnetometres', magnetometres), ('gyrometres',gyrometres)])) #if errors: #abort(401, message=str(errors)) return result
def get(self): schemaDataRequestWithOptions = schemas.DataRequestWithOptions() dataRequestWithOptions, dataRequestWithOptionsErrors = schemaDataRequestWithOptions.load(request.json) if dataRequestWithOptionsErrors: abort(401, message=str(dataRequestWithOptionsErrors)) # Retrieve Filter timeFilterSchema = schemas.TimeFilter() timeFilterData, timeFilterErrors = timeFilterSchema.load(dataRequestWithOptions['timeFilter']) if timeFilterErrors: abort(401, message=str(timeFilterErrors)) # Retrieve Sort sortSchema = schemas.DataSort() sortData, sortErrors = sortSchema.load(dataRequestWithOptions['sort']) if sortErrors: abort(401, message=str(sortErrors)) # Retrieve UUID uuidData, uuidErrors = schemaDataRequestWithOptions.load(dataRequestWithOptions['recordId']) if uuidErrors: abort(401, message='enter valid uuid') return recordSchema = schemas.Record() # Build request # No filter, no sort. Just return all the record matching the UUID if (timeFilterData is None) & (sortData is None): return recordSchema.dump(mongo.db.record.find({}, {'name': 1, '_id': uuidData})) # Filter and Sort the record that matches the UUID if (timeFilterData is not None) & (sortData is not None): start = timeFilterData['beginDateTime'] end = timeFilterData['endDateTime'] if sortData['sortedDirection'] == 1: return recordSchema.dump( mongo.db.record.find({}, {'_id': uuidData, 'date':{'$lt': end, '$gte': start}}).sort(sortData['sortedColumn'], mongo.ASCENDING)) elif sortData['sortedDirection'] == 2: return recordSchema.dump( mongo.db.record.find({}, {'_id': uuidData, 'date':{'$lt': end, '$gte': start}}).sort(sortData['sortedColumn'], mongo.DESCENDING)) else: return recordSchema.dump(mongo.db.record.find({'_id': uuidData, 'date':{'$lt': end, '$gte': start}})) # Filter only the record that matches the UUID if (timeFilterData is not None) & (sortData is None): start = timeFilterData['beginDateTime'] end = timeFilterData['endDateTime'] return recordSchema.dump(mongo.db.record.find({'_id': uuidData, 'date':{'$lt': end, '$gte': start}})) # Sort only the record that matches the UUID if (timeFilterData is None) & (sortData is not None): if sortData['sortedDirection'] == 1: return recordSchema.dump(mongo.db.record.find({'_id': uuidData}).sort(sortData['sortedColumn'], mongo.ASCENDING)) elif sortData['sortedDirection'] == 2: return recordSchema.dump(mongo.db.record.find({'_id': uuidData}).sort(sortData['sortedColumn'], mongo.DESCENDING)) else: return recordSchema.dump(mongo.db.record.find({'_id': uuidData}))
def post(self,uuid): name = request.args.get('name') schema = schemas.Record() return schema.dump( mongo.db.record.find_one_and_update( {'_id': ObjectId(uuid)}, {'$set': {'name': name}}, return_document=ReturnDocument.AFTER) )
def post(self,uuid=None): schema = schemas.RecordRequest() data, errors = schema.load(request.json) if errors: abort(401, message=str(errors)) #--------------------------------------------------------------- if uuid is None: schema = schemas.Record() record,errors = schema.dump(data['record']) if errors: abort(401, message=str(errors)) if 'parent_id' in record: if(record['parent_id'] == "None"): del record['parent_id'] elif mongo.db.record.find_one({'_id': ObjectId(record['parent_id'])}) is None: abort(401, message="parent_id is invalid") try: uuid = str(mongo.db.record.insert(record)) except pyErr.DuplicateKeyError: abort(401, message="DuplicateKeyError") #--------------------------------------------------------------- if 'accelerometres' in data: schema = schemas.Sensor(many=True) accelerometres,errors = schema.dump(data['accelerometres']) if errors: abort(401, message=str(errors)) for datum in accelerometres: datum['ref'] = uuid mongo.db.accelerometres.insert(accelerometres) #--------------------------------------------------------------- if 'gyrometres' in data: schema = schemas.Sensor(many=True) gyrometres,errors = schema.dump(data['gyrometres']) if errors: abort(401, message=str(errors)) for datum in gyrometres: datum['ref'] = uuid mongo.db.gyrometres.insert(gyrometres) #--------------------------------------------------------------- if 'magnetometres' in data: schema = schemas.Sensor(many=True) magnetometres,errors = schema.dump(data['magnetometres']) if errors: abort(401, message=str(errors)) for datum in magnetometres: datum['ref'] = uuid mongo.db.magnetometres.insert(magnetometres) #--------------------------------------------------------------- jsonresult = dict(valeuruuid=uuid) schema = schemas.Uuid() return schema.dump(jsonresult)
def post(self): schema = schemas.RecordRequest() data, errors = schema.load(request.json) if errors: abort(401, message=str(errors)) #--------------------------------------------------------------- schema = schemas.Record() record,errors = schema.dump(data['record']) if errors: abort(401, message=str(errors)) uuid = mongo.db.record.insert(record) #--------------------------------------------------------------- schema = schemas.Sensor(many=True) accelerometres,errors = schema.dump(data['accelerometres']) if errors: abort(401, message=str(errors)) for datum in accelerometres: datum['ref'] = uuid mongo.db.accelerometres.insert(accelerometres) #--------------------------------------------------------------- schema = schemas.Sensor(many=True) gyrometres,errors = schema.dump(data['gyrometres']) if errors: abort(401, message=str(errors)) for datum in gyrometres: datum['ref'] = uuid mongo.db.gyrometres.insert(gyrometres) #--------------------------------------------------------------- schema = schemas.Sensor(many=True) magnetometres,errors = schema.dump(data['magnetometres']) if errors: abort(401, message=str(errors)) for datum in magnetometres: datum['ref'] = uuid mongo.db.magnetometres.insert(magnetometres) #--------------------------------------------------------------- return str(uuid)
def get(self): schema = schemas.Record(many=True) return schema.dump(mongo.db.record.find())