Skip to content

Commit

Permalink
Added time record for feedback function
Browse files Browse the repository at this point in the history
  • Loading branch information
darrylong committed Nov 28, 2023
1 parent 471c411 commit ce058f9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cornac/serving/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import os
import pickle
from datetime import datetime, timezone
from csv import writer

try:
Expand Down Expand Up @@ -89,6 +90,9 @@ def create_app():
def recommend():
global model, train_set

if model is None:
return "Model is not yet loaded. Please try again later.", 400

params = request.args
uid = params.get("uid")
k = int(params.get("k", -1))
Expand Down Expand Up @@ -121,6 +125,7 @@ def add_feedback():
uid = params.get("uid")
iid = params.get("iid")
rating = params.get("rating", 1)
time = datetime.now(timezone.utc)

if uid is None:
return "uid is required", 400
Expand All @@ -130,12 +135,17 @@ def add_feedback():

with open("feedback.csv", "a+", newline="") as write_obj:
csv_writer = writer(write_obj)
csv_writer.writerow([uid, iid, rating])
csv_writer.writerow([uid, iid, rating, time])
write_obj.close()

data = {
"message": "Feedback added",
"data": f"uid: {uid}, iid: {iid}, rating: {rating}",
"data": {
"uid": uid,
"iid": iid,
"rating": rating,
"time": str(time),
},
}

return jsonify(data), 200
Expand Down

0 comments on commit ce058f9

Please sign in to comment.