def get_filter_values(table, column): if table == 'groups': values = MongoDBConnection.get_groups_collection().distinct(column) elif table == 'students': values = MongoDBConnection.get_students_collection().distinct(column) elif table == 'test': values = MongoDBConnection.get_tests_collection().distinct(column) elif table == 'saved_state': values = MongoDBConnection.get_saved_state_collection().distinct( column) elif table == 'games': values = MongoDBConnection.get_games_collection().distinct(column) elif table == 'chapters': values = MongoDBConnection.get_chapters_collection().distinct(column) elif table == 'events': values = MongoDBConnection.get_events_collection().distinct(column) elif table == 'decisions': values = MongoDBConnection.get_decisions_collection().distinct(column) try: values = list(map(int, values)) return [min(values), max(values)] except: return values
def get_student_and_group(student_code: str) -> dict: db = MongoDBConnection.get_students_collection() cursor = db.aggregate([{ "$match": { "studentCode": student_code } }, { "$lookup": { "from": "groups", "localField": "groupCode", "foreignField": "groupCode", "as": "group" } }, { "$unwind": "$group" }, { "$project": { "_id": 0, "studentCode": 1, "sex": 1, "age": 1, "country": "$group.country", "city": "$group.city", "groupCode": "$group.groupCode" } }]) return list(cursor)[0] if cursor is not None else None
def get_student_filter_values(student_ids: List[str], column: str) -> List[str]: db = MongoDBConnection.get_students_collection() return db.find({ 'studentCode': { '$in': student_ids } }, { '_id': 0, column: 1 }).distinct(column)
def student_exists(studentCode: str) -> bool: db = MongoDBConnection.get_students_collection() return db.find_one({'studentCode': studentCode}) is not None
def get_game_countries(game_code, version, students): db = MongoDBConnection.get_students_collection() groups = db.find({"studentCode": {"$in": students}}).distinct('groupCode') db = MongoDBConnection.get_groups_collection() return db.find({"groupCode": {"$in": groups}}).distinct('country')
def get_students_pass_filter(query: dict) -> List[str]: db = MongoDBConnection.get_students_collection() return db.find(query, {'studentCode': 1}).distinct('studentCode')
def get_students_in_groups(group_ids: List[str]) -> pymongo.cursor.Cursor: db = MongoDBConnection.get_students_collection() return db.find({'groupCode': {'$in': group_ids}})
def get_student(student_code): student = MongoDBConnection.get_students_collection().find_one( {'studentCode': student_code}) return student