def do_import_reco(file_path) -> Recommendation: reco_dataframe = pd.read_csv(file_path) total_reco = new_reco = 0 for row in reco_dataframe.itertuples(): if str(row.benefit) == 'nan': continue reco = Recommendation.query.get(row.id) if not reco: reco = Recommendation() reco.id = row.id new_reco += 1 reco.title = row.title if str(row.content) != 'nan': reco.content = row.content # TODO: temporary with set a default value else: reco.content = "Contenu non défini" if str(row.benefit) != 'nan': reco.benefit = row.benefit else: reco.benefit = 0.0 if str(row.benefit_description) != 'nan': reco.benefit_description = row.benefit_description if str(row.how_to) != 'nan': reco.how_to = row.how_to reco.type = FootprintType({'label': row.category}) total_reco += 1 BaseObject.check_and_save(reco) print('Recommendations updated : %s' % str(total_reco - new_reco)) print('Recommendations created : %s' % new_reco)
def test_get_propositions_should_return_highest_probability_reco_first(app): # Given obj_to_save = [] user = create_user(email='*****@*****.**', username='******', password='******') obj_to_save.append(user) recommendation_1 = create_recommendation(title='Prends ton vélo') recommendation_2 = create_recommendation(title='Prends ta trottinette') obj_to_save.append(recommendation_1) obj_to_save.append(recommendation_2) BaseObject.check_and_save(*obj_to_save) # When proposition_request = req_with_auth(email='*****@*****.**', password='******') \ .get(API_URL + '/propositions') # Then assert proposition_request.status_code == 200 content = proposition_request.json() assert len(content.get('propositions')) == 2 reco_1_probability = content.get('propositions')[0].get('probability') reco_2_probability = content.get('propositions')[1].get('probability') assert reco_1_probability >= reco_2_probability
def test_save_property_set_value_if_property_and_user_property_exist(app): # Given obj_to_save = [] user = create_user(email='*****@*****.**', username='******', password='******') obj_to_save.append(user) question = Question() question.question_name = 'question_1' obj_to_save.append(question) BaseObject.check_and_save(*obj_to_save) user_property_obj = UserProperty() user_property_obj.user_id = user.id user_property_obj.question_id = question.id user_property_obj.value = float(12) BaseObject.check_and_save(user_property_obj) data = dict() data['question_1'] = "0.5" # When property_request = req_with_auth(email='*****@*****.**', password='******') \ .post(API_URL + '/property', json=data) # Then assert property_request.status_code == 200 user_property_obj = UserProperty.query. \ filter_by(user_id=user.id). \ filter_by(question_id=question.id). \ first() assert user_property_obj is not None assert user_property_obj.value == 0.5
def create_task_quiz(user_id): content = request.json task_quiz = TaskQuiz() task_quiz.userID = str(content['userID']) task_quiz.date = str(content['date']) task_quiz.startTime = str(content['startTime']) task_quiz.quizTime = str(content['quizTime']) task_quiz.taskSession = str(content['taskSession']) task_quiz.taskSessionTry = str(content['taskSessionTry']) task_quiz.section = str(content['section']) task_quiz.quizQnNum = str(content['quizQnNum']) task_quiz.quizQnRT = str(content['quizQnRT']) task_quiz.quizStimIndexCount = str(content['quizStimIndexCount']) task_quiz.quizStimIndex = str(content['quizStimIndex']) task_quiz.quizStimDevalue = str(content['quizStimDevalue']) task_quiz.quizStimContin = str(content['quizStimContin']) task_quiz.quizContinDefault = str(content['quizContinDefault']) task_quiz.quizContin = str(content['quizContin']) task_quiz.quizConfDefault = str(content['quizConfDefault']) task_quiz.quizConf = str(content['quizConf']) task_quiz.quizSoundLabel= str(content['quizSoundLabel']) task_quiz.playNum = str(content['playNum']) task_quiz.quizVolume = str(content['quizVolume']) task_quiz.quizVolumeNotLog = str(content['quizVolumeNotLog']) task_quiz.quizAverDefault= str(content['quizAverDefault']) task_quiz.quizAver= str(content['quizAver']) task_quiz.checkPoint= str(content['checkPoint']) BaseObject.check_and_save(task_quiz) result = dict({"success": "yes"}) return jsonify(result)
def inexpsave(): """ The experiments script updates the server periodically on subjects' progress. This lets us better understand attrition. """ print("accessing the /inexpsave route") if ('prolific_id' in request.form) and ('longit_id' in request.form) and ( 'datastring' in request.form): prolific_id = request.form['prolific_id'] longit_id = request.form['longit_id'] datastring = request.form['datastring'] print("getting the save data for prolific id {0}, longit id {1}: {2}". format(prolific_id, longit_id, datastring)) user = Test.query.\ filter(Test.prolific_id == workerId).\ filter(Test.longit_id == longit_id).\ one() user.datastring = datastring user.status = STARTED BaseObject.check_and_save(user) result = dict({"success": "yes"}) return render_template('error.html', errornum=1012)
def execute(self, activity_id, user_id) -> Activity: if activity_id is None or user_id is None: raise BadArgException() # UPDATE ACTIVITY activity = Activity.query.filter_by(id=activity_id).first() activity.set_status(ActivityStatus.success) activity.set_date_end() # CREATE NEW : footprint footprint = Footprint.query. \ filter_by(user_id=user_id). \ filter_by(type=activity.recommendation.type). \ order_by(Footprint.date_created.desc()). \ first() previous_value = footprint.get_value() new_footprint = Footprint(from_dict=footprint._asdict()) new_footprint.set_value(previous_value - activity.recommendation.benefit) new_footprint.set_date_created() BaseObject.check_and_save(activity, new_footprint) return activity
def execute(sel, activity_id, user_id) -> Activity: if activity_id is None or user_id is None: raise BadArgException() # UPDATE ACTIVITY activity = Activity.query.filter_by(id=activity_id).first() activity.status = ActivityStatus.pending activity.set_date_end() # UPDATE : footprint footprint = Footprint.query. \ filter_by(user_id=user_id). \ filter_by(type=activity.recommendation.type). \ order_by(Footprint.date_created.desc()). \ first() previous_value = footprint.value new_footprint = Footprint(from_dict=footprint._asdict()) new_footprint.value = previous_value + activity.recommendation.benefit new_footprint.set_date_created() BaseObject.check_and_save(activity, new_footprint) HistoryActivity().execute(activity.id, "pending") return activity
def signup(): data = request.json new_user = User(from_dict=request.json) new_user.id = None footprints = data.get('footprints')[0] BaseObject.check_and_save(new_user) objects_to_save = [] for footprint in footprints.get('footprints'): footprint_obj = Footprint(from_dict=footprint) footprint_obj.user_id = int(new_user.get_id()) objects_to_save.append(footprint_obj) # TODO: c'est pas beau mais c'était plus rapide :( answers = footprints.get('answers') for key, value in answers.items(): property_obj = Property.query.filter_by(property_name=key).first() answer_obj = UserProperty() answer_obj.user_id = int(new_user.get_id()) answer_obj.property_id = property_obj.id answer_obj.value = float(value) objects_to_save.append(answer_obj) BaseObject.check_and_save(*objects_to_save) login_user(new_user) return jsonify(new_user._asdict(include=USER_INCLUDES)), 201
def create_psych_data(user_id): content = request.json psych_quiz = PsychQuiz() psych_quiz.userID = str(content['userID']) psych_quiz.date = str(content['date']) psych_quiz.startTime = str(content['startTime']) psych_quiz.qnTimeStart = str(content['qnTimeStart']) psych_quiz.qnTimeEnd = str(content['qnTimeEnd']) psych_quiz.PgFinish_demo = str(content['PgFinish_demo']) psych_quiz.PgFinish_OCIR = str(content['PgFinish_OCIR']) psych_quiz.PgFinish_STAI_Y1 = str(content['PgFinish_STAI_Y1']) psych_quiz.PgFinish_STAI_Y2 = str(content['PgFinish_STAI_Y2']) psych_quiz.PgRT_demo = str(content['PgRT_demo']) psych_quiz.PgRT_OCIR = str(content['PgRT_OCIR']) psych_quiz.PgRT_STAI_Y1 = str(content['PgRT_STAI_Y1']) psych_quiz.PgRT_STAI_Y2 = str(content['PgRT_STAI_Y2']) psych_quiz.age = str(content['age']) psych_quiz.gender = str(content['gender']) psych_quiz.OCIR = str(content['OCIR']) psych_quiz.STAI_Y1= str(content['STAI_Y1']) psych_quiz.STAI_Y2= str(content['STAI_Y2']) BaseObject.check_and_save(psych_quiz) result = dict({"success": "yes"}) return jsonify(result)
def enterexp(): """ AJAX listener that listens for a signal from the user's script when they leave the instructions and enter the real experiment. After the server receives this signal, it will no longer allow them to re-access the experiment applet (meaning they can't do part of the experiment and referesh to start over). """ print("/inexp") if ('prolific_id' in request.form) and ('longit_id' in request.form): prolific_id = request.form['prolific_id'] longit_id = request.form['longit_id'] else: raise ValueError('improper_inputs')\ user = Test.query.\ filter(Test.prolific_id == prolific_id).\ filter(Test.longit_id == longit_id).\ one() user.status = STARTED user.beginexp = datetime.datetime.now() BaseObject.check_and_save(user) result = dict({"success": "yes"}) return "Success"
def create_task_data(user_id): print(user_id) content = request.json task_data = TaskData() task_data.userID = str(content['userID']) task_data.date = str(content['date']) task_data.startTime = str(content['startTime']) task_data.taskSession = str(content['taskSession']) task_data.taskSessionTry = str(content['taskSessionTry']) task_data.trialNum = str(content['trialNum']) task_data.trialTime = str(content['trialTime']) task_data.blockNum = str(content['blockNum']) task_data.trialinBlockNum = str(content['trialinBlockNum']) task_data.devaluedBlock = str(content['devaluedBlock']) task_data.fixTime = str(content['fixTime']) task_data.attenIndexIndiv = str(content['attenIndexIndiv']) task_data.attenCheckKey = str(content['attenCheckKey']) task_data.attenCheckTime = str(content['attenCheckTime']) task_data.stimIndexCondIndiv = str(content['stimIndexCondIndiv']) task_data.stimTime = str(content['stimTime']) task_data.fbProbTrack = str(content['fbProbTrack']) task_data.randProb = str(content['randProb']) task_data.responseKey = str(content['responseKey']) task_data.reactionTime = str(content['reactionTime']) task_data.playFbSound = str(content['playFbSound']) task_data.fbTime = str(content['fbTime']) task_data.volume = str(content['volume']) task_data.volumeNotLog = str(content['volumeNotLog']) BaseObject.check_and_save(task_data) result = dict({"success": "yes"}) return jsonify(result)
def test_get_property_should_return_value_for_property_if_already_answered( app): # Given obj_to_save = [] user = create_user(email='*****@*****.**', username='******', password='******') obj_to_save.append(user) question = Question() question.question_name = 'question_1' obj_to_save.append(question) BaseObject.check_and_save(*obj_to_save) user_property_obj = UserProperty() user_property_obj.user_id = user.id user_property_obj.question_id = question.id user_property_obj.value = float(0.5) BaseObject.check_and_save(user_property_obj) # When property_request = req_with_auth(email='*****@*****.**', password='******') \ .get(API_URL + '/property') # Then assert property_request.status_code == 200 content = property_request.json() assert 'question_1' in content assert content['question_1'] == 0.5
def create_pilot_data(user_id): content = request.json audio_pilot = AudioPilot() audio_pilot.userID = str(content['userID']) audio_pilot.date = str(content['date']) audio_pilot.startTime = str(content['startTime']) audio_pilot.qnNum = str(content['qnNum']) audio_pilot.qnTime = str(content['qnTime']) audio_pilot.qnRT = str(content['qnRT']) audio_pilot.soundIndex = str(content['soundIndex']) audio_pilot.soundFocus = str(content['soundFocus']) audio_pilot.freqFocus = str(content['freqFocus']) audio_pilot.volume = str(content['volume']) audio_pilot.volumePer = str(content['volumePer']) audio_pilot.checkBox = str(content['checkBox']) audio_pilot.playNum = str(content['playNum']) audio_pilot.averRating = str(content['averRating']) audio_pilot.arouRating = str(content['arouRating']) audio_pilot.averRatingDef = str(content['averRatingDef']) audio_pilot.arouRatingDef = str(content['arouRatingDef']) BaseObject.check_and_save(audio_pilot) result = dict({"success": "yes"}) return jsonify(result)
def create_vol_cal_data(user_id): print(user_id) content = request.json vol_cal = VolCal() vol_cal.userID = str(content['userID']) vol_cal.date = str(content['date']) vol_cal.startTime = str(content['startTime']) vol_cal.volCalStage = str(content['volCalStage']) vol_cal.checkTry = str(content['checkTry']) vol_cal.qnTime = str(content['qnTime']) vol_cal.qnRT = str(content['qnRT']) vol_cal.qnNum = str(content['qnNum']) vol_cal.soundIndex = str(content['soundIndex']) vol_cal.soundFocus = str(content['soundFocus']) vol_cal.volume = str(content['volume']) vol_cal.volumePer = str(content['volumePer']) vol_cal.volumeNotLog = str(content['volumeNotLog']) vol_cal.playNum = str(content['playNum']) vol_cal.quizAnsIndiv = str(content['quizAnsIndiv']) vol_cal.qnPressKey = str(content['qnPressKey']) vol_cal.qnCorrIndiv = str(content['qnCorrIndiv']) vol_cal.averRating = str(content['averRating']) vol_cal.arouRating = str(content['arouRating']) vol_cal.averRatingDef= str(content['averRatingDef']) vol_cal.arouRatingDef= str(content['arouRatingDef']) BaseObject.check_and_save(vol_cal) result = dict({"success": "yes"}) return jsonify(result)
def execute(self, footprint: Footprint) -> Footprint: if footprint is None: raise BadArgException() BaseObject.check_and_save(footprint) return footprint
def create_tutorial_data(user_id): content = request.json tutorial_data = TutorialData() tutorial_data.userID = str(content['userID']) tutorial_data.date = str(content['date']) tutorial_data.startTime = str(content['startTime']) tutorial_data.tutorialSession = str(content['tutorialSession']) tutorial_data.tutorialSessionTry = str(content['tutorialSessionTry']) tutorial_data.trialNum = str(content['trialNum']) tutorial_data.trialTime = str(content['trialTime']) tutorial_data.fixTime = str(content['fixTime']) tutorial_data.attenIndex = str(content['attenIndex']) tutorial_data.attenCheckKey = str(content['attenCheckKey']) tutorial_data.attenCheckTime = str(content['attenCheckTime']) tutorial_data.stimTime = str(content['stimTime']) tutorial_data.stimIndex = str(content['stimIndex']) tutorial_data.fbProbTrack = str(content['fbProbTrack']) tutorial_data.randProb = str(content['randProb']) tutorial_data.responseKey = str(content['responseKey']) tutorial_data.reactionTime = str(content['reactionTime']) tutorial_data.playFbSound = str(content['playFbSound']) tutorial_data.fbTime = str(content['fbTime']) tutorial_data.volume = str(content['volume']) tutorial_data.volumeNotLog = str(content['volumeNotLog']) BaseObject.check_and_save(tutorial_data) result = dict({"success": "yes"}) return jsonify(result)
def execute(self, user: User, reco_already_attach_to_user: [Recommendation]) -> list: if user is None: raise BadUserException() query = Recommendation.query. \ filter(Recommendation.id.notin_(reco_already_attach_to_user)) if "RECO_ENGINE" in os.environ \ and int(os.environ.get("RECO_ENGINE")) == 1: possible_recommendations = np.array(query.all()) self.compute_possible_recommendation_with_ml( possible_recommendations) else: possible_recommendations = query.all() random.shuffle(possible_recommendations) result = list() first = True for reco in possible_recommendations: proposition = Proposition.query. \ filter_by(user_id=user.id). \ filter_by(recommendation_id=reco.id). \ filter_by(state=None). \ first() if proposition is None: proposition = Proposition() proposition.user_id = user.id proposition.recommendation_id = reco.id if "RECO_ENGINE" in os.environ \ and int(os.environ.get("RECO_ENGINE")) == 0: proposition.probability = random.uniform(0.0, 1.0) proposition.date_write = datetime.utcnow() BaseObject.check_and_save(proposition) tmp_obj = dict(reco._asdict()) tmp_obj['proposition_id'] = humanize(proposition.id) tmp_obj['probability'] = proposition.probability if first: tmp_obj['first'] = True first = False else: tmp_obj['first'] = False result.append(tmp_obj) sorted_result = sorted(result, key=lambda k: k['probability'], reverse=True) return sorted_result
def start_exp(): """ Serves up the experiment applet. """ print('prolific_id' in request.args) print('Start Expe') if not ('prolific_id' in request.args) and ( 'study_id' in request.args) and ('participant_id' in request.args) and ('longit_id' in request.args): raise ExperimentError( 'prolific_study_participant_longit_id_not_set_in_exp_url') prolific_id = request.args['prolific_id'] study_id = request.args['study_id'] participant_id = request.args['participant_id'] longit_id = request.args['longit_id'] print( ("Prolific ID: {0}, Study ID: {1}, Participant ID: {2}, Longit ID: {3}" ).format(prolific_id, study_id, participant_id, longit_id)) # Filter for prolific id and longit id in the DB: check first to see if they exist. matches = Test.query.\ filter(Test.prolific_id == prolific_id).\ filter(Test.longit_id == longit_id).\ all() # print(matches) numrecs = len(matches) if numrecs == 0: # is not in the DB -> create a record in the DB part = Test(prolific_id, study_id, participant_id, longit_id) print("No match. Status is", part.status) part.status = STARTED part.beginexp = datetime.datetime.now() part.prolific_id = prolific_id part.study_id = study_id part.longit_id = int(longit_id) part.participant_id = int(participant_id) BaseObject.check_and_save(part) result = dict({"success": "yes"}) else: part = matches[0] print("Participant id {0} matched in the DB! Status is {1}".format( participant_id, part.status)) # Start the task return render_template('ps_dev_exp.html', study_id=study_id, participant_id=participant_id, prolific_id=prolific_id, longit_id=longit_id)
def create_psych_data(user_id): content = request.json psych_quiz = PsychQuiz() psych_quiz.userID = str(content['userID']) psych_quiz.date = str(content['date']) psych_quiz.startTime = str(content['startTime']) psych_quiz.qnTimeStart = str(content['qnTimeStart']) psych_quiz.qnTimeEnd = str(content['qnTimeEnd']) psych_quiz.PgFinish_demo = str(content['PgFinish_demo']) psych_quiz.PgFinish_OCIR = str(content['PgFinish_OCIR']) psych_quiz.PgFinish_STAI_Y1 = str(content['PgFinish_STAI_Y1']) psych_quiz.PgFinish_STAI_Y2 = str(content['PgFinish_STAI_Y2']) psych_quiz.PgFinish_BIS11 = str(content['PgFinish_BIS11']) psych_quiz.PgFinish_SDS = str(content['PgFinish_SDS']) psych_quiz.PgFinish_ASI3 = str(content['PgFinish_ASI3']) psych_quiz.PgFinish_BEAQ = str(content['PgFinish_BEAQ']) psych_quiz.PgFinish_IQ_text = str(content['PgFinish_IQ_text']) psych_quiz.PgFinish_IQ_image = str(content['PgFinish_IQ_image']) psych_quiz.PgRT_demo = str(content['PgRT_demo']) psych_quiz.PgRT_OCIR = str(content['PgRT_OCIR']) psych_quiz.PgRT_STAI_Y1 = str(content['PgRT_STAI_Y1']) psych_quiz.PgRT_STAI_Y2 = str(content['PgRT_STAI_Y2']) psych_quiz.PgRT_BIS11 = str(content['PgRT_BIS11']) psych_quiz.PgRT_SDS = str(content['PgRT_SDS']) psych_quiz.PgRT_ASI3 = str(content['PgRT_ASI3']) psych_quiz.PgRT_BEAQ = str(content['PgRT_BEAQ']) psych_quiz.PgRT_IQ_text = str(content['PgRT_IQ_text']) psych_quiz.PgRT_IQ_image = str(content['PgRT_IQ_image']) psych_quiz.age = str(content['age']) psych_quiz.gender = str(content['gender']) psych_quiz.OCIR = str(content['OCIR']) psych_quiz.STAI_Y1 = str(content['STAI_Y1']) psych_quiz.STAI_Y2 = str(content['STAI_Y2']) psych_quiz.BIS11 = str(content['BIS11']) psych_quiz.SDS = str(content['SDS']) psych_quiz.ASI3 = str(content['ASI3']) psych_quiz.BEAQ = str(content['BEAQ']) psych_quiz.IQ_1 = str(content['IQ_1']) psych_quiz.IQ_2 = str(content['IQ_2']) psych_quiz.IQ_1 = str(content['IQ_1']) psych_quiz.IQ_2 = str(content['IQ_2']) psych_quiz.IQ_3 = str(content['IQ_3']) psych_quiz.IQ_4 = str(content['IQ_4']) psych_quiz.IQ_5 = str(content['IQ_5']) psych_quiz.IQ_6 = str(content['IQ_6']) psych_quiz.IQ_7 = str(content['IQ_7']) psych_quiz.IQ_8 = str(content['IQ_8']) psych_quiz.IQimage_1 = str(content['IQimage_1']) psych_quiz.IQimage_2 = str(content['IQimage_2']) psych_quiz.IQimage_3 = str(content['IQimage_3']) psych_quiz.IQimage_4 = str(content['IQimage_4']) psych_quiz.IQimage_5 = str(content['IQimage_5']) psych_quiz.IQimage_6 = str(content['IQimage_6']) psych_quiz.IQimage_7 = str(content['IQimage_7']) psych_quiz.IQimage_8 = str(content['IQimage_8']) BaseObject.check_and_save(psych_quiz) result = dict({"success": "yes"}) return jsonify(result)
def test_search_without_text_in_the_form(app): user = create_user() user.id = 1 BaseObject.check_and_save(user) create_reco("recommendations_data_test") r = req.get(API_URL + '/recommendations/search?title=""') search_json = r.json() assert r.status_code == 400 assert search_json['error'] == 'No recommendation found'
def execute(self, activity_id, user_id) -> Activity: if activity_id is None or user_id is None: raise BadArgException() activity = Activity.query.filter_by(id=activity_id).first() activity.set_status(ActivityStatus.fail) activity.set_date_end() BaseObject.check_and_save(activity) return activity
def create_feedback(user_id): content = request.json feedback = Feedback() feedback.userID = str(content['userID']) feedback.date = str(content['date']) feedback.startTime = str(content['startTime']) feedback.feedback = str(content['feedback']) BaseObject.check_and_save(feedback) result = dict({"success": "yes"}) return jsonify(result)
def execute(self, proposition_id: int): if proposition_id is None: raise BadArgException() proposition = Proposition.query.get(proposition_id) if proposition is None: raise BadIdException() proposition.state = PropositionStatus.refused BaseObject.check_and_save(proposition) HistoryProposition().execute(proposition.id, "refused")
def create_freq_data(user_id): content = request.json audio_freq = AudioFreq() audio_freq.userID = str(content['userID']) audio_freq.date = str(content['date']) audio_freq.startTime = str(content['startTime']) audio_freq.qnNum = str(content['qnNum']) audio_freq.qnTime = str(content['qnTime']) audio_freq.qnRT = str(content['qnRT']) audio_freq.volume = str(content['volume']) audio_freq.volumeNotLog = str(content['volumeNotLog']) audio_freq.freqThresIndiv = str(content['freqThresIndiv']) audio_freq.sliderFreqDefault = str(content['sliderFreqDefault']) BaseObject.check_and_save(audio_freq) result = dict({"success": "yes"}) return jsonify(result)
def create_tutorial_quiz(user_id): content = request.json tutorial_quiz = TutorialQuiz() tutorial_quiz.userID = str(content['userID']) tutorial_quiz.date = str(content['date']) tutorial_quiz.startTime = str(content['startTime']) tutorial_quiz.quizTime = str(content['quizTime']) tutorial_quiz.tutorialSession = str(content['tutorialSession']) tutorial_quiz.tutorialSessionTry = str(content['tutorialSessionTry']) tutorial_quiz.quizSession = str(content['quizSession']) tutorial_quiz.quizQnNum = str(content['quizQnNum']) tutorial_quiz.quizKeypress = str(content['quizKeypress']) tutorial_quiz.quizQnRT = str(content['quizQnRT']) tutorial_quiz.quizScoreCor = str(content['quizScoreCor']) BaseObject.check_and_save(tutorial_quiz) result = dict({"success": "yes"}) return jsonify(result)
def execute(self, recommendation_id: int, user_id: int): if recommendation_id is None or user_id is None: raise BadArgException() # TODO: refactor with proposition_id as a parameter of this function (from webapp) proposition = Proposition.query. \ filter_by(recommendation_id=recommendation_id). \ filter_by(user_id=user_id). \ order_by(Proposition.date_created.desc()). \ first() if proposition is None: raise BadIdException() proposition.state = PropositionStatus.accepted BaseObject.check_and_save(proposition) HistoryProposition().execute(proposition.id, "accepted")
def savedata(): """ User has finished the experiment and is posting their data in the form of a (long) string. They will receive a debriefing back. """ print("accessing the /done route") prolific_id = request.form['prolific_id'] study_id = request.form['study_id'] participant_id = request.form['participant_id'] longit_id = request.form['longit_id'] datastring = request.form['datastring'] when = request.form['when'] payment = request.form['payment'] print("saving the data of subject {1} for study {0} in time point {2}". format(prolific_id, study_id, longit_id)) if ('prolific_id' in request.form) and ('datastring' in request.form): prolific_id = request.form['prolific_id'] datastring = request.form['datastring'] print( "getting the save data {0} for prolific ID {1} and longit ID {2}". format(datastring, prolific_id, longit_id)) user = Test.query.\ filter(Test.prolific_id == prolific_id).\ filter(Test.longit_id == longit_id).\ one() print('Payment', payment) user.datastring = datastring user.status = COMPLETED user.endexp = datetime.datetime.now() user.bonus = payment BaseObject.check_and_save(user) result = dict({"success": "yes"}) print("Exp task done route, status is", user.status) # return render_template('payment.html') return render_template('feedback.html')
def test_get_propositions_should_return_empty_array_if_no_reco_in_db(app): # Given obj_to_save = [] user = create_user(email='*****@*****.**', username='******', password='******') obj_to_save.append(user) BaseObject.check_and_save(*obj_to_save) # When proposition_request = req_with_auth(email='*****@*****.**', password='******') \ .get(API_URL + '/propositions') # Then assert proposition_request.status_code == 200 content = proposition_request.json() assert len(content.get('propositions')) == 0
def startfeedback(): """ User has finished the feedback and is posting their data in the form of a (long) string. They will receive a prolific validation page back. """ print("accessing the /feedbackDone route") prolific_id = request.form['prolific_id'] study_id = request.form['study_id'] participant_id = request.form['participant_id'] longit_id = request.form['longit_id'] when = request.form['when'] print( "saving the feedback data of subject {1} for study {0} in time point {2}" .format(prolific_id, study_id, longit_id)) if ('prolific_id' in request.form) and ('feedbackDatastring' in request.form): prolific_id = request.form['prolific_id'] feedbackDatastring = request.form['feedbackDatastring'] print( "getting the feedback save data {0} for prolific ID {1} and longit ID {2}" .format(feedbackDatastring, prolific_id, longit_id)) user = Test.query.\ filter(Test.prolific_id == prolific_id).\ filter(Test.longit_id == longit_id).\ one() user.feedback = feedbackDatastring user.status = DEBRIEFED user.endexp = datetime.datetime.now() BaseObject.check_and_save(user) result = dict({"success": "yes"}) print("Feedback done route, status is", user.status) return render_template( 'payment.html') # proceed to the validation prolific page
def execute(self, recommendation_id, user_id) -> Activity: if recommendation_id is None: raise BadArgException() # TEST IF RECOMMENDATION ALREADY IN ACTIVITY FOR THE USER existing_activity = Activity.query. \ filter_by(user_id=user_id). \ filter_by(recommendation_id=recommendation_id).first() if existing_activity: raise AlreadyStartedException activity = Activity() activity.set_recommendation(recommendation_id) activity.set_user(user_id) BaseObject.check_and_save(activity) return activity