Skip to content

Commit

Permalink
removes duplicate on good_id, could be useful to do this for other fi…
Browse files Browse the repository at this point in the history
…elds or load this into pandas to interogate a bit better.
  • Loading branch information
Tllew committed Oct 1, 2024
1 parent 736bf7b commit 00eb1e6
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions api/support/management/commands/get_lite_specialcharacters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SpecialCharacterFinder:
fieldnames = []

results = []
unique_result = {}

def __init__(self, filename, data):
self.filename = filename
Expand All @@ -24,12 +25,18 @@ def check_regex(self, value):
def get_value(self, entry):
return entry

def get_id(self, entry):
return entry

def check_data(self, data):
results = []
for entry in data:
value = self.get_value(entry)
if match := self.check_regex(value):
results.append(self.format_results(entry, match))
id = self.get_id(entry)
if not self.unique_result.get(id):
value = self.get_value(entry)
if match := self.check_regex(value):
results.append(self.format_results(entry, match))
self.unique_result[id] = True
return results

def format_results(self, data, match):
Expand All @@ -54,13 +61,19 @@ class GoodSpecialCharacterFinder(SpecialCharacterFinder):
def get_value(self, entry):
return entry.good.name

def get_id(self, entry):
return str(entry.good.id)


class PartyNameSpecialCharacterFinder(SpecialCharacterFinder):
fieldnames = ["org_name", "reference_code", "party_id", "value", "match"]

def get_value(self, entry):
return entry.party.name

def get_id(self, entry):
return str(entry.party.id)

def format_results(self, data, match):
return {
"org_name": data.application.organisation.name,
Expand All @@ -78,6 +91,9 @@ class PartyAddressSpecialCharacterFinder(SpecialCharacterFinder):
def get_value(self, entry):
return entry.party.address

def get_id(self, entry):
return str(entry.party.id)

def format_results(self, data, match):
return {
"org_name": data.application.organisation.name,
Expand Down Expand Up @@ -120,7 +136,7 @@ def handle(self, *args, **options):
PartyAddressSpecialCharacterFinder("party_address", party_matches)


# retrieve file:
# # retrieve file:
# cf ssh lite-api-uat -c "cat app/good_names.csv" > good_names.csv
# cf ssh lite-api-uat -c "cat app/party_names.csv" > party_names.csv
# cf ssh lite-api-uat -c "cat app/party_address.csv" > party_address.csv

0 comments on commit 00eb1e6

Please sign in to comment.