| 1 |
"""
|
| 2 |
McDonaldsDispoTools
|
| 3 |
|
| 4 |
Created by:
|
| 5 |
Emanuel Borges
|
| 6 |
08.10.2023
|
| 7 |
|
| 8 |
This will be a set of functions that I can call which will help me with the 2 ePower dispositon projects
|
| 9 |
|
| 10 |
"""
|
| 11 |
|
| 12 |
import csv
|
| 13 |
from io import StringIO
|
| 14 |
|
| 15 |
|
| 16 |
class DocDisposition(object):
|
| 17 |
version = "0.02"
|
| 18 |
|
| 19 |
def __init__(self):
|
| 20 |
|
| 21 |
#reasonMatrixFile = r"C:\Users\eborges\Documents\Cases\McDonalds\20230621 - Defensible Disposition Additional Projects\_ReasonCodeMatrix.txt"
|
| 22 |
reasonMatrixFile = r"C:\Users\eborges\OneDrive - Redgrave LLP\Documents\Cases\McDonalds\2024 - Defensible Disposition\2024 - ePowerCenter\ePowerCenter Customer\_ReasonCodeMatrix.txt"
|
| 23 |
|
| 24 |
self.reasonCodesSet = set() ## Holds the upper version of exact reason codes listed
|
| 25 |
self.reasonCodeAbrivToReasonCodeMatrix = {} ## Holds the upper version of abbrieviated reason codes to upper reason codes listed
|
| 26 |
self.reasonCodeDescriptToReasonCodeMatrix = {} ## Holds the upper version of descriptions to upper reason codes listed
|
| 27 |
|
| 28 |
contents = open(reasonMatrixFile).readlines()
|
| 29 |
for line in contents:
|
| 30 |
line = line.replace("\n","")
|
| 31 |
line = line.split("|")
|
| 32 |
self.reasonCodesSet.add(line[0].upper())
|
| 33 |
if line[0][-2] == "-":
|
| 34 |
abrivVal = line[0][:-2]
|
| 35 |
if abrivVal.upper() in self.reasonCodeAbrivToReasonCodeMatrix.keys():
|
| 36 |
self.reasonCodeAbrivToReasonCodeMatrix[abrivVal.upper()].append(line[0].upper())
|
| 37 |
else:
|
| 38 |
self.reasonCodeAbrivToReasonCodeMatrix[abrivVal.upper()] = [line[0].upper(),]
|
| 39 |
if line[1].upper() in self.reasonCodeDescriptToReasonCodeMatrix.keys():
|
| 40 |
self.reasonCodeDescriptToReasonCodeMatrix[line[1].upper()].append(line[0].upper())
|
| 41 |
else:
|
| 42 |
self.reasonCodeDescriptToReasonCodeMatrix[line[1].upper()] = [line[0].upper(),]
|
| 43 |
|
| 44 |
|
| 45 |
def SearchTermsStringToList(self,searchTermsString):
|
| 46 |
"""Takes a string of search terms and exports a list, assuming space is delim and quotes are used when escaping terms with spaces"""
|
| 47 |
f = StringIO(searchTermsString)
|
| 48 |
reader = csv.reader(f,delimiter=" ")
|
| 49 |
for row in reader:
|
| 50 |
rslt = row
|
| 51 |
return rslt
|
| 52 |
|
| 53 |
def ReasonCodesStringToVerifiedString(self,reasonCodesString):
|
| 54 |
"""Takes a string of reason codes, (exact, abbrieviated, or description) separated by semicolon and returns a semicolon delimited string"""
|
| 55 |
verifiedReasonCodesSet = set()
|
| 56 |
tempReasonCodeList = reasonCodesString.split(";")
|
| 57 |
#print(len(tempReasonCodeList))
|
| 58 |
for r in tempReasonCodeList:
|
| 59 |
r = r.strip()
|
| 60 |
r = r.upper()
|
| 61 |
if r in self.reasonCodesSet:
|
| 62 |
verifiedReasonCodesSet.add(r)
|
| 63 |
#print (r)
|
| 64 |
elif r in list(self.reasonCodeAbrivToReasonCodeMatrix.keys()):
|
| 65 |
for i in self.reasonCodeAbrivToReasonCodeMatrix[r]:
|
| 66 |
verifiedReasonCodesSet.add(i)
|
| 67 |
#print(i)
|
| 68 |
elif r in list(self.reasonCodeDescriptToReasonCodeMatrix.keys()):
|
| 69 |
for i in self.reasonCodeDescriptToReasonCodeMatrix[r]:
|
| 70 |
verifiedReasonCodesSet.add(i)
|
| 71 |
#print(i)
|
| 72 |
else:
|
| 73 |
print(f"ERROR: {r} NOT FOUND!")
|
| 74 |
|
| 75 |
verifiedReasonCodesList = list(verifiedReasonCodesSet)
|
| 76 |
verifiedReasonCodesList.sort()
|
| 77 |
verifiedReasonCodesString = "; ".join(verifiedReasonCodesList)
|
| 78 |
return verifiedReasonCodesString
|
| 79 |
|
| 80 |
|
| 81 |
def ReasonCodesAndTerms(self,reasonCodesString, searchTermsString, locations = 'All Locations', timeFrame = 'All Dates'):
|
| 82 |
"""This will return the information needed when you have a row where it's reason codes but to the extent they also hit on search terms"""
|
| 83 |
resultEntry = []
|
| 84 |
searchTermsList = self.SearchTermsStringToList(searchTermsString)
|
| 85 |
verifiedReasonCodesString = self.ReasonCodesStringToVerifiedString(reasonCodesString)
|
| 86 |
for i in searchTermsList:
|
| 87 |
resultEntry.append(f"{i}|{verifiedReasonCodesString}|{locations}|{timeFrame}")
|
| 88 |
for r in resultEntry:
|
| 89 |
print(r)
|
| 90 |
|
| 91 |
|
| 92 |
def ReformatResturantCode(self, rawResturantCode):
|
| 93 |
"""Takes a single resurant code value and reformats it to be complient with client request"""
|
| 94 |
resturantCode = rawResturantCode.upper()
|
| 95 |
resturantCode = resturantCode.replace("NSN","")
|
| 96 |
resturantCode = resturantCode.strip()
|
| 97 |
resturantCode = int(resturantCode)
|
| 98 |
return(f"{resturantCode:05d}") |