def student_workload(self): """Retrieve all cohorts""" with sqlite3.connect(self.db_path) as conn: db_cursor = conn.cursor() db_cursor.execute(""" SELECT s.Id, s.first_name, s.last_name, s.slack_handle, c.Name, e.Name ExerciseName, e.Id, e.language from Student s JOIN exercise_assignment ex ON s.Id = ex.student_id JOIN Exercise e ON e.Id = ex.exercise_id JOIN Cohort c ON s.cohort_id = c.Id """) all_students_with_exercises = db_cursor.fetchall() students = dict() print(all_students_with_exercises) for exercise_student in all_students_with_exercises: exercise_id = exercise_student[6] exercise_name = exercise_student[5] exercise_language = exercise_student[7] student_id = exercise_student[0] cohort_name = exercise_student[4] slack_handle = exercise_student[3] if student_id not in students: # exercises[exercise_name] is adding a new key/value pair to the exercises dictionary, where exercise_name is the variable containing the key value which is string # [student_name] is creating a list with one item, that item is the string contained in the variable student_name new_student = Student(exercise_student[1], exercise_student[2], slack_handle, cohort_name) students[student_id] = new_student new_exercise = Exercise(exercise_name, exercise_language) students[student_id].exercises[exercise_id] = new_exercise print('this ran') else: new_exercise = Exercise(exercise_name, exercise_language) students[student_id].exercises[exercise_id] = new_exercise print(new_exercise) for student in students: print(f'{students[student].first_name}:') for exercise in students[student].exercises: print(f'\t* {students[student].exercises[exercise].name}')
def hello(): cards = getGYMCards() exercises = [] for card in cards: exercises.append(Exercise(card).get_json()) return flask.jsonify(exercises)
def all_exercises(self): """Retrieve all exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() execute_query = db_cursor.execute(""" SELECT e.Id, e.Name, e.Exercise_Language FROM Exercise e """) # print(execute_query) all_exercises = db_cursor.fetchall() # print(all_exercises) # When there is no row_factory function defined, we get a list of tuples # for student in all_exercises: # print(f'{student[1]} {student[2]} is in {student[5]}') # We have a row_factory function specified. That lambda takes each tuple and returns an instance of the Student class for exercise in all_exercises: print(exercise)
def testDefaults(self): exercise_test = Exercise("Box Jumps", False, "Legs") self.assertEqual(exercise_test.reps, Exercise.DEFAULT_REPS) self.assertEqual(exercise_test.weight, Exercise.DEFAULT_WEIGHT) self.assertEqual( Exercise.num_of_exercises, 1) #this might be the problem if I didn't write the test right
def all_exercises(self): """Retrieve all exercises""" row_factory = lambda cursor, row: Exercise(row[1], row[2]) query = """SELECT * FROM Exercise;""" response = self.get_data(row_factory, query) self.print_report("All Exercises", response)
def cSharp_exercises(self): """Retrieve c# exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT Id, Name, Language FROM Exercise WHERE Language LIKE "cSharp" ORDER BY Id """) cSharp_exercises = db_cursor.fetchall() print("****C# EXERCISES****") if len(cSharp_exercises) == 0: print("No exercises") else: for e in cSharp_exercises: print(e.name) print("----------------------------------------")
def loadExercises(): exercises = [] file = open('ExerciseList.csv') csv_file = csv.reader(file) for row in csv_file: exercise = Exercise(row[0], row[1], row[2], row[3], row[4], (row[5] if (len(row) > 5) else False)) exercises.append(exercise) return exercises
def exercises_from_language(self, language): """Retrieve all exercises of one language""" row_factory = lambda cursor, row: Exercise(row[1], row[2]) query = f""" SELECT * FROM EXERCISE WHERE Lang = "{language}"; """ response = self.get_data(row_factory, query) self.print_report(f"Exercises in {language} include", response)
def all_exercises(self): """Retreive all exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[0]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.name FROM Exercise AS e """) all_exercises = db_cursor.fetchall() [print(e) for e in all_exercises]
def students_with_exercises(self): """Retrieve all students with the cohort name""" with sqlite3.connect(self.db_path) as conn: # conn.row_factory here db_cursor = conn.cursor() db_cursor.execute(""" select e.Id ExerciseId, e.Name, e.ExLanguage, s.Id, s.FirstName, s.LastName, s.SlackHandle, c.Name from Exercise e join StudentExercise se on se.ExerciseId = e.Id join Student s on s.Id = se.StudentId join Cohort c on s.CohortId = c.Id """) students_with_exercises = db_cursor.fetchall() students = dict() for row in students_with_exercises: if row[3] not in students: students[row[3]] = Student(row[4], row[5], row[6], row[7]) students[row[3]].add_exercise(Exercise(row[1], row[2])) else: students[row[3]].add_exercise(Exercise(row[1], row[2])) for key in students: print( f'{students[key].first_name} {students[key].last_name} is working on:' ) for exercise in students[key].current_exercises: print(f'\t* {exercise}')
def js_exercises(self): """Retreive only javascript exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[0]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.name FROM Exercise AS e WHERE language = "Javascript" """) js_exercises = db_cursor.fetchall() [print(e) for e in js_exercises]
def csharp_exercises(self): """Retreive only c# exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[0]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.name FROM Exercise e WHERE language = "C#" """) csharp_exercises = db_cursor.fetchall() [print(e) for e in csharp_exercises]
def python_exercises(self): """Retreive only python exercises""" with sqlite3.connect(self.db_path) as conn: # Makes tuple into object conn.row_factory = lambda cursor, row: Exercise(row[0]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.name FROM Exercise e WHERE language = "Python" """) python_exercises = db_cursor.fetchall() [print(e) for e in python_exercises]
def all_html(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.Id, e.Name, e.ExLanguage FROM Exercise e """) all_html = db_cursor.fetchall() for exercise in all_html: if exercise.language == 'HTML': print(f'HTML exercise {exercise}')
def choose_exercises(self): """Retrieve all exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() execute_query = db_cursor.execute(""" SELECT e.Id, e.Name, e.Exercise_Language FROM Exercise e """) # print(execute_query) all_exercises = db_cursor.fetchall() print("Which Language?") print("1. Javascript") print("2. C#") print("3. Python") choice = 0 while not choice: choice = input(">> ") if choice == "1": choice = "Javascript" elif choice == "2": choice = "C#" elif choice == "3": choice = "Python" else: print("Choose a number 1-3") choice = 0 def check_exercise(exercise, language): if exercise.language == language: print(exercise) # print(all_exercises) # When there is no row_factory function defined, we get a list of tuples # for student in all_exercises: # print(f'{student[1]} {student[2]} is in {student[5]}') # We have a row_factory function specified. That lambda takes each tuple and returns an instance of the Student class for exercise in all_exercises: check_exercise(exercise, choice)
def all_python_exercises(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT Id, Name, Language FROM Exercise WHERE Language = "Python" """) all_python_exercises = db_cursor.fetchall() [print(py) for py in all_python_exercises]
def python_exercises(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[0], row[1]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT name, language FROM exercises WHERE language = "Python" ORDER BY name """) python_exercises = db_cursor.fetchall() [print(e) for e in python_exercises]
def all_exercises(self): """Retrieve all exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise( row[0], row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.Id, e.Name, e.Language FROM Exercise e ORDER BY e.Id; """) all_exercises = db_cursor.fetchall() [print(e) for e in all_exercises]
def all_java_exercises(self): """Retrieve all students with the cohort name""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" select e.Id, e.Name, e.ExLanguage from Exercise e """) all_java_exercises = db_cursor.fetchall() [print(e) for e in all_java_exercises if e.language == 'Java']
def all_exercises(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT * FROM Exercise e """) all_exercises = db_cursor.fetchall() for e in all_exercises: print(f'Exercise: {e.name} Language: {e.language}')
def testSpecifics(self): test_name: str = "Pull Ups" test_aerobic: bool = False test_category: str = "Arms" test_reps: int = 30 test_weight: int = 10 exercise1_test = Exercise(name=test_name, aerobic=test_aerobic, category=test_category, reps=test_reps, weight=test_weight) self.assertEqual(exercise1_test.name, test_name) self.assertEqual(exercise1_test.aerobic, test_aerobic) self.assertEqual(exercise1_test.category, test_category) self.assertEqual(exercise1_test.reps, test_reps) self.assertEqual(exercise1_test.weight, test_weight)
def all_python_exercises(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.Id, e.NAME, e.exercise_language FROM Exercise e WHERE e.exercise_language LIKE 'Python' """) all_exercises = db_cursor.fetchall() [print(s) for s in all_exercises]
def all_exercises(self): """Retrieve all exercises with the cohort name""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.Id, e.Name, e.ExLanguage FROM Exercise e """) all_exercises = db_cursor.fetchall() for exercise in all_exercises: print(exercise)
def all_exercises(self): """Retrieve all exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" select e.id, e.exercise_name, e.exercise_language from Exercise e """) all_exercises = db_cursor.fetchall() for exercise in all_exercises: print(exercise)
def javascript_exercises(self): """Retrieve Javascript exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise( row[0], row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.Id, e.Name, e.Language FROM Exercise e WHERE LANGUAGE = "JavaScript" ORDER BY e.Id; """) js_exercises = db_cursor.fetchall() [print(e) for e in js_exercises]
def _create_deck(self) -> None: ex = Exercise(self._create_equipment_list(), self._equipment_only) for s, e in [(DIAMONDS, ex.get_upper_body_exercise()), (CLUBS, ex.get_lower_body_exercise()), (HEARTS, ex.get_core_exercise()), (SPADES, ex.get_total_body_exercise())]: for v in range(2, 11): self._deck.append(Card(s, v, e)) cardio = ex.get_cardio_exercises() for s, e in [(DIAMONDS, cardio[0]), (CLUBS, cardio[1]), (HEARTS, cardio[2]), (SPADES, cardio[3])]: for v in FaceCards: self._deck.append(Card(s, v.value, e)) self._deck.append(Card('Joker', 14, '1 minute rest')) self._deck.append(Card('Joker', 14, '1 minute rest'))
def python_exercises(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[0], row[1]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT e.exercise_name, e.exercise_language FROM Exercise e WHERE e.exercise_language = 'Python' """) all_exercises = db_cursor.fetchall() for e in all_exercises: print(f'{e.name} is an exercise in {e.language}')
def all_exercises(self): """Retrieve all exercises""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[0], row[1]) db_cursor = conn.cursor() db_cursor.execute(""" select e.Name, e.Language from exercise e """) all_exercises = db_cursor.fetchall() for exercise in all_exercises: print(f'{exercise.Name} using {exercise.Language}')
def all_js_exercises(self): with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" SELECT Id, Name, Language FROM Exercise WHERE Language = "JavaScript" OR Language = "React" """) all_js_exercises = db_cursor.fetchall() [print(js) for js in all_js_exercises]
def all_exercises(self): """Retrieve all students with the cohort name""" with sqlite3.connect(self.db_path) as conn: conn.row_factory = lambda cursor, row: Exercise(row[1], row[2]) db_cursor = conn.cursor() db_cursor.execute(""" select ex.id, ex.name, ex.language from exercises ex order by ex.id """) all_exercises = db_cursor.fetchall() for exercise in all_exercises: print(exercise)