def getExperimentInformationById(self, experimentid): dao = ExperimentDAO() result = dao.getExperimentInformationById(experimentid) if result is None: return jsonify(Error="Experiment doesn't exist!") else: result_map = self.build_experiment_dict(result) return jsonify(Users=result_map)
def getAllMeasurementsFromExperimentById(self, experimentid): dao = ExperimentDAO() measurements_list = dao.getAllMeasurementsFromExperimentById(experimentid) result_map = [] for row in measurements_list: result = self.build_measurement_dict(row) result_map.append(result) return jsonify(Measurements=result_map)
def getAllExperiments(self): dao = ExperimentDAO() experiment_list = dao.getAllExperiments() if experiment_list: result_map = [] for row in experiment_list: result = self.build_experiment_dict(row) result_map.append(result) return jsonify(Experiments=result_map) else: return jsonify(Error="No experiments to show.")
def deleteAllMeasurementsFromExperimentById(self, experimentid): dao = ExperimentDAO() if not dao.getExperimentInformationById(experimentid): return jsonify(Error="Experiment not found."), 404 elif not dao.getAllMeasurementsFromExperimentById(experimentid): return jsonify(Error="No measurements found."), 404 else: if dao.getAllPressurePointsFromMeasurementById(experimentid): dao.deleteAllPressurePointsFromMeasurementById(experimentid) if dao.getAllMeasurementsFromExperimentById(experimentid): dao.deleteAllMeasurementsFromExperimentById(experimentid) return jsonify(DeleteStatus="OK"), 200
def deleteAllExperimentsFromUserById(self, userid): dao = ResearcherDAO() if not dao.getUserInformationById(userid): return jsonify(Error="User not found."), 404 elif not dao.getAllExperimentsFromUserById(userid): return jsonify(Error="No experiments found for this user."), 404 else: if dao.getAllExperimentsFromUserById(userid): experiment_table = dao.getAllExperimentsFromUserById(userid) dao2 = ExperimentDAO() for experiment in experiment_table: dao2.deleteExperimentById(experiment[0]) return jsonify(DeleteStatus="OK"), 200
def storeMeasurementFromExperimentById(self, experimentid, form): dao = ExperimentDAO() if len(form) != 8: return jsonify(Error="Malformed post request"), 400 else: eid = experimentid liftforce = form['liftforce'] dragfrontforce = form['dragfrontforce'] dragbackforce = form['dragbackforce'] leftsideforce = form['leftsideforce'] rightsideforce = form['rightsideforce'] windspeed = form['windspeed'] temperature = form['temperature'] humidity = form['humidity'] if eid and liftforce and dragfrontforce and dragbackforce and leftsideforce and rightsideforce and windspeed and temperature and humidity: mid = dao.storeMeasurementFromExperimentById(eid, liftforce, dragfrontforce, dragbackforce, leftsideforce, rightsideforce, windspeed, temperature, humidity) result = self.build_measurement_attributes(mid, liftforce, dragfrontforce, dragbackforce, leftsideforce, rightsideforce, windspeed, temperature, humidity, eid) return jsonify(Measurement=result), 200 else: return jsonify(Error="Unexpected attributes in post request"), 400