Esempio n. 1
0
def upload_instructors(teacher: dict):

    Mon = dbtools.minute_range(teacher["Monday"])
    Tue = dbtools.minute_range(teacher["Tuesday"])
    Wed = dbtools.minute_range(teacher["Wednesday"])
    Thurs = dbtools.minute_range(teacher["Thursday"])
    Fri = dbtools.minute_range(teacher["Friday"])

    Schedule = defaultdict(list)

    if Mon != None:
        Schedule[1].append(Mon)
    if Tue != None:
        Schedule[2].append(Tue)
    if Wed != None:
        Schedule[3].append(Wed)
    if Thurs != None:
        Schedule[4].append(Thurs)
    if Fri != None:
        Schedule[5].append(Fri)

    teacher_info = {
        "Name": teacher["Name"],
        "Gender": teacher["Gender"],
        "Ethnicity": teacher["Ethnicity"],
        "Region": teacher["Region"],
        "University": teacher["University"],
        "Year": teacher["Year"],
        "PreviousMentor": teacher["PreviousMentor"],
        "Car": teacher["Car"],
        "Languages": teacher["Languages"],
        "ShirtSize": teacher["ShirtSize"],
        "MultipleDays": teacher["MultipleDays"],
        "Schedule": Schedule
    }

    db = dfsapi.get_db()

    for p in teacher['Program']:
        if teacher['New']:
            latest = str(calendar.timegm(time.gmtime()))
            db.child(p).child("instructors").child(latest).child(
                teacher_info['Name']).set(teacher_info)
        else:
            timestamps = db.child(p).child("instructors").shallow().get()
            if timestamps.val() != None:
                latest = max(timestamps.val())
                db.child(p).child("instructors").child(latest).child(
                    teacher_info['Name']).set(teacher_info)

        db.child("instructors").child(teacher_info['Name']).set(teacher_info)

    for p in teacher['Program']:
        keys = db.child(p).child("instructors").shallow().get()
        if keys.val() != None:
            db_length = len(keys.val())
            if db_length > 10:
                oldest = min(keys.val())
                db.child(p).child("instructors").child(oldest).remove()
    return
Esempio n. 2
0
def upload_program(program: dict):
    db = dfsapi.get_db()

    season = program["Season"]
    del program["Season"]

    db.child(season).child("programs").child(program["name"]).update(program)
Esempio n. 3
0
def available_moves(program: str, teacher: str):
    db = dfsapi.get_db()
    valid_program = db.child(program).get()
    if valid_program.val() != None:

        timestamps = db.child(program).child("matches")
        latest = max(timestamps.shallow().get().val())

        removed_instructor = db.child(program).child("matches").child(
            latest).child("Removed").child(teacher).get().val()
        available_schools = db.child(program).child("matches").child(
            latest).child("Available").get().val()

        if removed_instructor != None and available_schools != None:
            instructor = make_instructor(removed_instructor)
            institutions = make_institution_list(available_schools, program)

            possible_moves = match_schools_to_instructor(
                instructor, institutions)
            school_weights = make_weights_dict(possible_moves)

            school_options = find_best_match(possible_moves, school_weights)

            return school_options
    return False
Esempio n. 4
0
def resort():
    sortparams = request.get_json()
    print("RP")
    print(sortparams)
    season = sortparams['Season']
    locked_instructors = sortparams["Locked"]

    db = dfsapi.get_db()
    # Get all schools
    schools_data = db.child(season).child("schools").get().val()
    # Get all instructors
    instructors_data = db.child(season).child("instructors").get().val()
    # Get all programs
    programs_data = db.child(season).child("programs").get().val()

    distance_data = dict()
    region_set = {
        instructors_data[instr]['region'][0]
        for instr in instructors_data
    }
    for school in schools_data:
        distance_data[school] = distance_between(
            list(region_set), schools_data[school]['address'])

    response = dict()
    for program in programs_data:
        response.update(
            optimal_sort.optimal_resort(locked_instructors, schools_data,
                                        instructors_data, distance_data,
                                        program))
    return dumps(response)
