ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Redgrave/McDonaldsDispoTools.py
Revision: 794
Committed: Fri Sep 8 15:05:52 2023 UTC (2 years, 6 months ago) by nino.borges
Content type: text/x-python
File size: 3957 byte(s)
Log Message:
a set of functions that I can call which will help me with the 2 ePower disposition projects

File Contents

# Content
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
23 self.reasonCodesSet = set() ## Holds the upper version of exact reason codes listed
24 self.reasonCodeAbrivToReasonCodeMatrix = {} ## Holds the upper version of abbrieviated reason codes to upper reason codes listed
25 self.reasonCodeDescriptToReasonCodeMatrix = {} ## Holds the upper version of descriptions to upper reason codes listed
26
27 contents = open(reasonMatrixFile).readlines()
28 for line in contents:
29 line = line.replace("\n","")
30 line = line.split("|")
31 self.reasonCodesSet.add(line[0].upper())
32 if line[0][-2] == "-":
33 abrivVal = line[0][:-2]
34 if abrivVal.upper() in self.reasonCodeAbrivToReasonCodeMatrix.keys():
35 self.reasonCodeAbrivToReasonCodeMatrix[abrivVal.upper()].append(line[0].upper())
36 else:
37 self.reasonCodeAbrivToReasonCodeMatrix[abrivVal.upper()] = [line[0].upper(),]
38 if line[1].upper() in self.reasonCodeDescriptToReasonCodeMatrix.keys():
39 self.reasonCodeDescriptToReasonCodeMatrix[line[1].upper()].append(line[0].upper())
40 else:
41 self.reasonCodeDescriptToReasonCodeMatrix[line[1].upper()] = [line[0].upper(),]
42
43
44 def SearchTermsStringToList(self,searchTermsString):
45 """Takes a string of search terms and exports a list, assuming space is delim and quotes are used when escaping terms with spaces"""
46 f = StringIO(searchTermsString)
47 reader = csv.reader(f,delimiter=" ")
48 for row in reader:
49 rslt = row
50 return rslt
51
52 def ReasonCodesStringToVerifiedString(self,reasonCodesString):
53 """Takes a string of reason codes, (exact, abbrieviated, or description) separated by semicolon and returns a semicolon delimited string"""
54 verifiedReasonCodesSet = set()
55 tempReasonCodeList = reasonCodesString.split(";")
56 for r in tempReasonCodeList:
57 r = r.strip()
58 r = r.upper()
59 if r in self.reasonCodesSet:
60 verifiedReasonCodesSet.add(r)
61 elif r in list(self.reasonCodeAbrivToReasonCodeMatrix.keys()):
62 for i in self.reasonCodeAbrivToReasonCodeMatrix[r]:
63 verifiedReasonCodesSet.add(i)
64 elif r in list(self.reasonCodeDescriptToReasonCodeMatrix.keys()):
65 for i in self.reasonCodeDescriptToReasonCodeMatrix[r]:
66 verifiedReasonCodesSet.add(i)
67 else:
68 print(f"ERROR: {r} NOT FOUND!")
69
70 verifiedReasonCodesList = list(verifiedReasonCodesSet)
71 verifiedReasonCodesList.sort()
72 verifiedReasonCodesString = "; ".join(verifiedReasonCodesList)
73 return verifiedReasonCodesString
74
75
76 def ReasonCodesAndTerms(self,reasonCodesString, searchTermsString, locations = 'All Locations', timeFrame = 'All Dates'):
77 """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"""
78 resultEntry = []
79 searchTermsList = self.SearchTermsStringToList(searchTermsString)
80 verifiedReasonCodesString = self.ReasonCodesStringToVerifiedString(reasonCodesString)
81 for i in searchTermsList:
82 resultEntry.append(f"{i}|{verifiedReasonCodesString}|{locations}|{timeFrame}")
83 for r in resultEntry:
84 print(r)