def decode_course(self, course_dict):
        cr_json = course_dict.get('course_runs')
        course_runs = self.decode_course_runs(cr_json)
        dep_json = course_dict.get('department')
        department = self.decode_department(dep_json)
        evaluation_json = course_dict.get('evaluations')
        evaluations =  self.decode_evaluations(evaluation_json)

        course = Course(
            code = course_dict['code'],
            language = course_dict['language'],
            title_en = course_dict['title_en'],
            title_da = course_dict['title_da'],
            evaluation_type = course_dict['evaluation_type'],
            ects_credits = float(course_dict['ects_credits'].replace(",", ".")),
            course_type = course_dict['course_type'],
            department = department
        )
        for run in course_runs:
            course.add_course_run(run)

        for evaluation in evaluations:
            course.add_evaluation(evaluation)

        return course
Ejemplo n.º 2
0
    def get_student_enrollment(self, student, term):
        sql_select_enroll = """
                            SELECT enrollid, ENROLLMENTS.classid, status,
                                   section, room, location,
                                   INSTRUCTORS.idno, lastname, firstname, middlename,
                                   COURSES.courseid, coursecode, COURSES.name, units, is_academic,
                                   classlimit
                            FROM ENROLLMENTS
                            JOIN CLASSES ON ENROLLMENTS.classid = CLASSES.classid
                            JOIN INSTRUCTORS ON instructor = INSTRUCTORS.idno
                            JOIN ROOMS ON room = roomid
                            JOIN COURSES ON CLASSES.courseid = COURSES.courseid
                            WHERE studentid = ? AND CLASSES.term = ?
                            ORDER BY coursecode
                            """

        cur = self.connection.cursor()
        cur.execute(sql_select_enroll, (student.get_id(), term))
        rows = cur.fetchall()
        return list(
            map(
                lambda row: Enrollment(
                    row[0], student,
                    Class(
                        row[1],
                        Course(row[10], row[11], row[12], row[13], row[14]),
                        row[3], term, None if row[6] == 0 else Instructor(
                            row[6], row[7], row[8], row[9]),
                        Room(row[4], row[5]), row[15]), row[2]), rows))
Ejemplo n.º 3
0
    def get_all_classes(self, term):
        sql_select_class = """
                           SELECT CLASSES.classid, section, idno, lastname, firstname, middlename, room, location, classlimit,
                                  COURSES.courseid, coursecode, name, units, is_academic, COUNT(enrollid)
                           FROM CLASSES
                           LEFT JOIN ENROLLMENTS ON ENROLLMENTS.classid = CLASSES.classid
                           JOIN INSTRUCTORS ON instructor = idno
                           JOIN ROOMS ON room = roomid
                           JOIN COURSES ON CLASSES.courseid = COURSES.courseid
                           WHERE term = ?
                           GROUP BY CLASSES.classid
                           HAVING COUNT(enrollid) < classlimit
                           ORDER BY coursecode, section
                           """

        cur = self.connection.cursor()
        cur.execute(sql_select_class, (term, ))
        rows = cur.fetchall()
        return list(
            map(
                lambda row: (Class(
                    row[0],
                    Course(row[9], row[10], row[11], row[12], row[13] != 0),
                    row[1], term, None
                    if row[2] == 0 else Instructor(row[2], row[3], row[4], row[
                        5]), Room(row[6], row[7]), row[8]), 0
                             if row[14] is None else row[14]), rows))
Ejemplo n.º 4
0
 def new_course(self, coursecode, name, units, is_academic):
     cur = self.connection.cursor()
     cur.execute(
         "INSERT INTO COURSES (coursecode, name, units, is_academic) VALUES (?, ?, ?, ?)",
         (coursecode, name, units, 1 if is_academic else 0))
     self.connection.commit()
     return Course(cur.lastrowid, coursecode, name, units, is_academic)
Ejemplo n.º 5
0
def test3():
    print("Test 3:")
    michael = User("Michael", Schedule())
    michael.schedule.add_course(
        Course("CSCI140", EventTime(("Mon", "Wed", "Fri"), 1200, 1400), "GOL"))
    print(michael.schedule.courses["CSCI140"].time.in_time(1300))  # True
    michael.schedule.add_event(Event("Skate", EventTime(("Mon"), 1800, 1900)))
    print(michael)
Ejemplo n.º 6
0
 def get_courses(self):
     cur = self.connection.cursor()
     cur.execute(
         "SELECT courseid, coursecode, name, units, is_academic FROM COURSES ORDER BY coursecode"
     )
     rows = cur.fetchall()
     return list(
         map(lambda row: Course(row[0], row[1], row[2], row[3], row[4]),
             rows))
