Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -789,12 +789,11 @@ def roadmap():
|
|
| 789 |
# Get roadmap data
|
| 790 |
roadmap_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id})
|
| 791 |
if roadmap_data:
|
| 792 |
-
return jsonify({'success': True, 'roadmapData': {'data': roadmap_data['data']}, 'activeDays': roadmap_data['activeDays']})
|
| 793 |
else:
|
| 794 |
return jsonify({'success': False})
|
| 795 |
|
| 796 |
|
| 797 |
-
|
| 798 |
@app.route('/roadmap/history', methods=['GET'])
|
| 799 |
@auth_user
|
| 800 |
def roadmapGetHistory():
|
|
@@ -812,7 +811,6 @@ def roadmapGetHistory():
|
|
| 812 |
return jsonify({"error": "An error occurred"}), 500
|
| 813 |
|
| 814 |
|
| 815 |
-
|
| 816 |
@app.route('/roadmapmodder', methods=['POST'])
|
| 817 |
@auth_user
|
| 818 |
def roadmapmodder():
|
|
@@ -959,6 +957,125 @@ def roadmapmodder():
|
|
| 959 |
return jsonify({'success': True})
|
| 960 |
|
| 961 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 962 |
|
| 963 |
if __name__ == '__main__':
|
| 964 |
app.run(debug=True, host='0.0.0.0')
|
|
|
|
| 789 |
# Get roadmap data
|
| 790 |
roadmap_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id})
|
| 791 |
if roadmap_data:
|
| 792 |
+
return jsonify({'success': True, 'roadmapData': {'data': roadmap_data['data']}, 'activeDays': roadmap_data['activeDays'], 'practice': roadmap_data['practice'], 'title': roadmap_data['title']})
|
| 793 |
else:
|
| 794 |
return jsonify({'success': False})
|
| 795 |
|
| 796 |
|
|
|
|
| 797 |
@app.route('/roadmap/history', methods=['GET'])
|
| 798 |
@auth_user
|
| 799 |
def roadmapGetHistory():
|
|
|
|
| 811 |
return jsonify({"error": "An error occurred"}), 500
|
| 812 |
|
| 813 |
|
|
|
|
| 814 |
@app.route('/roadmapmodder', methods=['POST'])
|
| 815 |
@auth_user
|
| 816 |
def roadmapmodder():
|
|
|
|
| 957 |
return jsonify({'success': True})
|
| 958 |
|
| 959 |
|
| 960 |
+
@app.route('/problemgenerator', methods=['POST'])
|
| 961 |
+
def problemgenerator():
|
| 962 |
+
if request.method == 'POST':
|
| 963 |
+
data = request.get_json()
|
| 964 |
+
user_id = data.get('user_id')
|
| 965 |
+
obj_id = data.get('_id')
|
| 966 |
+
week_day = int(data.get('weekDay'))
|
| 967 |
+
|
| 968 |
+
if data.get('type') == 1:
|
| 969 |
+
query = data.get('query')
|
| 970 |
+
|
| 971 |
+
prompt = '''
|
| 972 |
+
Generate 5 Multiple Choice Questions with single correct answers and 4 options in the following format:
|
| 973 |
+
[{"question": "What is that?", "options": {"1": "Option1", "2": "Option2", "3": "Option3", "4": "Option4"}, "answer" : {"3": "Option3"}, "explaination": "This is explaination."}, ... , {"question": "What is that?", "options": {"0": "Option1", "1": "Option2", "3": "Option3", "4": "Option4"}, "answer" : {"3": "Option3"}, "explaination": "This is explaination."}]
|
| 974 |
+
|
| 975 |
+
- Topic for questions is : ''' + query + '''
|
| 976 |
+
- It is required that the response should be an list of objects. Don't include any other verbose explanations and don't include the markdown syntax anywhere.
|
| 977 |
+
'''
|
| 978 |
+
|
| 979 |
+
response = model.generate_content(prompt)
|
| 980 |
+
|
| 981 |
+
if response.text[0] == '[':
|
| 982 |
+
retro = json.loads(response.text)
|
| 983 |
+
for ele in retro:
|
| 984 |
+
ele["solved"] = False
|
| 985 |
+
|
| 986 |
+
roadmap_collection.update_one(
|
| 987 |
+
{"_id": ObjectId(obj_id)},
|
| 988 |
+
{"$set": { f"practice.{str(week_day)}": retro }}
|
| 989 |
+
)
|
| 990 |
+
|
| 991 |
+
problems_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id}, {"_id": 1, "practice": 1})
|
| 992 |
+
|
| 993 |
+
return jsonify({"success": True, "practice": problems_data['practice'] }), 200
|
| 994 |
+
|
| 995 |
+
elif response.text[0] == '`':
|
| 996 |
+
retro = json.loads(response.text[7:-3])
|
| 997 |
+
for ele in retro:
|
| 998 |
+
ele["solved"] = False
|
| 999 |
+
|
| 1000 |
+
roadmap_collection.update_one(
|
| 1001 |
+
{"_id": ObjectId(obj_id)},
|
| 1002 |
+
{"$set": { f"practice.{str(week_day)}": retro }}
|
| 1003 |
+
)
|
| 1004 |
+
|
| 1005 |
+
problems_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id}, {"_id": 1, "practice": 1})
|
| 1006 |
+
|
| 1007 |
+
return jsonify({"success": True, "practice": problems_data['practice'] }), 200
|
| 1008 |
+
|
| 1009 |
+
print(response.text)
|
| 1010 |
+
return jsonify({"success": False}), 500
|
| 1011 |
+
|
| 1012 |
+
elif data.get('type') == 2:
|
| 1013 |
+
query = data.get('query')
|
| 1014 |
+
|
| 1015 |
+
prompt = '''
|
| 1016 |
+
Generate 5 Multiple Choice Questions with single correct answers and 4 options in the following format:
|
| 1017 |
+
[{"question": "What is that?", "options": {"1": "Option1", "2": "Option2", "3": "Option3", "4": "Option4"}, "answer" : {"3": "Option3"}, "explaination": "This is explaination."}, ... , {"question": "What is that?", "options": {"0": "Option1", "1": "Option2", "3": "Option3", "4": "Option4"}, "answer" : {"3": "Option3"}, "explaination": "This is explaination."}]
|
| 1018 |
+
|
| 1019 |
+
- Topic for questions is : ''' + query + '''
|
| 1020 |
+
- It is required that the response should be an list of objects. Don't include any other verbose explanations and don't include the markdown syntax anywhere.
|
| 1021 |
+
'''
|
| 1022 |
+
|
| 1023 |
+
response = model.generate_content(prompt)
|
| 1024 |
+
|
| 1025 |
+
if response.text[0] == '[':
|
| 1026 |
+
temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})
|
| 1027 |
+
retro = json.loads(response.text)
|
| 1028 |
+
for ele in retro:
|
| 1029 |
+
ele["solved"] = False
|
| 1030 |
+
|
| 1031 |
+
temp_data['practice'][str(week_day)] += retro
|
| 1032 |
+
roadmap_collection.update_one(
|
| 1033 |
+
{"_id": ObjectId(obj_id)},
|
| 1034 |
+
{"$set": { "practice": temp_data['practice'] }}
|
| 1035 |
+
)
|
| 1036 |
+
|
| 1037 |
+
problems_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id}, {"_id": 1, "practice": 1})
|
| 1038 |
+
|
| 1039 |
+
return jsonify({"success": True, "practice": problems_data['practice'] }), 200
|
| 1040 |
+
|
| 1041 |
+
elif response.text[0] == '`':
|
| 1042 |
+
temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})
|
| 1043 |
+
retro = json.loads(response.text[7:-3])
|
| 1044 |
+
for ele in retro:
|
| 1045 |
+
ele["solved"] = False
|
| 1046 |
+
|
| 1047 |
+
temp_data['practice'][str(week_day)] += retro
|
| 1048 |
+
roadmap_collection.update_one(
|
| 1049 |
+
{"_id": ObjectId(obj_id)},
|
| 1050 |
+
{"$set": { "practice": temp_data['practice'] }}
|
| 1051 |
+
)
|
| 1052 |
+
|
| 1053 |
+
problems_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id}, {"_id": 1, "practice": 1})
|
| 1054 |
+
|
| 1055 |
+
return jsonify({"success": True, "practice": problems_data['practice'] }), 200
|
| 1056 |
+
|
| 1057 |
+
print(response.text)
|
| 1058 |
+
return jsonify({"success": False}), 500
|
| 1059 |
+
|
| 1060 |
+
|
| 1061 |
+
@app.route('/problemhandler', methods=['POST'])
|
| 1062 |
+
def problemhandler():
|
| 1063 |
+
if request.method == 'POST':
|
| 1064 |
+
data = request.get_json()
|
| 1065 |
+
obj_id = data.get('_id')
|
| 1066 |
+
week_day = data.get('weekDay')
|
| 1067 |
+
indexer = data.get('index')
|
| 1068 |
+
|
| 1069 |
+
temp = f"practice.{week_day}.{indexer}.solved"
|
| 1070 |
+
print(temp)
|
| 1071 |
+
|
| 1072 |
+
test = roadmap_collection.update_one(
|
| 1073 |
+
{"_id": ObjectId(obj_id)},
|
| 1074 |
+
{"$set": { temp : True }}
|
| 1075 |
+
)
|
| 1076 |
+
print(test)
|
| 1077 |
+
return jsonify({"success": True}), 200
|
| 1078 |
+
|
| 1079 |
|
| 1080 |
if __name__ == '__main__':
|
| 1081 |
app.run(debug=True, host='0.0.0.0')
|