Skip to content

Commit

Permalink
reducing diff
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar-badlani committed Oct 3, 2024
1 parent 93e7496 commit 75b9eb9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/algorithm/evaluation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ def __init__(
self.draw_question_verdicts,
self.draw_score,
self.should_explain_scoring,
self.should_export_csv,
) = map(
outputs_configuration.get,
[
Expand All @@ -466,6 +467,7 @@ def __init__(
"draw_question_verdicts",
"draw_score",
"should_explain_scoring",
"should_export_csv",
],
)
if self.draw_question_verdicts["enabled"]:
Expand Down Expand Up @@ -995,6 +997,7 @@ def conditionally_add_explanation(
]
self.explanation_table.add_row(*row)


@staticmethod
def get_schema_verdict(answer_type, question_verdict, delta=None):
# Note: Negative custom weights should be considered as incorrect schema verdict(special case)
Expand All @@ -1014,6 +1017,12 @@ def conditionally_print_explanation(self):
def get_should_explain_scoring(self):
return self.should_explain_scoring

def get_should_export_csv(self):
return self.should_export_csv

def get_explanation_table(self):
return self.explanation_table

def get_formatted_answers_summary(self, answers_summary_format_string=None):
if answers_summary_format_string is None:
answers_summary_format_string = self.draw_answers_summary[
Expand Down
3 changes: 3 additions & 0 deletions src/algorithm/template/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def get_multi_marked_dir(self):
def get_errors_dir(self):
return self.directory_handler.path_utils.errors_dir

def get_eval_dir(self):
return self.directory_handler.path_utils.eval_dir

def read_omr_response(self, input_gray_image, colored_image, file_path):
# Convert posix path to string
file_path = str(file_path)
Expand Down
13 changes: 13 additions & 0 deletions src/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pandas as pd
from rich.table import Table
from rich_tools import table_to_df

from src.algorithm.evaluation.config import EvaluationConfig
from src.algorithm.evaluation.evaluation import evaluate_concatenated_response
Expand Down Expand Up @@ -326,9 +327,21 @@ def process_directory_files(
logger.info(
f"(/{files_counter}) Graded with score: {round(score, 2)}\t {default_answers_summary} \t file: '{file_id}'"
)
if evaluation_config_for_response.get_should_export_csv():
explanation_table = evaluation_config_for_response.get_explanation_table()
explanation_table = table_to_df(explanation_table)
explanation_table.to_csv(
template.get_eval_dir().joinpath(file_name + ".csv"),
quoting=QUOTE_NONNUMERIC,
index=False,
)

else:
logger.info(f"(/{files_counter}) Processed file: '{file_id}'")




# TODO: move this logic inside the class
save_marked_dir = template.get_save_marked_dir()

Expand Down
4 changes: 4 additions & 0 deletions src/schemas/evaluation_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@
"description": "Whether to print the table explaining question-wise verdicts",
"type": "boolean",
},
"should_export_csv": {
"description": "Whether to export the explanation of evaluation results as a CSV file",
"type": "boolean",
},
"draw_score": {
"description": "The configuration for drawing the final score",
"type": "object",
Expand Down
2 changes: 2 additions & 0 deletions src/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, output_dir):
self.manual_dir = output_dir.joinpath("Manual")
self.errors_dir = self.manual_dir.joinpath("ErrorFiles")
self.multi_marked_dir = self.manual_dir.joinpath("MultiMarkedFiles")
self.eval_dir = output_dir.joinpath("Evaluations")
self.debug_dir = output_dir.joinpath("Debug")

def create_output_directories(self):
Expand Down Expand Up @@ -96,6 +97,7 @@ def create_output_directories(self):
for save_output_dir in [
self.results_dir,
self.image_metrics_dir,
self.eval_dir,
]:
if not os.path.exists(save_output_dir):
logger.info(f"Created : {save_output_dir}")
Expand Down

0 comments on commit 75b9eb9

Please sign in to comment.