UPdate: gamification points calculation

parent 4ba367a6
...@@ -13,29 +13,29 @@ from bson.objectid import ObjectId ...@@ -13,29 +13,29 @@ from bson.objectid import ObjectId
def add_points_earns(id): def add_points_earns(id):
try: try:
# points 1-10 # points 1-10
points = 4000 # points = 4000
earns = 2000 earns = 2000
# points calculation algorithm # points calculation algorithm
# if earns >= 5000: if earns >= 5000:
# points = 10 points = 10
# elif earns >= 4000 and earns <= 5000: elif earns > 4000 and earns <= 5000:
# points = 9 points = 9
# elif earns >= 3000 and earns <= 4000: elif earns > 3000 and earns <= 4000:
# points = 8 points = 8
# elif earns >= 2000 and earns <= 3000: elif earns > 2000 and earns <= 3000:
# points = 7 points = 7
# elif earns >= 1500 and earns <= 2000: elif earns > 1500 and earns <= 2000:
# points = 6 points = 6
# elif earns >= 1000 and earns <= 1500: elif earns > 1000 and earns <= 1500:
# points = 5 points = 5
# elif earns >= 500 and earns <= 1000: elif earns > 500 and earns <= 1000:
# points = 4 points = 4
# elif earns >= 500 and earns <= 1000: elif earns > 400 and earns <= 500:
# points = 3 points = 3
# elif earns >= 500 and earns <= 1000: elif earns > 300 and earns <= 400:
# points = 2 points = 2
# elif earns >= 100 and earns <= 500: elif earns > 100 and earns <= 300:
# points = 1 points = 1
user_earns = db.users.find_one({"_id": ObjectId(id)}) user_earns = db.users.find_one({"_id": ObjectId(id)})
# for user in user_earns: # for user in user_earns:
......
...@@ -6,13 +6,37 @@ import json ...@@ -6,13 +6,37 @@ import json
from bson.objectid import ObjectId from bson.objectid import ObjectId
@app.route("/points/<id>", methods=["POST"]) @app.route("/discount/<id>", methods=["POST"])
# @check_for_token # @check_for_token
def calculate_discount(): def calculate_discount(id):
user_earns = db.CropData.find_one({"_id": ObjectId(id)})
print(user_earns)
return Response( # if points >= 1:
response= json.dumps({"message": "user points entered"}), # discount = 1
# elif points > 2:
# discount = 2
# elif points > 3:
# discount = 3
# elif points > 4:
# discount = 4
# elif points > 5:
# discount = 5
# elif points > 6:
# discount = 6
# elif points > 7:
# discount = 7
# elif points > 8:
# discount = 8
# elif points > 9:
# discount = 9
# elif points > 10:
# discount = 10
return Response(
response= json.dumps({"Discount price": discount}),
status=200, status=200,
) )
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment