Skip to content
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

Updated catalog import to include subplan code as a matchable field #412

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions programs/management/commands/import-catalog-descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
28 changes: 22 additions & 6 deletions programs/utilities/catalog_match.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down