def load_database():
    '''
    Initialize all objects stored in data/..
    Close program if there is not enough database to function properly.

    Parameters, Returns: None

    Initialize:
        Student objs.
        Mentor objs.
        Employee objs.
        Manager objs.
        Assigments objs.
        Logins.list_of_logins
    '''
    Assignment.get_assignments_from_file('assignments.csv')
    Attendance.get_attendance_from_file('attendance.csv')
    Student.get_codecoolers_from_file('students.csv')
    Employee.get_codecoolers_from_file('employees.csv')
    Mentor.get_codecoolers_from_file('mentors.csv')
    Manager.get_codecoolers_from_file('managers.csv')

    if len(Manager.list_of_managers) < 1 or len(
            Employee.list_of_employees) < 1:
        err_msg = 'There is no database stored. Contact our support at [email protected]'
        view.print_message(err_msg)
        sys.exit()

    Logins.from_codecoolers(Student.list_of_students,
                            Employee.list_of_employees,
                            Manager.list_of_managers, Mentor.list_of_mentors)
def update_attendance(option, student, attendance_list):
    '''
    Updates the attendance list and saves to file.

    Args:
        option (int) - option choosed from menu
        student (Student obj)
        attendance_list (class Attendance list)
    '''
    today_attendance = get_today_attendance(option)
    attendance = Attendance(student.login, datetime.date.today(),
                            today_attendance)
    attendance_list.append(attendance)
    attendance.save_attendance_to_file('attendance.csv')
示例#3
0
def get_raw_data():

    # Get the HTML & Parse it
    response = requests.get(os.environ['EQDKP_URL'] + 'index.php/Points')
    raw_html = BeautifulSoup(response.text, 'html.parser')
    overview_table_html = raw_html.find(name='table', class_='hptt')
    player_data_html = overview_table_html.find_all(
        name='span',
        attrs={'positive', 'negative', 'neutral',
               re.compile('class_*')})
    player_data_raw = [data.string for data in player_data_html]
    n = len(EQDKP_COLUMNS)
    data_by_player = [
        player_data_raw[i:i + n] for i in range(0, len(player_data_raw), n)
    ]

    # Create the DataFrame
    df = pd.DataFrame(data_by_player, columns=EQDKP_COLUMNS)

    # Convert DKP & Attendance columns
    df[ATTENDANCE_COLUMNS] = df[ATTENDANCE_COLUMNS].applymap(
        lambda x: Attendance(x))
    df['DKP'] = df['DKP'].apply(lambda x: float(x))

    # Apply default sorting and dkp ranking columns
    df = order_df(df, DEFAULT_ORDER)
    df.insert(loc=3, column='DKP RANK', value=df.index)

    return df
def create():
    gym_class = gym_class_repository.select(request.form["class_id"])
    member = member_repository.select(request.form["member_id"])

    attendance = Attendance(gym_class, member)
    attendance_repository.save(attendance)

    return redirect(f'/classes/{gym_class.id}')
def clean_attendance_data():
    '''
    Eliminates all duplicate or outdated attendances (i.e. after removing students)
    '''
    attendances = Attendance.list_of_attendance
    atts_to_remove = []

    for attendance in attendances:
        if attendance.student_login not in [
                student.login for student in Student.list_of_students
        ]:
            atts_to_remove.append(attendance)

    for att in atts_to_remove:
        attendances.remove(att)

    remove_duplicates(attendances)

    Attendance.overwrite_file('attendance.csv')
def select(id):
    sql = "SELECT * FROM attendees WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)

    if result is not None:
        gym_class = gym_class_repository.select(result[0]["class_id"])
        member = member_repository.select(result[0]["member_id"])
        attendance = Attendance(gym_class, member, id)

    return attendance
def select_by_fitness_class(fitness_class):
    sql = "SELECT * FROM attendance WHERE fitness_class_id = %s"
    values = [fitness_class.id]
    results = run_sql(sql, values)
    attendance_list = []
    for row in results:
        member = member_repo.select(row['member_id'])
        fitness_class = fitness_class_repo.select(row['fitness_class_id'])
        attendance = Attendance(fitness_class, member, row['id'])
        attendance_list.append(attendance)
    return attendance_list
def select(id):
    attendance = None
    sql = "SELECT * FROM attendance WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        member = member_repo.select(result['member_id'])
        fitness_class = fitness_class_repo.select(result['fitness_class_id'])
        attendance = Attendance(fitness_class, member, result['id'])
    return attendance