Esempio n. 5
0
def read_institutions(program:str):
	db = dfsapi.get_db()

	institutions = list()

	keys = db.child(program).child("institutions").shallow().get()

	if keys.val() == None:
		return False

	recentdb = max(keys.val())

	data = db.child(program).child("institutions").child(recentdb).get()

	for i in data.each():
		institution = i.val()

		Name = institution["Name"]
		Address = institution["Address"]
		County = institution["County"]
		Instructors = institution["Instructors"]
		Schedule = manageinstructors.schedule_to_dict(institution["Schedule"])

		institutions.append(Institution(Name, Address, County, 
			Instructors, Schedule))

	return institutions
Esempio n. 6
0
def upload_matches(program: str):
    instructors = fbread.read_instructors(program)
    institutions = fbread.read_institutions(program)

    if instructors == False:
        return False
    if institutions == False:
        return False

    result = iassorter.sort(instructors, institutions)

    timestamp = str(calendar.timegm(time.gmtime()))
    db = dfsapi.get_db()

    keys = db.child(program).child("matches").shallow().get()
    if keys.val() != None:
        db_length = len(keys.val())
        if db_length > 10:
            oldest = min(keys.val())
            db.child(program).child("matches").child(oldest).remove()
            print("Here")

    json_matches = defaultdict(list)

    for school in result:
        for match in result[school]:
            match_dict = match_to_dict(match)
            json_matches[school].append(match_dict)
            db.child(program).child("matches").child(timestamp).child(
                school).child(match.teacher_name).set(match_dict)
            db.child(program).child("matches").child(timestamp).child(
                school).child(match.teacher_name).update({"Locked": False})

    return json_matches
Esempio n. 7
0
def upload_shirtsize(program: str):
    instructors = fbread.read_instructors(program)

    shirtsizes = getshirtsize(instructors)

    db = dfsapi.get_db()

    for shirt in shirtsizes:
        db.child(program).child("shirts").child(shirt).set(shirtsizes[shirt])
Esempio n. 8
0
def get_locked_instructors(program:str):
    db = dfsapi.get_db()
    keys = db.child(program).child("matches").shallow().get()

    if keys.val() != None:
        recentdb = max(keys.val())
        instructors = db.child(program).child("matches").child(recentdb).child("Locked").get()
        if instructors.val() != None:
            return instructors.val()

    return False
Esempio n. 9
0
def move_instructor(program: str, to_school: str, teacher: str):
    db = dfsapi.get_db()
    valid_program = db.child(program).get()
    if valid_program.val() != None:
        timestamps = db.child(program).child("matches").shallow().get()
        latest = max(timestamps.val())
        removed_teacher = db.child(program).child("matches").child(
            latest).child("Removed").child(teacher).get().val()
        available_school = db.child(program).child("matches").child(
            latest).child("Available").child(to_school).get().val()
        existing_instructors = len(
            db.child(program).child("matches").child(latest).child(
                to_school).shallow().get().val())
        print("Here")
        print(existing_instructors)
        if removed_teacher != None and available_school != None:
            match_info = {
                "Car": removed_teacher['Car'],
                "Ethnicity": removed_teacher['Ethnicity'],
                "Gender": removed_teacher['Gender'],
                "Instructors":
                available_school['Instructors'] + existing_instructors,
                "Languages": removed_teacher['Languages'],
                "Locked": removed_teacher['Locked'],
                "MultipleDays": removed_teacher['MultipleDays'],
                "PreviousMentor": removed_teacher['PreviousMentor'],
                "Region": removed_teacher['Region'],
                "Schedule": available_school['Schedule'],
                "SchoolAddress": available_school['Address'],
                "SchoolCounty": available_school['County'],
                "SchoolName": available_school['Name'],
                "ShirtSize": removed_teacher['ShirtSize'],
                "TeacherName": removed_teacher['Name'],
                "TeacherSchedule": removed_teacher['Schedule'],
                "University": removed_teacher['University'],
                "Year": removed_teacher['Year'],
            }

            db.child(program).child("matches").child(latest).child(
                to_school).child(teacher).set(match_info)
            db.child(program).child("matches").child(latest).child(
                "Removed").child(teacher).remove()
            required_instructors = int(available_school["Instructors"]) - 1
            if required_instructors <= 0:
                db.child(program).child("matches").child(latest).child(
                    "Available").child(to_school).remove()
            else:
                db.child(program).child("matches").child(latest).child(
                    "Available").child(to_school).update(
                        {"Instructors": required_instructors})

            return True
    return False
