Skip to content

Commit

Permalink
Merge pull request #2298 from IFRCGo/fix/validate-extracts
Browse files Browse the repository at this point in the history
Validation Check for the validated extracts for secondary summary
  • Loading branch information
szabozoltan69 authored Nov 5, 2024
2 parents 965d40f + f496654 commit 6382764
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions per/ops_learning_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def add_used_ops_learnings_sector(
if not sector_instance:
logger.info(f"Sector '{sector}' not found.")
return
ops_learning_instances = OpsLearning.objects.filter(id__in=used_ops_learnings)
ops_learning_instances = OpsLearning.objects.filter(is_validated=True, id__in=used_ops_learnings)
if len(ops_learning_instances):
ops_learning_sector, created = (
OpsLearningSectorCacheResponse.objects.select_related("filter_response", "sector")
Expand Down Expand Up @@ -205,7 +205,7 @@ def add_used_ops_learnings_component(
if not component_instance:
logger.info(f"Component '{component}' not found.")
return
ops_learning_instances = OpsLearning.objects.filter(id__in=used_ops_learnings)
ops_learning_instances = OpsLearning.objects.filter(is_validated=True, id__in=used_ops_learnings)
if len(ops_learning_instances):
ops_learning_component, created = (
OpsLearningComponentCacheResponse.objects.select_related("filter_response", "component")
Expand Down Expand Up @@ -276,7 +276,7 @@ def fetch_ops_learnings(cls, filter_data):
"excerpts_id",
"component_title",
"sector_title",
"learning",
"learning_validated",
"country_id",
"country_name",
"region_id",
Expand All @@ -287,10 +287,7 @@ def fetch_ops_learnings(cls, filter_data):
)
)
ops_learning_df = ops_learning_df.rename(
columns={
"component_title": "component",
"sector_title": "sector",
}
columns={"component_title": "component", "sector_title": "sector", "learning_validated": "learning"}
)
ops_learning_df.set_index("id", inplace=True)
return ops_learning_df
Expand Down Expand Up @@ -795,14 +792,14 @@ def _modify_format(summary) -> str:

# Attempt to parse the summary as a dictionary
if _validate_text_is_dictionary(summary):
formated_summary = ast.literal_eval(summary)
formatted_summary = ast.literal_eval(summary)
else:
formatted_summary = _modify_format(summary)
formatted_summary = ast.literal_eval(formatted_summary)

# Checking if the generated summary is empty
if bool(formated_summary):
return formated_summary
if bool(formatted_summary):
return formatted_summary

# NOTE: Generating the summary if summary is empty
while retires < MAX_RETRIES:
Expand Down

0 comments on commit 6382764

Please sign in to comment.