From 6116c0defbc2d66de4249c04a8b36e205d49e816 Mon Sep 17 00:00:00 2001 From: Jim Barnes Date: Fri, 26 Jan 2024 10:56:51 -0500 Subject: [PATCH] Updated catalog import to include subplan code as a matchable field --- .../commands/import-catalog-descriptions.py | 15 ++++++++++ programs/utilities/catalog_match.py | 28 +++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/programs/management/commands/import-catalog-descriptions.py b/programs/management/commands/import-catalog-descriptions.py index a9188af..7bf38d1 100644 --- a/programs/management/commands/import-catalog-descriptions.py +++ b/programs/management/commands/import-catalog-descriptions.py @@ -370,6 +370,21 @@ def __get_catalog_entries(self): self.catalog_entry_data_queue.join() + subplan_prep_progress = ChargingBar( + 'Matching subplans...', + max=len(self.catalog_entries) + ) + + # For all entries with subplan, find their plans + for entry in self.catalog_entries: + subplan_prep_progress.next() + if entry.subplan_code is not None: + entry.plan_code = [ + x.plan_code \ + for x in self.catalog_entries \ + if x.data['pid'] == entry.parent_catalog_id + ] + def __get_catalog_entry_data(self): """ diff --git a/programs/utilities/catalog_match.py b/programs/utilities/catalog_match.py index ed5eb07..973a13e 100644 --- a/programs/utilities/catalog_match.py +++ b/programs/utilities/catalog_match.py @@ -1,7 +1,7 @@ from operator import itemgetter from fuzzywuzzy import fuzz -from programs.models import Level, Career +from programs.models import Level, Career, Program class CatalogEntry(object): @@ -20,6 +20,18 @@ def __init__(self, json, html_data, program_type, college_short): self.level_pk = self.level.pk self.career_pk = self.career.pk + self.plan_code = None + self.subplan_code = None + self.parent_catalog_id = None + + # Set plan code or subplan code + if 'inheritedFrom' not in self.data and 'code' in self.data: + self.plan_code = self.data['code'] + else: + self.parent_catalog_id = self.data['inheritedFrom'] + self.subplan_code = self.data['code'] + + @property def description(self): """ @@ -205,7 +217,7 @@ class MatchableProgram(object): """ Describes a Program and its match(es) to CatalogEntries. """ - def __init__(self, program): + def __init__(self, program: Program): self.program = program self.matches = [] # List of tuples containing score, CatalogEntry object self.best_match = None @@ -260,10 +272,14 @@ def __get_code_match(self, catalog_entry): Tries to match the "code" field with the plan_code of the program. """ - if catalog_entry.data and \ - 'code' in catalog_entry.data and \ - self.program.plan_code == catalog_entry.data['code']: - return 100 + # If this is a parent program + if self.program.parent_program == None: + if self.program.plan_code == catalog_entry.plan_code: + return 100 + else: # If this is a subplan + if self.program.plan_code == catalog_entry.plan_code and \ + self.program.subplan_code == catalog_entry.subplan_code: + return 100 return 0