Ejemplo n.º 7
0
 def get_course(self, coursecode):
     cur = self.connection.cursor()
     cur.execute(
         "SELECT courseid, name, units, is_academic FROM COURSES WHERE coursecode = ?",
         (coursecode, ))
     row = cur.fetchone()
     if row is not None:
         return Course(row[0], coursecode, row[1], row[2], row[3] == 1)
     else:
         return None
Ejemplo n.º 8
0
def test_student_enrollment_quiz_taking_and_grading(quiz1, quiz2):
    teacher_sam = Teacher(1, "Sam", "Doe")
    student1 = Student(1, "Joe", "Bar")
    course = Course("MATH_101", 4)
    spring_2003_math_101 = course.add_class("SPRING", 2003, teacher_sam)
    student1.enroll(spring_2003_math_101)

    spring_2003_math_101.assign_quiz(quiz1)
    spring_2003_math_101.assign_quiz(quiz2)

    student1.answer_quiz(spring_2003_math_101, 1, 1, ['A'])
    student1.answer_quiz(spring_2003_math_101, 1, 2, ['B'])
    student1.answer_quiz(spring_2003_math_101, 2, 1, ['A'])
    student1.answer_quiz(spring_2003_math_101, 2, 2, ['A'])

    student1.grade_quiz(spring_2003_math_101, 1) == 100.0
    student1.grade_quiz(spring_2003_math_101, 2) == 50.0

    assert student1.accumulate_grade(spring_2003_math_101) == 75.0
Ejemplo n.º 9
0
def we_have_the_following_courses(context):
    courses = {}
    for row in context.table:
        course_name = row['course_name']
        credit = row['credit']
        courses[course_name] = Course(course_name, credit)
    context.courses = courses
    for value in courses.values():
        print(str(value))
    pass
Ejemplo n.º 10
0
    def decode_course(self, course_dict):
        cr_json = course_dict.get("course_runs")
        course_runs = self.decode_course_runs(cr_json)
        dep_json = course_dict.get("department")
        department = self.decode_department(dep_json)

        course = Course(
            code=course_dict["code"],
            language=course_dict["language"],
            title_en=course_dict["title_en"],
            title_da=course_dict["title_da"],
            evaluation_type=course_dict["evaluation_type"],
            ects_credits=course_dict["ects_credits"],
            course_type=course_dict["course_type"],
            department=department,
        )
        for run in course_runs:
            course.add_course_run(run)

        return course
Ejemplo n.º 11
0
 def create_course_from_dict(course_dict):
     try:
         course = Course(course_dict['course_name'],
                         course_dict['professor_first_name'],
                         course_dict['professor_last_name'],
                         course_dict['location'],
                         course_dict["creation_time"],
                         course_dict["last_update_time"])
         return course
     except Exception as e:
         print(e)
Ejemplo n.º 12
0
    def new_class(self, course: Course, section, term, room, classlimit):
        sql_create_class = """
                           INSERT INTO CLASSES (courseid, section, term, instructor, room, classlimit)
                           VALUES (?, ?, ?, ?, ?, ?)
                           """

        cur = self.connection.cursor()
        cur.execute(
            sql_create_class,
            (course.get_id(), section, term, 0, room.get_id(), classlimit))
        self.connection.commit()
        return Class(cur.lastrowid, course, section, term, None, room,
                     classlimit)
Ejemplo n.º 13
0
 def set_user_courses(self):
     """ Gets and sets the user's courses
     ---
         Sends a GET request using core_enrol_get_users_courses to retrieve
         the courses that the user is enrolled in.
     """
     url = self.__url_with_token + 'core_enrol_get_users_courses&userid=' + self.get_user(
     ).get_id()
     r = requests.get(url).json()
     self.__user_courses = []
     for course in r:
         course = Course(course)
         self.__user_courses.append(course)
         self.get_user().set_course(course)
Ejemplo n.º 14
0
def __add_new_courses(conn: Connection, state: Config,
                      courses: Dict[int, str]) -> list:
    """
    This function is responsible for finding new courses, adding them to the DB and downloading them if the user wants
    :param state: The current moodle state
    :param courses: List of all the courses. The id is the key, and the shortname the value
    :return: A list of the new courses ids
    """
    # Check for new courses and store them
    new_courses = __check_courses_differences(state, courses.keys())

    # Add the new courses to the state and stored them in the DB
    for c_id in new_courses:
        # Create the course and populate ir
        course = Course(c_id, courses[c_id],
                        state.default_action == "download")
        content = get_course_contents(state, c_id)
        course.read_json_contents(content)
        state.add_course(course)

        # DB
        insert_course(conn, course, state.id)

    # Download the courses or notify
    if state.default_action == 'notify':
        # Notify
        logging.warning(
            "New courses were found, please check which contents you want to download."
        )
    elif state.default_action == 'download':
        # Download
        logging.info("Downloading")
        for course_key in state.courses:
            course = state.courses[course_key]
            download_course(course, state)
    return new_courses
