From 5648ef11978defbdff800882b5867e2c69b3bd98 Mon Sep 17 00:00:00 2001 From: aldo Date: Sun, 1 Dec 2024 13:32:38 -0600 Subject: [PATCH 1/4] fixed mysql issue that arose --- BackEndFlask/Functions/exportCsv.py | 29 +++++++++++++++++++++++++---- BackEndFlask/models/queries.py | 3 ++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/BackEndFlask/Functions/exportCsv.py b/BackEndFlask/Functions/exportCsv.py index 78a981c12..80808a511 100644 --- a/BackEndFlask/Functions/exportCsv.py +++ b/BackEndFlask/Functions/exportCsv.py @@ -212,7 +212,7 @@ def _format(self) -> None: self._singular[Csv_Data.USER_ID.value], self._singular[Csv_Data.TEAM_ID.value], self._at_id, category) - + # Adding the other column names which are the ocs and sfi text. headers += ["OC:" + i[0] for i in oc_sfi_per_category[0]] + ["SFI:" + i[0] for i in oc_sfi_per_category[1]] @@ -234,14 +234,32 @@ def _format(self) -> None: self._writer.writerow(row) self._writer.writerow(['']) +class Comments_Csv(Csv_Creation): + """ + Description: Singleton that creates a csv string of comments per category per student. + """ + def __init__(self, at_id: int) -> None: + """ + Parameters: + at_id: + """ + super().__init__(at_id) + + def _format(self) -> None: + """ + Description: Formats the data in the csv string. + Exceptions: None except what IO can rise. + """ + class CSV_Type(Enum): """ Description: This is the enum for the different types of csv file formats the clients have requested. """ RATING_CSV = 0 OCS_SFI_CSV = 1 + COMMENTS_CSV = 2 -def create_csv_strings(at_id:int, type_csv=CSV_Type.OCS_SFI_CSV.value) -> str: +def create_csv_strings(at_id:int, type_csv:int=1) -> str: """ Description: Creates a csv file with the data in the format specified by type_csv. @@ -254,10 +272,13 @@ def create_csv_strings(at_id:int, type_csv=CSV_Type.OCS_SFI_CSV.value) -> str: Exceptions: None except the chance the database or IO calls raise one. """ + type_csv = CSV_Type(type_csv) match type_csv: - case CSV_Type.RATING_CSV.value: + case CSV_Type.RATING_CSV: return Ratings_Csv(at_id).return_csv_str() - case CSV_Type.OCS_SFI_CSV.value: + case CSV_Type.OCS_SFI_CSV: return Ocs_Sfis_Csv(at_id).return_csv_str() + case CSV_Type.COMMENTS_CSV: + return Comments_Csv(at_id).return_csv_str() case _: return "No current class meets the deisred csv format. Error in create_csv_strings()." \ No newline at end of file diff --git a/BackEndFlask/models/queries.py b/BackEndFlask/models/queries.py index 3429077ac..02d38a639 100644 --- a/BackEndFlask/models/queries.py +++ b/BackEndFlask/models/queries.py @@ -1026,7 +1026,8 @@ def get_csv_categories(rubric_id: int, user_id: int, team_id: int, at_id: int, c for i in range(0, 2): ocs_sfis_query[i] = db.session.query( - ObservableCharacteristic.observable_characteristic_text if i == 0 else SuggestionsForImprovement.suggestion_text + ObservableCharacteristic.observable_characteristic_text if i == 0 else SuggestionsForImprovement.suggestion_text, + ObservableCharacteristic.observable_characteristics_id if i == 0 else SuggestionsForImprovement.suggestion_id, ).join( Category, (ObservableCharacteristic.category_id if i == 0 else SuggestionsForImprovement.category_id) == Category.category_id From 17df81264eaa5a1800b3fb1beb303d9b7b2f430e Mon Sep 17 00:00:00 2001 From: aldo Date: Sun, 1 Dec 2024 14:02:06 -0600 Subject: [PATCH 2/4] back-end can now do a ratings and comments output --- BackEndFlask/Functions/exportCsv.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/BackEndFlask/Functions/exportCsv.py b/BackEndFlask/Functions/exportCsv.py index 80808a511..dad1c799e 100644 --- a/BackEndFlask/Functions/exportCsv.py +++ b/BackEndFlask/Functions/exportCsv.py @@ -250,14 +250,34 @@ def _format(self) -> None: Description: Formats the data in the csv string. Exceptions: None except what IO can rise. """ + column_name = ["First Name"] + ["Last Name"] if not self._is_teams else ["Team Name"] + + # Adding the column name. Noitice that done and comments is skipped since they are categories but are not important. + column_name += [i for i in self._singular[Csv_Data.JSON.value] if (i != "done" and i !="comments")] + + with open("ap.txt", 'w') as out: + print(self._singular, file=out) + + self._writer.writerow(column_name) + + row_info = None + + # Notice that in the list comphrehensions done and comments are skiped since they are categories but dont hold relavent data. + for individual in self._completed_assessment_data: + + row_info = [individual[Csv_Data.FIRST_NAME.value]] + [individual[Csv_Data.LAST_NAME.value]] if not self._is_teams else [individual[Csv_Data.TEAM_NAME.value]] + + row_info += [individual[Csv_Data.JSON.value][category]["comments"] for category in individual[Csv_Data.JSON.value] if (category != "done" and category !="comments")] + + self._writer.writerow(row_info) class CSV_Type(Enum): """ Description: This is the enum for the different types of csv file formats the clients have requested. """ RATING_CSV = 0 - OCS_SFI_CSV = 1 - COMMENTS_CSV = 2 + OCS_SFI_CSV = 2 + COMMENTS_CSV = 1 def create_csv_strings(at_id:int, type_csv:int=1) -> str: """ From 16c2f9721f56962023c85d0e8f8f57c567158e0e Mon Sep 17 00:00:00 2001 From: aldo Date: Sun, 1 Dec 2024 14:03:39 -0600 Subject: [PATCH 3/4] removing debugging code --- BackEndFlask/Functions/exportCsv.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/BackEndFlask/Functions/exportCsv.py b/BackEndFlask/Functions/exportCsv.py index dad1c799e..396201b8e 100644 --- a/BackEndFlask/Functions/exportCsv.py +++ b/BackEndFlask/Functions/exportCsv.py @@ -255,9 +255,6 @@ def _format(self) -> None: # Adding the column name. Noitice that done and comments is skipped since they are categories but are not important. column_name += [i for i in self._singular[Csv_Data.JSON.value] if (i != "done" and i !="comments")] - with open("ap.txt", 'w') as out: - print(self._singular, file=out) - self._writer.writerow(column_name) row_info = None @@ -276,8 +273,8 @@ class CSV_Type(Enum): Description: This is the enum for the different types of csv file formats the clients have requested. """ RATING_CSV = 0 - OCS_SFI_CSV = 2 - COMMENTS_CSV = 1 + OCS_SFI_CSV = 1 + COMMENTS_CSV = 2 def create_csv_strings(at_id:int, type_csv:int=1) -> str: """ From 39f762df8dcb994cd499e0586afa9b62fe5d19e8 Mon Sep 17 00:00:00 2001 From: aldo Date: Sun, 1 Dec 2024 14:14:23 -0600 Subject: [PATCH 4/4] New error catching --- BackEndFlask/Functions/exportCsv.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/BackEndFlask/Functions/exportCsv.py b/BackEndFlask/Functions/exportCsv.py index 396201b8e..1e0476524 100644 --- a/BackEndFlask/Functions/exportCsv.py +++ b/BackEndFlask/Functions/exportCsv.py @@ -289,7 +289,10 @@ def create_csv_strings(at_id:int, type_csv:int=1) -> str: Exceptions: None except the chance the database or IO calls raise one. """ - type_csv = CSV_Type(type_csv) + try: + type_csv = CSV_Type(type_csv) + except: + raise ValueError("No type of csv is associated for the value passed.") match type_csv: case CSV_Type.RATING_CSV: return Ratings_Csv(at_id).return_csv_str() @@ -298,4 +301,4 @@ def create_csv_strings(at_id:int, type_csv:int=1) -> str: case CSV_Type.COMMENTS_CSV: return Comments_Csv(at_id).return_csv_str() case _: - return "No current class meets the deisred csv format. Error in create_csv_strings()." \ No newline at end of file + return "Error in create_csv_strings()." \ No newline at end of file