Created
June 17, 2019 14:52
-
-
Save JustAyush/ae457636060eb4c5f01ec132bf25657a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user_id = request.user.id + 278858 | |
book_id = isbn | |
new_rating = rating | |
x=mycol.find({"user_id":user_id,"activity.book_id":book_id},{"activity.$.activity":1,"_id":0}) | |
if x.count()==0: | |
y=mycol.find({"user_id":user_id},{"activity.$.activity":1,"_id":0}) | |
if(y.count()==0): | |
mycol.insert({"user_id":user_id,"isFifteen":0,"activity":[{"book_id":book_id,"activity":{"rating":new_rating,"net_rating":new_rating,"date_modified":datetime.datetime.now()}}]}) | |
else: | |
mycol.update({"user_id":user_id},{"$push":{"activity":{"book_id":book_id,"activity":{"rating":new_rating,"net_rating":new_rating,"date_modified":datetime.datetime.now()}}}}) | |
else: | |
data=x[0]['activity'][0]['activity'] | |
print(data) | |
try: | |
clicks_rating=float(data['clicks_rating']) | |
except: | |
clicks_rating=0 | |
try: | |
review_rating=float(data['review_rating']) | |
except: | |
review_rating=0 | |
net_rating=get_net_rating(review_rating,new_rating,clicks_rating) | |
print("clicks_rating is:"+str(clicks_rating)) | |
print("review rating is:"+str(review_rating)) | |
print("new rating is:"+str(new_rating)) | |
print("net"+str(net_rating)) | |
print("new date:"+str(datetime.datetime.now())) | |
mycol.update({"user_id":user_id,"activity.book_id":book_id},{"$set":{"activity.$.activity.rating":new_rating,"activity.$.activity.net_rating":net_rating,"activity.$.activity.date_modified":datetime.datetime.now()} },upsert=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment