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 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): import numpy snaps = [] amp = 100 fs = 20 uuid = ObjectId('57ed3f20e0034625e8fa61f1') dict = [ {'x': int(amp*numpy.sin (2*numpy.pi*r/fs)), 'y': int(amp*numpy.sin (2*numpy.pi*r/fs)), 'z': int(amp*numpy.sin (2*numpy.pi*r/fs)), 't': r, '_id': uuid } for r in range(1, fs)] schema = schemas.Sensor(many=True) result, _ = schema.load(dict) mongo.db.accelerometres.insert(result)