|
|
|
from pymongo import MongoClient |
|
from datetime import datetime |
|
from werkzeug.security import generate_password_hash |
|
import os |
|
from dotenv import load_dotenv |
|
|
|
load_dotenv() |
|
MONGO_URI = os.getenv("MONGO_URI") |
|
|
|
client = MongoClient(MONGO_URI) |
|
try: |
|
client.admin.command("ping") |
|
print("MongoDB connection successful") |
|
except Exception as e: |
|
print(f"MongoDB connection failed: {e}") |
|
|
|
db = client["novascholar_db"] |
|
|
|
|
|
|
|
research_assistant_schema = { |
|
"bsonType": "object", |
|
"required": ["full_name", "password", "email", "courses_assisted"], |
|
"properties": { |
|
"full_name": { |
|
"bsonType": "string", |
|
"description": "Full name of the research assistant", |
|
}, |
|
"password": { |
|
"bsonType": "string", |
|
"description": "Hashed password of the research assistant", |
|
}, |
|
"email": { |
|
"bsonType": "string", |
|
"description": "Email address of the research assistant", |
|
}, |
|
"courses_assisted": { |
|
"bsonType": "array", |
|
"description": "List of courses the research assistant is assisting", |
|
"items": { |
|
"bsonType": "object", |
|
"required": ["course_id"], |
|
"properties": { |
|
"course_id": { |
|
"bsonType": "string", |
|
"description": "ID of the course", |
|
} |
|
}, |
|
}, |
|
}, |
|
}, |
|
} |
|
|
|
|
|
research_assistants_collection = db["research_assistants"] |
|
|
|
|
|
research_assistants_collection.create_index("full_name", unique=True) |
|
research_assistants_collection.create_index("email", unique=True) |
|
|
|
|
|
|
|
def insert_sample_research_assistants(): |
|
sample_research_assistants = [ |
|
{ |
|
"full_name": "John Doe RA", |
|
"password": generate_password_hash("password123"), |
|
"email": "[email protected]", |
|
"courses_assisted": [{"course_id": "CS101"}, {"course_id": "CS102"}], |
|
} |
|
] |
|
|
|
try: |
|
research_assistants_collection.insert_many(sample_research_assistants) |
|
print("Sample research assistants inserted successfully!") |
|
except Exception as e: |
|
print(f"Error inserting sample research assistants: {e}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
analyst_schema = { |
|
"bsonType": "object", |
|
"required": ["full_name", "password", "email", "courses_analyzed"], |
|
"properties": { |
|
"full_name": {"bsonType": "string", "description": "Full name of the analyst"}, |
|
"password": { |
|
"bsonType": "string", |
|
"description": "Hashed password of the analyst", |
|
}, |
|
"email": {"bsonType": "string", "description": "Email address of the analyst"}, |
|
"courses_analyzed": { |
|
"bsonType": "array", |
|
"description": "List of courses the analyst is analyzing", |
|
"items": { |
|
"bsonType": "object", |
|
"required": ["course_id"], |
|
"properties": { |
|
"course_id": { |
|
"bsonType": "string", |
|
"description": "ID of the course", |
|
} |
|
}, |
|
}, |
|
}, |
|
}, |
|
} |
|
|
|
|
|
analysts_collection = db["analysts"] |
|
|
|
|
|
analysts_collection.create_index("full_name", unique=True) |
|
analysts_collection.create_index("email", unique=True) |
|
|
|
|
|
def insert_sample_analysts(): |
|
sample_analysts = [ |
|
{ |
|
"full_name": "jane", |
|
"password": generate_password_hash("jane"), |
|
"email": "[email protected]", |
|
"courses_analyzed": [{"course_id": "CS101"}, {"course_id": "CS102"}], |
|
} |
|
] |
|
|
|
try: |
|
analysts_collection.insert_many(sample_analysts) |
|
print("Sample analysts inserted successfully!") |
|
except Exception as e: |
|
print(f"Error inserting sample analysts: {e}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
course_schema = { |
|
"bsonType": "object", |
|
"required": [ |
|
"course_id", |
|
"title", |
|
"description", |
|
"faculty", |
|
"faculty_id", |
|
"duration", |
|
"created_at", |
|
], |
|
"properties": { |
|
"course_id": { |
|
"bsonType": "string", |
|
"description": "Unique identifier for the course", |
|
}, |
|
"title": {"bsonType": "string", "description": "Title of the course"}, |
|
"description": { |
|
"bsonType": "string", |
|
"description": "Description of the course", |
|
}, |
|
"faculty": {"bsonType": "string", "description": "Name of the faculty"}, |
|
"duration": {"bsonType": "string", "description": "Duration of the course"}, |
|
"created_at": { |
|
"bsonType": "date", |
|
"description": "Date when the course was created", |
|
}, |
|
"sessions": { |
|
"bsonType": "array", |
|
"description": "List of sessions associated with the course", |
|
"items": { |
|
"bsonType": "object", |
|
"required": ["session_id", "title", "date", "status", "created_at"], |
|
"properties": { |
|
"session_id": { |
|
"bsonType": "string", |
|
"description": "Unique identifier for the session", |
|
}, |
|
"title": { |
|
"bsonType": "string", |
|
"description": "Title of the session", |
|
}, |
|
"date": {"bsonType": "date", "description": "Date of the session"}, |
|
"status": { |
|
"bsonType": "string", |
|
"description": "Status of the session (e.g., completed, upcoming)", |
|
}, |
|
"created_at": { |
|
"bsonType": "date", |
|
"description": "Date when the session was created", |
|
}, |
|
"pre_class": { |
|
"bsonType": "object", |
|
"description": "Pre-class segment data", |
|
"properties": { |
|
"resources": { |
|
"bsonType": "array", |
|
"description": "List of pre-class resources", |
|
"items": { |
|
"bsonType": "object", |
|
"required": ["type", "title", "url"], |
|
"properties": { |
|
"type": { |
|
"bsonType": "string", |
|
"description": "Type of resource (e.g., pdf, video)", |
|
}, |
|
"title": { |
|
"bsonType": "string", |
|
"description": "Title of the resource", |
|
}, |
|
"url": { |
|
"bsonType": "string", |
|
"description": "URL of the resource", |
|
}, |
|
"vector": { |
|
"bsonType": "array", |
|
"description": "Vector representation of the resource", |
|
"items": {"bsonType": "double"}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
"completion_required": { |
|
"bsonType": "bool", |
|
"description": "Indicates if completion of pre-class resources is required", |
|
}, |
|
}, |
|
}, |
|
"in_class": { |
|
"bsonType": "object", |
|
"description": "In-class segment data", |
|
"properties": { |
|
"topics": { |
|
"bsonType": "array", |
|
"description": "List of topics covered in the session", |
|
"items": {"bsonType": "string"}, |
|
}, |
|
"quiz": { |
|
"bsonType": "object", |
|
"description": "Quiz data", |
|
"properties": { |
|
"title": { |
|
"bsonType": "string", |
|
"description": "Title of the quiz", |
|
}, |
|
"questions": { |
|
"bsonType": "int", |
|
"description": "Number of questions in the quiz", |
|
}, |
|
"duration": { |
|
"bsonType": "int", |
|
"description": "Duration of the quiz in minutes", |
|
}, |
|
}, |
|
}, |
|
"polls": { |
|
"bsonType": "array", |
|
"description": "List of polls conducted during the session", |
|
"items": { |
|
"bsonType": "object", |
|
"required": ["question", "options"], |
|
"properties": { |
|
"question": { |
|
"bsonType": "string", |
|
"description": "Poll question", |
|
}, |
|
"options": { |
|
"bsonType": "array", |
|
"description": "List of poll options", |
|
"items": {"bsonType": "string"}, |
|
}, |
|
"responses": { |
|
"bsonType": "object", |
|
"description": "Responses to the poll", |
|
"additionalProperties": {"bsonType": "int"}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
"post_class": { |
|
"bsonType": "object", |
|
"description": "Post-class segment data", |
|
"properties": { |
|
"assignments": { |
|
"bsonType": "array", |
|
"description": "List of assignments", |
|
"items": { |
|
"bsonType": "object", |
|
"required": ["id", "title", "due_date", "status"], |
|
"properties": { |
|
"id": { |
|
"bsonType": "int", |
|
"description": "Assignment ID", |
|
}, |
|
"title": { |
|
"bsonType": "string", |
|
"description": "Title of the assignment", |
|
}, |
|
"due_date": { |
|
"bsonType": "date", |
|
"description": "Due date of the assignment", |
|
}, |
|
"status": { |
|
"bsonType": "string", |
|
"description": "Status of the assignment (e.g., pending, completed)", |
|
}, |
|
"submissions": { |
|
"bsonType": "array", |
|
"description": "List of submissions", |
|
"items": { |
|
"bsonType": "object", |
|
"required": [ |
|
"student_id", |
|
"file_url", |
|
"submitted_at", |
|
], |
|
"properties": { |
|
"student_id": { |
|
"bsonType": "string", |
|
"description": "ID of the student who submitted the assignment", |
|
}, |
|
"file_url": { |
|
"bsonType": "string", |
|
"description": "URL of the submitted file", |
|
}, |
|
"submitted_at": { |
|
"bsonType": "date", |
|
"description": "Date when the assignment was submitted", |
|
}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
} |
|
}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
courses_collection2 = db["courses_collection2"] |
|
|
|
|
|
|
|
users_schema = { |
|
"bsonType": "object", |
|
"required": ["user_id", "username", "password", "role", "created_at"], |
|
"properties": { |
|
"user_id": { |
|
"bsonType": "string", |
|
"description": "Unique identifier for the user", |
|
}, |
|
"username": {"bsonType": "string", "description": "Name of the User"}, |
|
"password": {"bsonType": "string", "description": "Password of the user"}, |
|
"role": { |
|
"bsonType": "string", |
|
"description": "Type of user (e.g., student, faculty)", |
|
}, |
|
"created_at": { |
|
"bsonType": "date", |
|
"description": "Date when the user was created", |
|
}, |
|
}, |
|
} |
|
|
|
|
|
users_collection = db["users"] |
|
|
|
|
|
|
|
student_schema = { |
|
"bsonType": "object", |
|
"required": ["SID", "full_name", "password", "enrolled_courses", "created_at"], |
|
"properties": { |
|
"SID": { |
|
"bsonType": "string", |
|
"description": "Unique identifier for the student", |
|
}, |
|
"full_name": {"bsonType": "string", "description": "Full name of the student"}, |
|
"password": { |
|
"bsonType": "string", |
|
"description": "Hashed password of the student", |
|
}, |
|
"enrolled_courses": { |
|
"bsonType": "array", |
|
"description": "List of courses the student is enrolled in", |
|
"items": { |
|
"bsonType": "object", |
|
"required": ["course_id", "title"], |
|
"properties": { |
|
"course_id": { |
|
"bsonType": "string", |
|
"description": "Unique identifier for the course", |
|
}, |
|
"title": { |
|
"bsonType": "string", |
|
"description": "Title of the course", |
|
}, |
|
}, |
|
}, |
|
}, |
|
"created_at": { |
|
"bsonType": "date", |
|
"description": "Date when the student was created", |
|
}, |
|
}, |
|
} |
|
|
|
faculty_schema = { |
|
"bsonType": "object", |
|
"required": ["TID", "full_name", "password", "courses_taught", "created_at"], |
|
"properties": { |
|
"TID": { |
|
"bsonType": "string", |
|
"description": "Unique identifier for the faculty", |
|
}, |
|
"full_name": {"bsonType": "string", "description": "Full name of the faculty"}, |
|
"password": { |
|
"bsonType": "string", |
|
"description": "Hashed password of the faculty", |
|
}, |
|
"courses_taught": { |
|
"bsonType": "array", |
|
"description": "List of courses the faculty is teaching", |
|
"items": { |
|
"bsonType": "object", |
|
"required": ["course_id", "title"], |
|
"properties": { |
|
"course_id": { |
|
"bsonType": "string", |
|
"description": "Unique identifier for the course", |
|
}, |
|
"title": { |
|
"bsonType": "string", |
|
"description": "Title of the course", |
|
}, |
|
}, |
|
}, |
|
}, |
|
"created_at": { |
|
"bsonType": "date", |
|
"description": "Date when the faculty was created", |
|
}, |
|
}, |
|
} |
|
|
|
|
|
|
|
|
|
students_collection = db["students"] |
|
faculty_collection = db["faculty"] |
|
|
|
|
|
vector_schema = { |
|
"bsonType": "object", |
|
"required": ["resource_id", "vector"], |
|
"properties": { |
|
"resource_id": { |
|
"bsonType": "objectId", |
|
"description": "Unique identifier for the resource", |
|
}, |
|
"vector": { |
|
"bsonType": "array", |
|
"description": "Vector representation of the resource", |
|
"items": {"bsonType": "double"}, |
|
}, |
|
"text": {"bsonType": "string", "description": "Text content of the resource"}, |
|
"created_at": { |
|
"bsonType": "date", |
|
"description": "Date when the vector was created", |
|
}, |
|
}, |
|
} |
|
|
|
|
|
vectors_collection = db["vectors"] |
|
|
|
|
|
|
|
|
|
chat_history_schema = { |
|
"bsonType": "object", |
|
"required": ["user_id", "session_id", "messages", "timestamp"], |
|
"properties": { |
|
"user_id": { |
|
"bsonType": "objectId", |
|
"description": "Unique identifier for the user", |
|
}, |
|
"session_id": { |
|
"bsonType": "string", |
|
"description": "Identifier for the session", |
|
}, |
|
"timestamp": { |
|
"bsonType": "date", |
|
"description": "Timestamp when the chat session started", |
|
}, |
|
"messages": { |
|
"bsonType": "array", |
|
"description": "List of chat messages", |
|
"items": { |
|
"bsonType": "object", |
|
"properties": { |
|
"prompt": { |
|
"bsonType": "string", |
|
"description": "User's question or prompt", |
|
}, |
|
"response": { |
|
"bsonType": "string", |
|
"description": "Assistant's response", |
|
}, |
|
"timestamp": { |
|
"bsonType": "date", |
|
"description": "Timestamp of the message", |
|
}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
} |
|
|
|
|
|
|
|
chat_history_collection = db["chat_history"] |
|
|
|
|
|
|
|
|
|
research_assistant_schema = { |
|
"bsonType": "object", |
|
"required": ["full_name", "password", "email", "courses_assisted"], |
|
"properties": { |
|
"full_name": { |
|
"bsonType": "string", |
|
"description": "Full name of the research assistant", |
|
}, |
|
"password": { |
|
"bsonType": "string", |
|
"description": "Hashed password of the research assistant", |
|
}, |
|
"email": { |
|
"bsonType": "string", |
|
"description": "Email address of the research assistant", |
|
}, |
|
"courses_assisted": { |
|
"bsonType": "array", |
|
"description": "List of courses the research assistant is assisting", |
|
"items": { |
|
"bsonType": "object", |
|
"required": ["course_id"], |
|
"properties": { |
|
"course_id": { |
|
"bsonType": "string", |
|
"description": "ID of the course", |
|
} |
|
}, |
|
}, |
|
}, |
|
}, |
|
} |
|
|
|
|
|
research_assistants_collection = db["research_assistants"] |
|
|
|
|
|
research_assistants_collection.create_index("full_name", unique=True) |
|
research_assistants_collection.create_index("email", unique=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|