Esempio n. 10
0
def upload_instructor(instructor: dict):
    db = dfsapi.get_db()

    season = instructor["Season"]
    del instructor["Season"]

    #Set everything
    instructor["programs"] = {
        k: i + 1
        for i, k in enumerate(instructor["programs"])
    }
    ret = db.child(season).child("instructors").push(instructor)
    '''
Esempio n. 11
0
def remove_instructor(program: str, school: str, teacher: str):
    db = dfsapi.get_db()
    valid_program = db.child(program).get()
    if valid_program.val() != None:
        timestamps = db.child(program).child("matches").shallow().get()
        latest = max(timestamps.val())
        result = db.child(program).child("matches").child(latest).child(
            school).child(teacher).get().val()
        if result != None:
            available_school = db.child(program).child("matches").child(
                latest).child("Available").child(school).get().val()

            if available_school == None:
                school_info = {}
                school_info["Name"] = result["SchoolName"]
                school_info["Address"] = result["SchoolAddress"]
                school_info["County"] = result["SchoolCounty"]
                school_info["Instructors"] = 1
                school_info["Schedule"] = result["Schedule"]
                db.child(program).child("matches").child(latest).child(
                    "Available").child(school).set(school_info)
            elif int(available_school["Instructors"]) <= result["Instructors"]:
                instructors = available_school["Instructors"]
                new_instructors = int(instructors) + 1
                db.child(program).child("matches").child(latest).child(
                    "Available").child(school).update(
                        {"Instructors": new_instructors})

            teacher_info = {}
            teacher_info["Name"] = result["TeacherName"]
            teacher_info["Car"] = result["Car"]
            teacher_info["Ethnicity"] = result["Ethnicity"]
            teacher_info["Gender"] = result["Gender"]
            teacher_info["Languages"] = result["Languages"]
            teacher_info["Locked"] = result["Locked"]
            teacher_info["MultipleDays"] = result["MultipleDays"]
            teacher_info["PreviousMentor"] = result["PreviousMentor"]
            teacher_info["Region"] = result["Region"]
            teacher_info["Schedule"] = result["TeacherSchedule"]
            teacher_info["University"] = result["University"]
            teacher_info["Year"] = result["Year"]
            teacher_info["ShirtSize"] = result["ShirtSize"]

            db.child(program).child("matches").child(latest).child(
                "Removed").child(teacher).set(teacher_info)
            db.child(program).child("matches").child(latest).child(
                school).child(teacher).remove()

            return True

    return False
Esempio n. 12
0
def upload_institutions(school: dict):
    db = dfsapi.get_db()

    Mon = dbtools.minute_range(school["Monday"])
    Tue = dbtools.minute_range(school["Tuesday"])
    Wed = dbtools.minute_range(school["Wednesday"])
    Thurs = dbtools.minute_range(school["Thursday"])
    Fri = dbtools.minute_range(school["Friday"])

    Schedule = defaultdict(list)

    if Mon != None:
        Schedule[1].append(Mon)
    if Tue != None:
        Schedule[2].append(Tue)
    if Wed != None:
        Schedule[3].append(Wed)
    if Thurs != None:
        Schedule[4].append(Thurs)
    if Fri != None:
        Schedule[5].append(Fri)

    school_info = {
        "Name": school["Name"],
        "Address": school["Address"],
        "County": school["County"],
        "Instructors": school["Instructors"],
        "Schedule": Schedule
    }

    for p in school['Program']:
        if school['New']:
            latest = str(calendar.timegm(time.gmtime()))
            db.child(p).child("institutions").child(latest).child(
                school_info['Name']).set(school_info)
        else:
            timestamps = db.child(p).child("institutions").shallow().get()
            if timestamps.val() != None:
                latest = max(timestamps.val())
                db.child(p).child("institutions").child(latest).child(
                    school_info['Name']).set(school_info)
    db.child("institutions").child(school_info['Name']).set(school_info)

    for p in school['Program']:
        keys = db.child(p).child("institutions").shallow().get()
        if keys.val() != None:
            db_length = len(keys.val())
            if db_length > 10:
                oldest = min(keys.val())
                db.child(p).child("institutions").child(oldest).remove()
Esempio n. 13
0
def upload_instructors(filepath: str, program: str):
    db = dfsapi.get_db()
    workbook = xlrd.open_workbook(filepath)
    sheet = workbook.sheet_by_index(0)
    sheet.cell_value(0, 0)

    timestamp = str(calendar.timegm(time.gmtime()))

    for i in range(1, sheet.nrows):

        Name = sheet.cell_value(i, 0)
        Gender = sheet.cell_value(i, 1)
        Ethnicity = sheet.cell_value(i, 2)
        Region = sheet.cell_value(i, 3)
        University = sheet.cell_value(i, 4)
        Year = sheet.cell_value(i, 5)
        PreviousMentor = sheet.cell_value(i, 6)
        Car = sheet.cell_value(i, 7)
        Languages = sheet.cell_value(i, 8)
        ShirtSize = sheet.cell_value(i, 9)
        MultipleDays = sheet.cell_value(i, 10)
        Mon = sheet.cell_value(i, 11)
        Tue = sheet.cell_value(i, 12)
        Wed = sheet.cell_value(i, 13)
        Thur = sheet.cell_value(i, 14)
        Fri = sheet.cell_value(i, 15)

        teacher = {
            "Name": Name,
            "Gender": Gender,
            "Ethnicity": Ethnicity,
            "Region": Region,
            "University": University,
            "Year": Year,
            "PreviousMentor": PreviousMentor,
            "Car": Car,
            "Languages": Languages,
            "ShirtSize": ShirtSize,
            "MultipleDays": MultipleDays,
            "Monday": Mon,
            "Tuesday": Tue,
            "Wednesday": Wed,
            "Thursday": Thur,
            "Friday": Fri
        }

        #db.child(program).child(Name).set(teacher)
        db.child(program).child("instructors").child(timestamp).child(
            Name).set(teacher)
Esempio n. 14
0
def read_instructors(program: str):
    db = dfsapi.get_db()

    instructors = list()

    keys = db.child(program).child("instructors").shallow().get()
    recentdb = max(keys.val())

    data = db.child(program).child("instructors").child(recentdb).get()

    for i in data.each():
        instructor = i.val()

        Name = instructor["Name"]
        Gender = instructor["Gender"]
        Ethnicity = instructor["Ethnicity"]
        Region = instructor["Region"]
        University = instructor["University"]
        Year = instructor["Year"]
        PreviousMentor = instructor["PreviousMentor"]
        Car = instructor["Car"]
        Languages = instructor["Languages"]
        ShirtSize = instructor["ShirtSize"]
        MultipleDays = instructor["MultipleDays"]
        Mon = dbtools.minute_range(instructor["Monday"])
        Tue = dbtools.minute_range(instructor["Tuesday"])
        Wed = dbtools.minute_range(instructor["Wednesday"])
        Thurs = dbtools.minute_range(instructor["Thursday"])
        Fri = dbtools.minute_range(instructor["Friday"])

        Schedule = defaultdict(list)

        if Mon != None:
            Schedule[1].append(Mon)
        if Tue != None:
            Schedule[2].append(Tue)
        if Wed != None:
            Schedule[3].append(Wed)
        if Thurs != None:
            Schedule[4].append(Thurs)
        if Fri != None:
            Schedule[5].append(Fri)

        instructors.append(
            Instructor(Name, Gender, Ethnicity, Region, University, Year,
                       PreviousMentor, Schedule, Car, Languages, ShirtSize,
                       MultipleDays))

    return instructors
Esempio n. 15
0
def resort_matches(program: str):
    fblocked = get_locked_instructors(program)

    if fblocked == False:
        return False

    if fblocked != None:
        locked = get_locked_matches(fblocked)
        print("Locked: " + str(locked))
        print("Program: " + program)
        result = iassorter.resort(locked, program)
        print("FBRESORT RESULT: ")
        print_result(result)
        db = dfsapi.get_db()
        timestamps = db.child(program).child("matches").shallow().get()
        latest = max(timestamps.val())
        print("LATEST TIMESTAMP VALUE: " + str(latest))
        timestamp = str(calendar.timegm(time.gmtime()))
        keys = db.child(program).child("matches").shallow().get()
        if keys.val() != None:
            db_length = len(keys.val())
            if db_length > 10:
                oldest = min(keys.val())
                db.child(program).child("matches").child(oldest).remove()
                print("Here")
        json_matches = defaultdict(list)
        for school in result:
            for match in result[school]:
                match_dict = match_to_dict(match)
                json_matches[school].append(match_dict)
                db.child(program).child("matches").child(timestamp).child(
                    school).child(match.teacher_name).set(match_dict)
                #db.child(program).child("matches").child(timestamp).child("Locked").child(school).child(match.teacher_name).set(fblocked)
        for institution in locked:
            for instructor in locked[institution]:
                print("INSTRUCTOR: ")
                db.child(program).child("matches").child(latest).child(
                    "Locked").child(institution).child(
                        instructor.teacher_name).update({"Locked": True})
                info = db.child(program).child("matches").child(latest).child(
                    institution).child(instructor.teacher_name).get()
                db.child(program).child("matches").child(timestamp).child(
                    "Locked").child(institution).child(
                        instructor.teacher_name).set(info.val())
        return json_matches
        #return fblocked
    else:
        return False
Esempio n. 16
0
def upload_school(school: dict):
    db = dfsapi.get_db()

    season = school["Season"]
    del school["Season"]

    # Set everything
    program_preference = {}
    school["programs"] = {k: 1 for k in school["programs"]}
    ret = db.child(season).child("schools").push(school)
    pk = ret["name"]
    # Add School to programs.
    if "programs" in school:
        programs_list = school["programs"]
        for program in programs_list:
            db.child(season).child("programs").child(program).child(
                "assigned_schools").child(pk).set(1)
Esempio n. 17
0
def read_institutions(program: str):
    db = dfsapi.get_db()

    institutions = list()

    keys = db.child(program).child("institutions").shallow().get()
    recentdb = max(keys.val())

    data = db.child(program).child("institutions").child(recentdb).get()

    for i in data.each():
        institution = i.val()

        Name = institution["Name"]
        Address = institution["Address"]
        County = institution["County"]
        Program = institution["Program"]
        Instructors = institution["Instructors"]

        Mon = dbtools.minute_range(institution["Monday"])
        Tue = dbtools.minute_range(institution["Tuesday"])
        Wed = dbtools.minute_range(institution["Wednesday"])
        Thurs = dbtools.minute_range(institution["Thursday"])
        Fri = dbtools.minute_range(institution["Friday"])

        Schedule = defaultdict(list)

        if Mon != None:
            Schedule[1].append(Mon)
        if Tue != None:
            Schedule[2].append(Tue)
        if Wed != None:
            Schedule[3].append(Wed)
        if Thurs != None:
            Schedule[4].append(Thurs)
        if Fri != None:
            Schedule[5].append(Fri)

        institutions.append(
            Institution(Name, Address, County, Program, Instructors, Schedule))

    return institutions
Esempio n. 18
0
def lock_instructor(program:str, teacher:str, school:str):
    db = dfsapi.get_db()

    timestamps = db.child(program).child("matches").shallow().get()
    print("Timestamps: " + str(timestamps))
    print("Timestamps Value: " + str(timestamps.val()))

    if timestamps.val() != None:
        latest = max(timestamps.val())

        teachers = db.child(program).child("matches").child(latest).child(school).shallow().get()

        if teachers.val() != None and teacher in teachers.val():
            db.child(program).child("matches").child(latest).child(school).child(teacher).update({"Locked":True})
            info = db.child(program).child("matches").child(latest).child(school).child(teacher).get()
            db.child(program).child("matches").child(latest).child("Locked").child(school).child(teacher).set(info.val())

            return info.val()

    return False
Esempio n. 19
0
def upload_matches(program: str):

    instructors = fbread.read_instructors(program)
    institutions = fbread.read_institutions(program)

    result = iassorter.sort(instructors, institutions)

    timestamp = str(calendar.timegm(time.gmtime()))

    db = dfsapi.get_db()

    json_matches = defaultdict(list)

    for school in result:
        for match in result[school]:
            match_dict = match_to_dict(match)
            json_matches[school].append(match_dict)
            db.child(program).child("matches").child(timestamp).child(
                school).child(match.teacher_name).set(match_dict)

    return json_matches
Esempio n. 20
0
def unlock_instructor(program:str, teacher:str, school:str):
    db = dfsapi.get_db()

    timestamps = db.child(program).child("matches").shallow().get()
    print("Timestamps: " + str(timestamps))
    print("Timestamps Value: " + str(timestamps.val()))
    #for key,val in timestamps.items():
        #print("Key: " + str(key) + " Value: " + str(val))

    if timestamps.val() != None:
        latest = max(timestamps.val())
        print("Timestamp Value: " + str(latest))

        locked_teachers = db.child(program).child("matches").child(latest).child("Locked").child(school).shallow().get()
        print("Locked Teachers Value: " + str(locked_teachers.val()))

        if locked_teachers.val() != None and teacher in locked_teachers.val():
            db.child(program).child("matches").child(latest).child(school).child(teacher).update({"Locked":False})
            db.child(program).child("matches").child(latest).child("Locked").child(school).child(teacher).remove()
            return True
    return False
Esempio n. 21
0
def read_instructors(program: str):
    db = dfsapi.get_db()

    instructors = list()

    keys = db.child(program).child("instructors").shallow().get()

    if keys.val() == None:
        return False

    recentdb = max(keys.val())

    data = db.child(program).child("instructors").child(recentdb).get()

    for i in data.each():
        instructor = i.val()

        Name = instructor["Name"]
        Gender = instructor["Gender"]
        Ethnicity = instructor["Ethnicity"]
        Region = instructor["Region"]
        University = instructor["University"]
        Year = instructor["Year"]
        PreviousMentor = instructor["PreviousMentor"]
        Car = instructor["Car"]
        Languages = instructor["Languages"]
        ShirtSize = instructor["ShirtSize"]
        MultipleDays = instructor["MultipleDays"]
        if "Schedule" not in instructor:
            continue
        Schedule = manageinstructors.schedule_to_dict(instructor["Schedule"])

        instructors.append(
            Instructor(Name, Gender, Ethnicity, Region, University, Year,
                       PreviousMentor, Schedule, Car, Languages, ShirtSize,
                       MultipleDays))

    return instructors
Esempio n. 22
0
def upload_institutions(filepath: str, program: str):
    db = dfsapi.get_db()
    workbook = xlrd.open_workbook(filepath)
    sheet = workbook.sheet_by_index(0)
    sheet.cell_value(0, 0)

    timestamp = str(calendar.timegm(time.gmtime()))

    for i in range(1, sheet.nrows):
        Name = sheet.cell_value(i, 0)
        Address = sheet.cell_value(i, 1)
        County = sheet.cell_value(i, 2)
        Program = sheet.cell_value(i, 3)
        Instructors = sheet.cell_value(i, 4)
        Mon = sheet.cell_value(i, 5)
        Tue = sheet.cell_value(i, 6)
        Wed = sheet.cell_value(i, 7)
        Thurs = sheet.cell_value(i, 8)
        Fri = sheet.cell_value(i, 9)

        school = {
            "Name": Name,
            "Address": Address,
            "County": County,
            "Program": Program,
            "Instructors": Instructors,
            "Monday": Mon,
            "Tuesday": Tue,
            "Wednesday": Wed,
            "Thursday": Thurs,
            "Friday": Fri
        }

        #db.child(program).child(Name).set(school)
        db.child(program).child("institutions").child(timestamp).child(
            Name).set(school)
Esempio n. 23
0
        # TODO remove instr_choices from being used again
        for x in instr_choices:
            #instr, m_dict = x[1]
            instr = x[1]

            if school not in response[program]:
                response[program][school] = dict()
            response[program][school][instr] = 1
            if school == "35439":
                print("Instructor: ", instr)
                print("Score: ", x[0])
    print("RESORT: ")
    print(response)
    return dict(response)

if __name__ == "__main__":

    season = "Fall 2020"
    program = "AppJam"

    db = dfsapi.get_db()
    # Get all schools
    schools_data = db.child(season).child("schools").get().val()
    # Get all instructors
    instructors_data = db.child(season).child("instructors").get().val()

    distance_data = dict()
    region_set = {instructors_data[instr]['region'][0] for instr in instructors_data}
    for school in schools_data:
        distance_data[school] = distance_between(list(region_set), schools_data[school]['address'])
    data = optimal_sort(schools_data, instructors_data, distance_data, program)