def select_all():
    attendance_list = []
    sql = "SELECT * FROM attendance"
    results = run_sql(sql)

    for row in results:
        member = member_repo.select(row['member_id'])
        fitness_class = fitness_class_repo.select(row['fitness_class_id'])
        attendance = Attendance(fitness_class, member, row['id'])
        attendance_list.append(attendance)
    return attendance_list
def select_all():
    all_attendances = []
    sql = "SELECT * FROM attendees"
    results = run_sql(sql)

    for result in results:
        gym_class = gym_class_repository.select(result["class_id"])
        member = member_repository.select(result["member_id"])
        attendance = Attendance(gym_class, member, id)
        all_attendances.append(attendance)

    return all_attendances
def select_by_class(gym_class):
    attendees = []
    sql = "SELECT * FROM attendees WHERE class_id = %s"
    values = [gym_class.id]
    results = run_sql(sql, values)

    for result in results:
        gym_class = gym_class_repository.select(result["class_id"])
        member = member_repository.select(result["member_id"])
        attendance = Attendance(gym_class, member, result["id"])
        attendees.append(attendance)

    return attendees
示例#12
0
def update():
    found_member = member_repo.select(request.form['member_id'])
    found_fitness_class = fitness_class_repo.select(
        request.form['fitness_class_id'])
    # verify there is availability on the class if for some reason the user manages to get this far
    calc_availability = found_fitness_class.capacity - len(
        attendance_repo.select_by_fitness_class(found_fitness_class))
    if calc_availability > 0:
        attendance = Attendance(found_fitness_class, found_member)
        attendance_repo.save(attendance)
    else:
        return render_template('/errors/405.html'), 405
    return redirect('/classes/' + str(found_fitness_class.id))
member_repo.save(member3)
member4 = Member('James', 'Holden', 'standard', '2019/06/13', 'EH7 9DE', '07538472658', '*****@*****.**')
member_repo.save(member4)
member5 = Member('Gary', 'McDonald', 'standard', '2021/01/14', 'EH15 7ST', '07695844449', '*****@*****.**')
member_repo.save(member5)

fitness_class1 = FitnessClass('Body Attack', trainer2, location1, '2021/03/10', '13:00', 20)
fitness_class_repo.save(fitness_class1)
fitness_class2 = FitnessClass('HIIT', trainer1, location3, '2021/03/10', '17:00', 30)
fitness_class_repo.save(fitness_class2)
fitness_class3 = FitnessClass('Zumba', trainer1, location1, '2021/03/10', '18:15', 35)
fitness_class_repo.save(fitness_class3)
fitness_class4 = FitnessClass('Yoga', trainer2, location2, '2021/03/10', '07:00', 20)
fitness_class_repo.save(fitness_class4)

attendance1 = Attendance(fitness_class1, member2)
attendance_repo.save(attendance1)
attendance2 = Attendance(fitness_class1, member3)
attendance_repo.save(attendance2)
attendance3 = Attendance(fitness_class1, member4)
attendance_repo.save(attendance3)
attendance4 = Attendance(fitness_class2, member2)
attendance_repo.save(attendance4)
attendance5 = Attendance(fitness_class2, member3)
attendance_repo.save(attendance5)
attendance6 = Attendance(fitness_class3, member5)
attendance_repo.save(attendance6)
attendance7 = Attendance(fitness_class4, member2)
attendance_repo.save(attendance7)
attendance8 = Attendance(fitness_class4, member1)
attendance_repo.save(attendance8)
示例#14
0
gym_class_repository.save(class_1)
gym_class_repository.save(class_2)
gym_class_repository.save(class_3)
gym_class_repository.save(class_4)
gym_class_repository.save(class_5)
gym_class_repository.save(class_6)
gym_class_repository.save(class_7)
gym_class_repository.save(class_8)
gym_class_repository.save(class_9)
gym_class_repository.save(class_10)
gym_class_repository.save(class_11)
gym_class_repository.save(class_12)
gym_class_repository.save(class_13)

attendance_1 = Attendance(class_1, member_1)
attendance_2 = Attendance(class_2, member_2)
attendance_3 = Attendance(class_3, member_4)
attendance_4 = Attendance(class_4, member_8)
attendance_5 = Attendance(class_5, member_6)
attendance_6 = Attendance(class_6, member_8)
attendance_7 = Attendance(class_7, member_8)
attendance_8 = Attendance(class_8, member_9)
attendance_9 = Attendance(class_9, member_10)
attendance_10 = Attendance(class_10, member_15)
attendance_11 = Attendance(class_11, member_14)
attendance_12 = Attendance(class_12, member_13)
attendance_13 = Attendance(class_13, member_12)
attendance_14 = Attendance(class_12, member_16)
attendance_15 = Attendance(class_11, member_12)
attendance_16 = Attendance(class_13, member_10)