Ejemplo n.º 15
0
def populate_config(conn: Connection, config: Config):
    """
    This function is responsible for adding the already present courses to the config.
    THIS FUNCTION MUTATES THE config PARAM
    :param conn: DB connection
    :param config: Moodle configuration
    """
    rows = get_config_courses(conn, config.id)

    # Create the courses and populate each one
    # TODO test this code
    for row in rows:
        course = Course.create_from_db(row)

        # Create the sections and populate each one
        rows_sections = get_course_sections(conn, config.id, course.id)

        for r_section in rows_sections:
            section = Section.create_from_db(r_section)

            # Add the LinkableContents
            section.modules = __get_linkablecontents(conn, config.id,
                                                     section.id, True)

            # Create the modules, populate each one and add them to the section
            rows_modules = get_section_modules(conn, config.id, section.id)
            for r_module in rows_modules:
                module = Module.create_from_db(r_module)

                # Add the LinkableContents
                module.contents = __get_linkablecontents(
                    conn, config.id, module.id, False)

                # Add the Files
                rows_files = get_module_files(conn, config.id, module.id)

                for r_file in rows_files:
                    module.add_content(
                        File.create_file_or_linkablecontent(r_file))

                # Add the module to the section
                section.add_module(module)

            # Add the section to the course
            course.add_section(section)

        # Add the course to the config
        config.add_course(course)
Ejemplo n.º 16
0
def test2():
    print("Test 2:")
    reynaldo = User("Reynaldo", Schedule())
    reynaldo.schedule.add_course(
        Course("CSCI141", EventTime(("Mon"), 1000, 1200), "GOL"))
    print(reynaldo)
Ejemplo n.º 17
0
 def create_course(self, course_name, course_price, course_time):
     course = Course(course_name, course_price, course_time)
     self.school_course[course_name] = course
Ejemplo n.º 18
0
async def on_message(message):
    if message.content.startswith('!'):
        split_message = message.content.split()
        command = split_message[0][1:]
        args = []
        if len(split_message) > 1:
            args = split_message[1:]

        if command == 'help':
            await respond(
                message.channel, "__**Available Commands**__:\n%s" % (''.join(
                    ['**%s**: %s\n' % (k, v) for k, v in commands.items()])))

        elif command == 'info':
            if message.author.id in data.db['users']:
                await respond(message.channel,
                              data.db['users'][message.author.id])
            else:
                await respond(message.channel, "You're not registered")

        elif command == 'register':
            if message.author.id not in data.db['users']:
                data.add_user(message.author.id, message.author.name)
                data.write_data()
                await respond(message.channel, "Registration successful.")
            else:
                await respond(message.channel, "You're already registered.")

        elif command == 'unregister':
            if message.author.id in data.db["users"]:
                data.db['users'].pop(message.author.id)
                data.write_data()
                await respond(message.channel, "Unregistered successfully.")
            else:
                await respond(message.channel, "You're not registered.")

        elif command == 'addcourse':
            if len(args) == 3:
                if message.author.id in data.db['users'] and args[
                        1] not in data.db['users'][
                            message.author.id].schedule.courses:
                    course_time = EventTime(set())
                    course_time.parse_input(args[1])
                    data.db['users'][message.author.id].schedule.add_course(
                        Course(args[0], course_time, args[2]))
                    data.write_data()
                    await respond(message.channel,
                                  "Course added successfully.")
                else:
                    await respond(message.channel, "You're not registered.")
            else:
                await respond(
                    message.channel,
                    "Usage: `!addcourse <id> <time> <place>`\nExample: !addcourse CSCI140 MWF12P2P GOL"
                )

        elif command == 'removecourse':
            if len(args) == 1:
                if args[0] in data.db['users'][
                        message.author.id].schedule.courses:
                    data.db['users'][message.author.id].schedule.remove_course(
                        args[0])
                    data.write_data
                    await respond(message.channel,
                                  "Course successfully removed.")
                else:
                    await respond(message.channel,
                                  "Course is not in your schedule.")
            else:
                await respond(message.channel, "Usage `!removecourse <id>`")

        elif command == 'clearcourses':
            if message.author.id in data.db['users']:
                data.db['users'][message.author.id].schedule.clear_courses()
                await respond(message.channel, "Courses cleared successfully.")
            else:
                await respond(message.channel, "You're not registered.")

        elif command == 'addevent':
            if len(args) == 2:
                if message.author.id in data.db['users']:
                    event_time = EventTime(set())
                    event_time.parse_input(args[1])
                    data.db['users'][message.author.id].schedule.add_event(
                        Event(args[0], event_time))
                    data.write_data()
                    await respond(message.channel, "Event added successfully.")
                else:
                    await respond(message.channel, "You're not registered.")
            else:
                await respond(message.channel,
                              "Usage: `!addevent <name> <time>`")

        elif command == 'removeevent':
            if len(args) == 1:
                if args[0] in data.db['users'][
                        message.author.id].schedule.events:
                    data.db['users'][message.author.id].schedule.remove_event(
                        args[0])
                    data.write_data
                    await respond(message.channel,
                                  "Event successfully removed.")
                else:
                    await respond(message.channel,
                                  "Event is not in your schedule.")
            else:
                await respond(message.channel, "Usage: `!removeevent <name>`")

        elif command == 'clearevents':
            if message.author.id in data.db['users']:
                data.db['users'][message.author.id].schedule.clear_events()
                await respond(message.channel, "Events cleared successfully.")
            else:
                await respond(message.channel, "You're not registered.")

        elif command == 'clearschedule':
            if message.author.id in data.db['users']:
                data.db['users'][message.author.id].schedule.clear_schedule()
                await respond(message.channel,
                              "Schedule cleared successfully.")
            else:
                await respond(message.channel, "You're not registered.")

        elif command == 'free':
            current_time = time.asctime(time.localtime(time.time()))
            # day = current_time[:3]
            statuses = '__**Free Users**__\n'
            free_people = []
            for user in data.db['users']:
                if not data.db['users'][user].is_busy(
                        int(current_time.split()[3].replace(':', '')[:4])):
                    free_people.append(data.db['users'][user].name)

            for person in free_people:
                statuses += person + '\n'

            await respond(message.channel, statuses)

        else:
            await respond(
                message.channel,
                "Command wasn't recognized. Use !help to see available commands."
            )
