Open cgc opened 3 years ago
I did this in a separate project by adding a function in custom.py
@custom_code.route('/complete_exp', methods=['POST'])
def complete_exp():
if not 'uniqueId' in request.form:
raise ExperimentError('improper_inputs')
unique_id = request.form['uniqueId']
current_app.logger.info("completed experimente")
try:
user = Participant.query.\
filter(Participant.uniqueid == unique_id).one()
user.status = COMPLETED
user.endhit = datetime.datetime.now()
db_session.add(user)
db_session.commit()
resp = {"status": "success"}
except exc.SQLAlchemyError:
current_app.logger.error("DB error: Unique user not found.")
resp = {"status": "error, uniqueId not found"}
return jsonify(**resp)
and then added a
await $.ajax("complete_exp", {
type: "POST",
data: {uniqueId}
});
in the final completion function (which is async). I know you had a different solution though. Do you think yours might be better?
May be worth considering how to write to
endhit
andstatus
from Prolific, since those variables are part of the logic for counterbalancing. Code here.