File size: 1,008 Bytes
f86ba47
 
 
 
 
 
 
c30ad92
d28c029
f86ba47
 
 
d28c029
 
 
 
 
 
 
 
 
 
f86ba47
d28c029
f86ba47
 
 
d28c029
f86ba47
 
 
 
 
 
 
255e287
 
f86ba47
d28c029
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os

from dotenv import load_dotenv
from pymongo import MongoClient

load_dotenv()

client = MongoClient(os.getenv("MONGO_CONNECTION_STRING"))
print("Connected to MongoDB")

db = client[os.getenv("MONGO_DB_NAME")]

env_type = os.getenv("ENV_TYPE")
print("env:", env_type)

if env_type == "dev":
    collection_name = os.getenv("DEV_MONGO_COLLECTION")
    print("Using dev collection")
else:
    collection_name = os.getenv("PROD_MONGO_COLLECTION")
    print("Using prod collection")

collection = db[collection_name]
print("Using collection:", collection_name)


def save_results(student_name, class_name, model, book, questions, feedback, rating):
    print("Saving results")
    collection.insert_one({
        "student_name": student_name,
        "class": class_name,
        "model": model,
        "book": book,
        "questions": questions,
        "feedback": feedback,
        "rating": rating,
        "created_at": db.command("serverStatus")["localTime"]
    })
    print("Saved results")