-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added feature to export the evaluation summary table in csv format #229
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import os | ||
import re | ||
from copy import deepcopy | ||
from csv import QUOTE_NONNUMERIC | ||
|
||
import cv2 | ||
import pandas as pd | ||
|
@@ -197,6 +198,7 @@ def __init__(self, curr_dir, evaluation_path, template, tuning_config): | |
self.should_explain_scoring = options.get("should_explain_scoring", False) | ||
self.has_non_default_section = False | ||
self.exclude_files = [] | ||
self.explanation_table_data_for_csv = [] | ||
|
||
if source_type == "csv": | ||
csv_path = curr_dir.joinpath(options["answer_key_csv_path"]) | ||
|
@@ -352,10 +354,41 @@ def match_answer_for_question(self, current_score, question, marked_answer): | |
) | ||
return delta | ||
|
||
def conditionally_print_explanation(self): | ||
def conditionally_print_explanation(self, file_id): | ||
if self.should_explain_scoring: | ||
console.print(self.explanation_table, justify="center") | ||
|
||
self.explanation_to_csv(file_id) | ||
self.explanation_table_data_for_csv = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also populate |
||
|
||
# Explanation Table to CSV | ||
def explanation_to_csv(self, file_id): | ||
evaluation_json = open_evaluation_with_validation(self.path) | ||
|
||
if evaluation_json["options"].get("enable_evaluation_table_to_csv", False): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should already have access to options in constructors. No need to load the json file again.
|
||
explanation_table_header = [] | ||
cols = self.explanation_table.columns | ||
processed_img_name, ext = file_id.split(".") | ||
|
||
for col in cols: | ||
explanation_table_header.append(col.header) | ||
|
||
output_dir = os.path.join( | ||
os.path.dirname(os.getcwd()), | ||
f"OMRChecker/outputs/Evaluation/{processed_img_name}.csv", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OMRChecker works on multiple directories actually, so can't use hardcoded paths. You need to access |
||
) | ||
|
||
pd.DataFrame( | ||
self.explanation_table_data_for_csv, | ||
columns=explanation_table_header, | ||
dtype=str, | ||
).to_csv( | ||
output_dir, | ||
mode="a", | ||
quoting=QUOTE_NONNUMERIC, | ||
index=False, | ||
) | ||
|
||
def get_should_explain_scoring(self): | ||
return self.should_explain_scoring | ||
|
||
|
@@ -505,9 +538,10 @@ def conditionally_add_explanation( | |
if item is not None | ||
] | ||
self.explanation_table.add_row(*row) | ||
self.explanation_table_data_for_csv.append(row) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of appending the row here, can you check if `self.explanation_table.rows can be looped upon later? It will reduce the coupling. |
||
|
||
|
||
def evaluate_concatenated_response(concatenated_response, evaluation_config): | ||
def evaluate_concatenated_response(concatenated_response, evaluation_config, file_id): | ||
evaluation_config.prepare_and_validate_omr_response(concatenated_response) | ||
current_score = 0.0 | ||
for question in evaluation_config.questions_in_order: | ||
|
@@ -517,6 +551,6 @@ def evaluate_concatenated_response(concatenated_response, evaluation_config): | |
) | ||
current_score += delta | ||
|
||
evaluation_config.conditionally_print_explanation() | ||
evaluation_config.conditionally_print_explanation(file_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's call a separate function instead of coupling the logic with the dedicated small functions |
||
|
||
return current_score |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import argparse | ||
import json | ||
import os | ||
import shutil | ||
from csv import QUOTE_NONNUMERIC | ||
from time import localtime, strftime | ||
|
||
|
@@ -25,6 +26,7 @@ def __init__(self, output_dir): | |
self.save_marked_dir = output_dir.joinpath("CheckedOMRs") | ||
self.results_dir = output_dir.joinpath("Results") | ||
self.manual_dir = output_dir.joinpath("Manual") | ||
self.evaluation_dir = output_dir.joinpath("Evaluation") | ||
self.errors_dir = self.manual_dir.joinpath("ErrorFiles") | ||
self.multi_marked_dir = self.manual_dir.joinpath("MultiMarkedFiles") | ||
|
||
|
@@ -44,6 +46,11 @@ def setup_dirs_for_paths(paths): | |
logger.info(f"Created : {save_output_dir}") | ||
os.makedirs(save_output_dir) | ||
|
||
for save_output_dir in [paths.evaluation_dir]: | ||
if os.path.exists(save_output_dir): | ||
shutil.rmtree(save_output_dir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's not remove any of the user's output. Conditionally create the directory instead similar to other lines here |
||
os.makedirs(save_output_dir) | ||
|
||
for save_output_dir in [paths.multi_marked_dir, paths.errors_dir]: | ||
if not os.path.exists(save_output_dir): | ||
logger.info(f"Created : {save_output_dir}") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead can we directory call a function
conditionally_save_explanation_csv()
from the parent? Wherever conditionally_print_explanation() is called currently?