Spaces:
Sleeping
Sleeping
| from config import initialize | |
| _, mongo_db_manager = initialize() | |
| if mongo_db_manager is None: | |
| print("Error: MongoDB initialization failed. Exiting.") | |
| exit(1) # Exit to prevent unwanted behavior | |
| collection_name = "questions" | |
| def insert_data(mongo_db_manager, collection_name, questions_data): | |
| """Insert data into MongoDB collection.""" | |
| """EXAMPLE of questions_data: | |
| questions_data = [ | |
| { | |
| "stage": "Survival and Growth", | |
| "strength": "Fairness", | |
| "rank": "High", | |
| "questions": [ | |
| "How do you make sure you treat people fairly when making decisions?", | |
| "Can you think of a time when being fair led to a positive outcome? What happened?", | |
| "How do you balance fairness and making tough choices, especially when not everyone agrees?" | |
| ] | |
| }, | |
| { | |
| "stage": "Survival and Growth", | |
| "strength": "Fairness", | |
| "rank": "Medium", | |
| "questions": [ | |
| "What does fairness mean to you, and how do you make sure you apply it in your daily life?", | |
| "Have you ever had to stand up for fairness in a difficult situation? How did you handle it?", | |
| "How can you balance being fair to everyone while still making decisions that help your team or group succeed?" | |
| ] | |
| }, | |
| { | |
| "stage": "Survival and Growth", | |
| "strength": "Fairness", | |
| "rank": "Low", | |
| "questions": [ | |
| "If fairness isn’t your strongest trait, what steps can you take to make sure your decisions are unbiased?", | |
| "Have you ever made a decision that others thought was unfair? What did you learn from the experience?", | |
| "How can you create simple habits or rules that help you treat people fairly in group settings?" | |
| ] | |
| } | |
| ] | |
| """ | |
| try: | |
| inserted_ids = mongo_db_manager.insert_many(collection_name, questions_data) | |
| print(f"Inserted document IDs: {inserted_ids}") | |
| return True | |
| except Exception as e: | |
| print(f"Error inserting data into MongoDB: {e}") | |
| return False | |
| def get_questions(collection_name, stage, strength, rank): | |
| return mongo_db_manager.get_questions(collection_name, stage, strength, rank) | |
| collection_name = "questions" | |
| stage = "Survival and Growth" | |
| strength = "Fairness" | |
| rank = "High" | |
| questions = get_questions(collection_name, stage, strength, rank) | |
| print(questions) |