Ejemplo n.º 19
0
    def __init__(self):
        self.students = {}

        #add to student dictionary
        s = Student(1, "Carson", "Alexander", "09012005")
        self.students[s.student_id] = s
        s = Student(2, "Meredith", "Alonso", "09022002")
        self.students[s.student_id] = s
        s = Student(3, "Arturo", "Anand", "09032003")
        self.students[s.student_id] = s
        s = Student(4, "Gytis", "Barzdukas", "09012001")
        self.students[s.student_id] = s
        s = Student(5, "Peggy", "Justice", "09012001")
        self.students[s.student_id] = s
        s = Student(6, "Laura", "Norman", "09012003")
        self.students[s.student_id] = s
        s = Student(7, "Nino", "Olivetto", "09012005")
        self.students[s.student_id] = s

        self.professors = {}

        #professor_id   first_name   last_name  hire_date
        p = Professor(1, "Kim", "Abercrombie", "1995-03-11")
        self.professors[p.professor_id] = p

        p = Professor(2, "Fadi", "Fakhouri", "2002-07-06")
        self.professors[p.professor_id] = p

        p = Professor(3, "Roger", "Harui", "1998-07-01")
        self.professors[p.professor_id] = p

        p = Professor(4, "Candace", "Kapoor", "2001-01-15")
        self.professors[p.professor_id] = p

        p = Professor(5, "Roger", "Zheng", "2004-02-12")
        self.professors[p.professor_id] = p

        self.courses = {}

        #add to course dictionary
        c = Course(1050, "Chemistry", 3, self.professors[1])
        self.courses[c.course_id] = c
        c = Course(4022, "Microeconomics", 3, self.professors[3])
        self.courses[c.course_id] = c
        c = Course(4041, "Macroeconomics", 3, self.professors[3])
        self.courses[c.course_id] = c
        c = Course(1045, "Calculus", 4, self.professors[4])
        self.courses[c.course_id] = c
        c = Course(3141, "Trigonometry", 4, self.professors[4])
        self.courses[c.course_id] = c
        c = Course(2021, "Composition", 3, self.professors[2])
        self.courses[c.course_id] = c
        c = Course(2042, "Literature", 4, self.professors[5])
        self.courses[c.course_id] = c

        self.enrollments = {}

        #add enrolled students into courses
        enroll_id = 11050  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[1],
                                self.courses[1050])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 14022  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[1],
                                self.courses[4022])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 14041  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[1],
                                self.courses[4041])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 21045  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[2],
                                self.courses[1045])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 23141  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[2],
                                self.courses[3141])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 22021  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[2],
                                self.courses[4041])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 31050  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[3],
                                self.courses[1050])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 41050  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[4],
                                self.courses[1050])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 44022  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[4],
                                self.courses[4022])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 54041  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[5],
                                self.courses[2021])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 61045  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[6],
                                self.courses[1045])
        self.enrollments[enroll_id] = enrollment

        enroll_id = 73141  #combine student id + chemistry id
        enrollment = Enrollment(enroll_id, self.students[7],
                                self.courses[3141])
        self.enrollments[enroll_id] = enrollment