Hi!
I've created a custom.py that fails to get called at the end of my experiment.
The server.log outputs:
File "/home/username/env/lib/python3.8/site-packages/flask/templating.py", line 86, in _get_source_fast
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: compute_bonus
However, I'm not raising any exceptions of that type in my custom.py file (I even tried commenting out the jinja2 import) so I'm afraid the server is still using the original template, even after restarting it (js files get updated as expected though).
How can I force the server to use the new version of custom.py?
Or is it possible that the error is somewhere else?
Here is my custom.py code:
@custom_code.route("/http://localhost:22362/compute_bonus", methods=["GET"])
def compute_bonus():
# check that user provided the correct keys
# errors will not be that graceful here if being
# accessed by the Javascript client
if not "uniqueId" in request.args:
# i don't like returning HTML to JSON requests... maybe should change this
raise ExperimentError("improper_inputs")
uniqueId = request.args["uniqueId"]
def get_completion(user_df):
criterion = "questionnaire" in user_df.phase.unique().tolist()
return criterion
def get_time_bonus(elapsed_ms, hourly_rate=8, dp=2):
return round(hourly_rate*(elapsed_ms/3600000), dp)
def get_perf_bonus(perf, worst_perf=0.5, best_perf=0.8, best_bonus=2.5, dp=2):
if perf >= best_perf:
return best_bonus
elif perf <= worst_perf:
return 0
elif (perf > worst_perf) and (perf < best_perf):
m = best_bonus/(best_perf-worst_perf)
q = -m * worst_perf
return round(m*perf + q, dp)
else:
return 0
user = Participant.query.\
filter(Participant.uniqueid == uniqueId).\
one()
user_data = loads(user.datastring) # load datastring from JSON
flat_user_data = [record["trialdata"] for record in user_data["data"]]
user_df = pd.DataFrame(flat_user_data) # get user data as pandas df
max_elapsed_time = user_df.time_elapsed[user_df.time_elapsed.last_valid_index()] # in ms
bonus = get_time_bonus(max_elapsed_time)
if get_completion(user_df):
perf = round(user_df_learn_points[user_df_learn_points.correct.astype("str") == "True"].correct.count()/(num_trials/2), 4)
bonus += get_perf_bonus(perf) # add performance bonus
print(bonus)
user.bonus = bonus
db_session.add(user)
db_session.commit()
resp = {"bonusComputed": "success"}
return jsonify(**resp)
Thank you so much for your time and help!
Gaia