def all_instructors(self): """Retrieve all instrcutors with the cohort name""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[1], row[2], row[3], row[4], row[5]) db_cursor = conn.cursor() db_cursor.execute(""" select i.Id, i.FirstName, i.LastName, i.SlackHandle, i.CohortId, i.Specialty, c.Name from Instructor i join Cohort c on i.CohortId = c.Id order by i.CohortId """) all_instructors = db_cursor.fetchall() for instructor in all_instructors: print(instructor)
def all_instructors(self): """Retrieve all instructors with the cohort name""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[1], row[2], row[3], row[4], row[6]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT i.Id, i.First_Name, i.Last_Name, i.Slack, i.Specialty, i.CohortId, c.Name FROM Instructor i JOIN Cohort c ON i.CohortId = c.Id ORDER BY i.CohortId """) all_instructors = db_cursor.fetchall() print("------------Instructors-----------------") [print(s) for s in all_instructors] print("----------------------------------------")
def all_instructors(self): """Retrieve all students with the cohort name""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[1], row[2], row[3], row[6], row[5]) db_cursor = conn.cursor() db_cursor.execute(""" select i.id, i.first, i.last, i.slack, i.cohortId, i.specialty, c.name from instructors i join cohorts c on i.cohortId = c.cohortId order by i.cohortId """) all_instructors = db_cursor.fetchall() for instructor in all_instructors: print(instructor)
def all_instructors(self): """Retrieve all instructors with the instructors name""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[1], row[2], row[3], row[4], row[5]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT i.Id, i.FirstName, i.LastName, i.SlackHandle, i.CohortId, i.Specialty, c.Name FROM Instructor i JOIN Cohort c on i.CohortId = c.Id ORDER BY i.CohortId; """) all_instructors = db_cursor.fetchall() for instructors in all_instructors: print(instructors)
def config_instructors(self,file_path_for_instructor): """ Creates Instructors from instructors.txt """ all_instructors = dict() for row_data in self.file_reading_gen(file_path_for_instructor,3,"\t",True): cwid, name, dept = row_data all_instructors[cwid] = Instructor({"cwid":cwid, "name":name,"dept":dept}) return all_instructors
def make_instructor(info: dict): return Instructor(info['Name'], info['Gender'], info['Ethnicity'], info['Region'], info['University'], info['Year'], info['PreviousMentor'], schedule_to_dict(info['Schedule']), info['Car'], info['Languages'], info['ShirtSize'], info['MultipleDays'])
def all_instructors_with_cohort(self): """Retrieve all instructors with the their cohort""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[1], row[2], row[3], row[5], row[6]) db_cursor = conn.cursor() db_cursor.execute(""" select i.instructor_id, i.first_name, i.last_name, i.slackhandle, i.cohort_id, c.name, i.specialty from Instructors i join Cohorts c on i.cohort_id = c.cohort_id order by i.cohort_id """) all_instructors = db_cursor.fetchall() print("Instructors") print("=========") # comprehension: [print(i) for i in all_instructors] print("")
def exercises_w_students(self): exercises = dict() with sqlite3.connect(self.db_path) as conn: db_cursor = conn.cursor() db_cursor.execute(""" select e.Id ExerciseId, e.Name, s.Id, s.First_Name, s.Last_Name, i.Id, i.First_Name, i.Last_Name from Exercise e join Assigned_Exercises ae on ae.ExerciseId = e.Id join Student s on s.Id = ae.StudentId join Instructor i on i.Id = ae.InstructorId; """) dataset = db_cursor.fetchall() for row in dataset: exercise_name = row[1] student = Student(row[2], row[3], row[4], "", "") instructor = Instructor(row[5], row[6], row[7], "", "", "") instructor.students = [] if exercise_name not in exercises: exercises[exercise_name] = [instructor] instructor.students.extend(f'{student.first_name} {student.last_name}') else: exercises[exercise_name].append(instructor) instructor.students.extend(f'{student.first_name} {student.last_name}') for exercise_name, instructors in exercises.items(): print(f'{exercise_name}:') for instructor in instructors: this = f'\t* {instructor.first_name} {instructor.last_name} assigned this to ' for each in instructor.students: this += each print(this) print("\n")
def list_exercises_for_instructors(self): with sqlite3.connect(self.db_path) as conn: db_cursor = conn.cursor() db_cursor.execute(""" SELECT i.id, i.first_name, i.last_name, i.slack_handle, i.specialty, c.name, e.name FROM Instructor i JOIN AssignedExercise ae ON i.id = ae.instructor_id JOIN Exercise e ON ae.exercise_id = e.id JOIN Cohort c ON i.cohort_id = c.id; """) instructor_results = db_cursor.fetchall() instructor_dict = dict() for instructor in instructor_results: instructor_id = instructor[0] first_name = instructor[1] last_name = instructor[2] slack_handle = instructor[3] specialty = instructor[4] cohort = instructor[5] exercise = instructor[6] if instructor_id not in instructor_dict: instructor_dict[instructor_id] = Instructor( first_name, last_name, slack_handle, cohort, specialty) exercise_set = set( instructor_dict[instructor_id].assigned_exercises) exercise_set.add(exercise) instructor_dict[instructor_id].assigned_exercises = list( exercise_set) for instructor_id, instructor in instructor_dict.items(): print( f"{instructor.first_name} {instructor.last_name} has assigned:" ) [ print(f" * {exercise}") for exercise in instructor.assigned_exercises ]
def get_instructor_via_tr_id(self, tr_id): with dbapi2.connect(self.dbfile) as connection: cursor = connection.cursor() query = "select * from instructor where (tr_id = %s)" cursor.execute(query, (tr_id, )) if cursor.rowcount == 0: return None instructor = Instructor( *cursor.fetchone()) # Inline unpacking of a tuple return instructor
def instructors(self): from instructor import Instructor last = self.prime.split(',')[0] first = self.prime.split() if len(first) > 1: first = first[1] else: first = None prime = Instructor.query(ancestor = self.key).filter(ndb.AND(Instructor.last == last, Instructor.first == first)).get() ret = [] if prime: ret.append(prime) instructors_list = Instructor.query(ancestor = self.key).order(Instructor.last).fetch() for i in instructors_list: if i != prime: ret.append(i) return ret
def test_from_file(self) -> None: # Test getting a list of student from file non_existing_file_path: str = "./test" dir_path: str = "./support" file_path: str = "./support/instructors.txt" with self.assertRaises(TypeError): Instructors.from_file(0) with self.assertRaises(FileNotFoundError): Instructors.from_file(non_existing_file_path) with self.assertRaises(ValueError): Instructors.from_file(dir_path) instructors: List[Instructor] = \ Instructors.from_file(file_path) self.assertEqual(len(instructors), 6) expected_result: List[Instructor] = [ Instructor("98765", "Einstein, A", "SFEN"), Instructor("98764", "Feynman, R", "SFEN"), Instructor("98763", "Newton, I", "SFEN"), Instructor("98762", "Hawking, S", "SYEN"), Instructor("98761", "Edison, A", "SYEN"), Instructor("98760", "Darwin, C", "SYEN"), ] for i in range(len(instructors)): self.assertEqual(instructors[i].cwid, expected_result[i].cwid) self.assertEqual(instructors[i].name, expected_result[i].name) self.assertEqual(instructors[i].department, expected_result[i].department)
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
def instructors_and_cohorts(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[0], row[1], row[2], row[3]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT i.Id, i.FirstName, i.LastName, c.Name FROM Instructor i LEFT JOIN Cohort c ON i.CohortId = c.Id ORDER BY i.CohortId """) instructor_cohorts = db_cursor.fetchall() [print(i) for i in instructor_cohorts]
def import_people(cohort, role): people = [] with open(f"data/c{cohort}_{role}.csv") as csv_file: csv_reader = csv.reader(csv_file, delimiter=",") first_line = True for row in csv_reader: if first_line == True: first_line = False else: if role == "student": people.append( Student(row[1], row[2], row[3], f"Cohort {cohort}")) else: people.append( Instructor(row[1], row[2], row[3], f"Cohort {cohort}", row[4])) return people
def all_instructors(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[0], row[1], row[2], row[3], row[4]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT first_name, last_name, slack_handle, cohorts.name, specialty FROM instructors JOIN cohorts ON instructors.cohort_id = cohorts.id ORDER BY instructors.last_name """) all_instructors = db_cursor.fetchall() [print(i) for i in all_instructors]
def main(): #title of the online schedule (a Google Sheet) sheet_title = get_tomorrows_date() #the online schedule for the next day schedule = Schedule(sheet_title) #the content being sent to instructors group_text = TextMessage() people = schedule.get_scheduled_instructors() for person in people: to_add = Instructor(person, todays_schedule=schedule).get_human_time() group_text.append_to_msg_content(to_add) group_text.send_text() return
def all_instructors(self): """Retrieve all instructors with the cohort name""" row_factory = lambda cursor, row: Instructor(row[0], row[1], row[2], row[3], row[5]) query = """ SELECT i.Id, i.FirstName, i.LastName, i.Slack, i.CohortId, c.Name FROM Instructor i JOIN Cohort c ON i.CohortId = c.Id """ response = self.get_data(row_factory, query) self.print_report("All Instructors", response)
def all_instructors(self): """Retreive all instructors and their respective cohorts""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[1], row[2], row[3], row[5]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT i.Id, i.First_Name, i.Last_Name, i.Slack_Handle, i.Cohort_Id, c.Name FROM Instructor i JOIN Cohort c on i.Cohort_Id = c.Id """) all_instructors = db_cursor.fetchall() [print(i) for i in all_instructors]
def test_repository(self) -> None: # Test repository functionalities file_path: str = "./support/instructors.txt" instructors: List[Instructor] = \ Instructors.from_file(file_path) repository: Instructors = Instructors(instructors) self.assertEqual(len(repository.all()), 6) expected_instructor: Instructor = Instructor("98765", "Einstein, A", "SFEN") teacher: Instructor = repository.get(instructor.GetBy.ID, "98765") self.assertEqual(expected_instructor.cwid, teacher.cwid) self.assertEqual(expected_instructor.name, teacher.name) self.assertEqual(expected_instructor.department, teacher.department) self.assertEqual( len(repository.get(instructor.GetBy.DEPARTMENT, "SFEN")), 3) self.assertEqual( len(repository.get(instructor.GetBy.DEPARTMENT, "SYEN")), 3) with self.assertRaises(ValueError): repository.get(instructor.GetBy.ID, "TEST")
def all_instructors(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[1], row[2], row[3], row[4], row[6]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT i.Id, i.FirstName, i.LastName, i.SlackHandle, i.Specialty, i.CohortId, c.Name FROM Instructor i JOIN Cohort c ON i.CohortId = c.Id """) all_instructors = db_cursor.fetchall() [print(inst) for inst in all_instructors]
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
def get_all_instructors(self): instructors = [] with dbapi2.connect(self.dbfile) as connection: cursor = connection.cursor() cursor.execute( "select instructor.*, people.name, people.surname, department.name, faculty.name " "from people, instructor, department, faculty " "where (people.tr_id = instructor.tr_id " "and instructor.department_id = department.id " "and instructor.faculty_id = faculty.id);") for row in cursor: instructor = Instructor(*row[:9]) instructor.name = row[9] instructor.surname = row[10] instructor.departmentName = row[11] instructor.facultyName = row[12] instructors.append(instructor) return instructors
def all_instructors_with_cohort(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[1], row[2], row[3], row[6], row[4]) db_cursor = conn.cursor() db_cursor.execute(""" select i.Id, i.First_Name, i.Last_Name, i.Slack_Handle, i.Cohort_Id, i.Specialty, c.Cohort_Name from Instructor i join Cohort c on i.Cohort_Id = c.Id order by i.Cohort_Id """) all_instructors_with_cohort = db_cursor.fetchall() print("\nAll instructors by Cohort") [print(s) for s in all_instructors_with_cohort]
def all_people_with_cohort(self, role): with sqlite3.connect(self.db_path) as conn: conn.row_factory = ( lambda cursor, row: Student(row[1], row[2], row[3], row[4]) if role == "student" else Instructor(row[1], row[2], row[3], row[5], row[4])) db_cursor = conn.cursor() specialty = "" if role == "instructor": specialty = f"r.specialty, " db_cursor.execute(f""" SELECT r.id, r.first_name, r.last_name, r.slack_handle, {specialty} c.name FROM {role.capitalize()} r JOIN Cohort c ON r.cohort_id = c.id """) all_people_with_cohort = db_cursor.fetchall() print(f"\nAll {role}s") [print(f" {person}") for person in all_people_with_cohort]
def all_instructors(self): """Retrieve all instructors with the cohort name""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Instructor( row[1], row[2], row[3], row[5], row[6]) # conn.row_factory = lambda cursor, row: Instructor(*row) db_cursor = conn.cursor() execute_query = db_cursor.execute(""" SELECT i.Id, i.First_Name, i.Last_Name, i.Slack_Handle, i.CohortId, i.Speciality, c.Name FROM Instructor i JOIN Cohort c ON i.CohortId = c.Id ORDER BY i.CohortId """) # print(execute_query) all_instructors = db_cursor.fetchall() # print(all_instructors) # When there is no row_factory function defined, we get a list of tuples # for instructor in all_instructors: # print(f'{instructor[1]} {instructor[2]} is in {instructor[5]}') # We have a row_factory function specified. That lambda takes each tuple and returns an instance of the instructor class for instructor in all_instructors: print(instructor)
# Create 3, or more, cohorts. cohort35 = Cohort("Cohort 35") cohort36 = Cohort("Cohort 36") cohort37 = Cohort("Cohort 37") # Create 4, or more, students and assign them to one of the cohorts. samSam = Student("Sam", "Pita", "SamTheSlice") guyGuy = Student("Guy", "Cherkesky", "WhatA") erEr = Student("Erin", "Polley", "ErIn") treyTrey = Student("Trey", "Suitor", "HesASuitor") # Create 3, or more, instructors and assign them to one of the cohorts. jisie = Instructor("Jisie", "David", "jDavid", "all-around-badass") joe = Instructor("Joe", "Shepard", "jShep", "the jokes") jenna = Instructor("Jenna", "Solis", "jSol", "cat babies") andy = Instructor("Andy", "Smith", "andEE", "scuba diving") steve = Instructor("Steve", "Jenkins", "@steve", "poetry") cohort36.assign_instructor(jisie) cohort36.assign_instructor(andy) cohort35.assign_instructor(joe) cohort36.assign_instructor(jenna) cohort37.assign_instructor(steve) cohort36.list_instructors() cohort37.list_instructors() cohort35.list_instructors()
# Have each instructor assign 2 exercises to each of the students. exercise1 = Exercise("exercise1", "javascript") exercise2 = Exercise("exercise2", "python") exercise3 = Exercise("exercise3", "html") exercise4 = Exercise("exercise4", "css") cohort1 = Cohort("cohort1") cohort2 = Cohort("cohort2") cohort3 = Cohort("cohort3") student1 = Student("John", "Doe") student1.cohort = cohort1 student2 = Student("Jane", "Doe") student2.cohort = cohort2 student3 = Student("Jill", "Doe") student3.cohort = cohort3 instructor1 = Instructor("Doe", "John") instructor1.cohort = cohort1 instructor2 = Instructor("Doe", "Jane") instructor2.cohort = cohort2 instructor3 = Instructor("Doe", "Jill") instructor3.cohort = cohort3 instructor1.assign_exercise_to_student(student1, exercise1) instructor1.assign_exercise_to_student(student1, exercise2) instructor1.assign_exercise_to_student(student2, exercise3) instructor1.assign_exercise_to_student(student2, exercise4) instructor2.assign_exercise_to_student(student1, exercise1) instructor2.assign_exercise_to_student(student1, exercise2) instructor2.assign_exercise_to_student(student3, exercise3) instructor2.assign_exercise_to_student(student3, exercise4) instructor3.assign_exercise_to_student(student2, exercise1)
C37 = Cohort("Day Cohort 37") C38 = Cohort("Day Cohort 38") C40 = Cohort("Day Cohort 40") mac = Student("Mac", "Gibbons", "Mac Gibbons") me = Student("Matthew", "Kroeger", "Matthew Kroeger") coop = Student("Cooper", "Nichols", "Cooper Nichols") frog = Student("Roxanne", "Nasraty", "Roxanne Nasraty") students.extend([mac, me, coop, frog]) C37.assign_student(mac) C38.assign_student(me) C38.assign_student(coop) C40.assign_student(frog) steve = Instructor("Steve", "Brownlee", "coach", "Good Vibes") jisie = Instructor("Jisie", "David", ":crown:", "Excitement") bryan = Instructor("Bryan", "Nilsen", "Kickass High-Fiver", "High Fives") C37.assign_instructor(steve) C38.assign_instructor(jisie) C40.assign_instructor(bryan) steve.assign_exercise(mac, capstone) steve.assign_exercise(mac, bank_account) bryan.assign_exercise(frog, fizz_buzz) bryan.assign_exercise(frog, capstone) for student in C38.students: jisie.assign_exercise(student, minecraft) jisie.assign_exercise(student, snake)
parser.add_argument('-warmup', type=float, help='warmup value for BertAdam') parser.add_argument('-epochs', type=int, help='number of iterations') parser.add_argument('-model_out', type=str, default='', help='path to model dir') parser.add_argument('-result_out', type=str, default='', help='path to result fi') parser.add_argument('-loss_dir', type=str, default='', help='path to result loss dir') parser.add_argument("-cuda", action="store_true", help="use gpu or not") parser.add_argument("-test", action="store_true", help="valid/test if true") parser.add_argument('-load_epoch', type=int, default=-1, help='0-indexed epoch of the model to load') parser.add_argument('-seed', type=int, default=2809, help='random seeds') args = parser.parse_args() print(args) instructor = Instructor(args) if args.test: instructor.test() else: instructor.train()
monkey_chicken = Exercise("MonkeyChicken", "Python") welcome_to_nashville = Exercise("Welcome to Nashville", "JavaScript") celebrity_tribute = Exercise("Celebrity Tribute", "HTML") nutshell = Exercise("Nutshell", "ReactJS") day_cohort_36 = Cohort("Day Cohort 36") day_cohort_45 = Cohort("Day Cohort 45") night_cohort_15 = Cohort("Evening Cohort 15") christian = Student("Christian", "Pippin", "@cpippin98") lauren = Student("Lauren", "Riddle", "@lriddle19") corri = Student("Corri", "Golden", "@cgolden17") matt = Student("Matt", "Blagg", "@mblagg45") chase = Student("Chase", "Fite", "@cfite76") day_cohort_36.add_student(christian) night_cohort_15.add_student(lauren) day_cohort_45.add_student(corri) day_cohort_36.add_student(matt) night_cohort_15.add_student(chase) joe = Instructor("Joe", "Shepherd", "@jshepherd24", "Python") jisie = Instructor("Jisie", "David", "@jdavid36", "JavaScript") jenna = Instructor("Jenna", "Solis", "@jsolis09", "CSharp") day_cohort_36.add_instructor(joe) night_cohort_15.add_instructor(jisie) day_cohort_45.add_instructor(jenna) joe.assign_exercise(christian, monkey_chicken)
def savedInstructors(self): from instructor import Instructor return Instructor.query(ancestor = self.key).filter(Instructor.onSyllabus == False).order(Instructor.last).fetch()