ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/RandomCodeRequests/Narco_reqs.txt
(Generate patch)

Comparing Python/NinoCode/RandomCodeRequests/Narco_reqs.txt (file contents):
Revision 480 by nino.borges, Wed Nov 6 19:47:59 2013 UTC vs.
Revision 559 by nino.borges, Tue Nov 25 15:54:29 2014 UTC

# Line 1 | Line 1
1 + --- NEW ---
2 + """In this project, Rawlings data check,old format I was asked to take two spreadsheets and using last name and the last 4 dig of ssn,
3 + cross ref and give them a list of what matched"""
4 +
5 + >>> matrix = {}
6 + >>> contents = open(r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Narco\schedule a - list of pe claims to be paid Q3.csv").readlines()
7 + # First I made a matrix with {fullname,full_ssn}, this came from the schedule a list
8 + >>> for line in contents:
9 + ...     line = line.split("|")
10 + ...     name = line[0]
11 + ...     matrix[name] = line[1]
12 +
13 + # Then I made a matrix of {lastName,[fullname,fullname,fullname]}, so that I could first search by last name and then per
14 + # name test the ssn
15 + >>> lastNameMatrix = {}
16 + >>> for line in contents:
17 + ...     line = line.split("|")
18 + ...     name = line[0]
19 + ...     lastName = name.split(",")[0]
20 + ...     lastName = lastName.upper()
21 + ...     if lastName in lastNameMatrix.keys():
22 + ...             lastNameMatrix[lastName].append(name)
23 + ...     else:
24 + ...             lastNameMatrix[lastName] = [name,]
25 +
26 + # Finally, going through the other file, I tested firs the last name and then, if that was found, checked the ssn per
27 + # last name found.
28 + contents = open(r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Narco\NARCO Trust Claims Master File 11042014.csv").readlines()
29 + >>> outputFile = open(r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Narco\Matched.txt",'w')
30 + >>> errFile = open(r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Narco\NotFound.txt",'w')
31 + >>> for line in contents:
32 + ...     newLine = line.split("|")
33 + ...     lastName = newLine[4]
34 + ...     lastName = lastName.strip()
35 + ...     ssn = newLine[5]
36 + ...     if len(ssn) > 8:
37 + ...             ssnPart = ssn[-4:]
38 + ...             if lastName.upper() in lastNameMatrix.keys():
39 + ...                     for ln in lastNameMatrix[lastName.upper()]:
40 + ...                             if ssnPart == matrix[ln][-4:]:
41 + ...                                     outputFile.write("%s | %s"%(matrix[ln],line))
42 + ...                             else:
43 + ...                                     errFile.write(line)
44 + ...             else:
45 + ...                     errFile.write(line)
46 + ...                    
47 + >>> outputFile.close()
48 + >>> errFile.close()
49 +
50 +
51 + --- END ---
52 + --- ALTERNATE ---
53 + """ new format"""
54 + >>> matrix = {}
55 + >>> contents = open(r"C:\Users\eborges\Box Sync\Client\Narco\New_Sched_A.csv").readlines()
56 + # First I made a matrix with {fullname[full_ssn,full_ssn]}, this came from the schedule a list
57 + >>> for line in contents:
58 + ...     line = line.split("|")
59 + ...     lastName = line[1]
60 + ...     firstName = line[2]
61 + ...     if line[3]:
62 + ...             midName = line[3]
63 + ...     else:
64 + ...             midName = None
65 + ...     if midName:
66 + ...             name = "%s, %s %s"% (lastName, firstName, midName)
67 + ...     else:
68 + ...             name = "%s, %s"% (lastName, firstName)
69 + ...     if name in matrix.keys():
70 + ...             matrix[name].append(line[4])
71 + ...     else:
72 + ...             matrix[name] = [line[4],]
73 +
74 + # Then I made a matrix of {lastName,[fullname,fullname,fullname]}, so that I could first search by last name and then per
75 + # name test the ssn
76 + >>> lastNameMatrix = {}
77 + # do this again each time...
78 + >>> contents = open(r"C:\Users\eborges\Box Sync\Client\Narco\New_Sched_A.csv").readlines()
79 + >>> for line in contents:
80 + ...     line = line.split("|")
81 + ...     lastName = line[1]
82 + ...     lastName = lastName.strip()
83 + ...     lastName = lastName.upper()
84 + ...     if lastName in lastNameMatrix.keys():
85 + ...             lastNameMatrix[lastName].append(name)
86 + ...     else:
87 + ...             lastNameMatrix[lastName] = [name,]
88 + ...
89 +
90 + # Finally, going through the other file, I tested first the last name and then, if that was found, checked the ssn per
91 + # last name found and per ssn found
92 + contents = open(r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Narco\NARCO Trust Claims Master File 11042014.csv").readlines()
93 + >>> outputFile = open(r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Narco\Matched_2.txt",'w')
94 + >>> errFile = open(r"\\BSTDD967DTW1\Users\eborges\Box Sync\Client\Narco\NotFound_2.txt",'w')
95 + >>> for line in contents:
96 + ...     newLine = line.split("|")
97 + ...     lastName = newLine[4]
98 + ...     lastName = lastName.strip()
99 + ...     ssn = newLine[5]
100 + ...     if len(ssn) > 8:
101 + ...             ssnPart = ssn[-4:]
102 + ...             if lastName.upper() in lastNameMatrix.keys():
103 + ...                     for ln in lastNameMatrix[lastName.upper()]:
104 + ...                             for fl_SSN in matrix[ln]:
105 + ...                                     if ssnPart == fl_SSN[-4:]:
106 + ...                                             outputFile.write("%s | %s"%(fl_SSN,line))
107 + ...                                     else:
108 + ...                                             errFile.write(line)
109 + ...             else:
110 + ...                     errFile.write(line)
111 + >>> outputFile.close()
112 + >>> errFile.close()
113 + --- END ---
114 +
115 + -----------------------------------------
116   """ In this project, I was asked to compare teh ssn column to two ssn columns in a separate sheet.
117   I also had to normalize the ssn to look for hyphens"""
118  
# Line 34 | Line 149 | outputFile = open(r"W:\Manny\Client\Narc
149   ...     else:
150   ...             outputFile.write(line + "\tNO\n")
151   ...            
152 < >>> outputFile.close()
152 > >>> outputFile.close()
153 >
154 >
155 > """ In this one, she wanted me to cross ref an access table with an excel.  (Excel converted to tab delm but access
156 > I left in mdb, since exporting was super messy."""
157 >
158 > import os,sys, win32com.client
159 > >>> daoDB = daoEngine.OpenDatabase(r"W:\Manny\Client\Narco\Summation.mdb")
160 > >>> daoRSObj = daoDB.OpenRecordset("SELECT SUM_SSN FROM Summation")
161 > >>> daoRSObj.MoveLast()
162 > >>> fullCount = daoRSObj.RecordCount
163 > >>> daoRSObj.MoveFirst()
164 > >>> newList = []
165 > >>> for i in range(fullCount):
166 > ...     newList.append(daoRSObj.Fields('SUM_SSN').Value)
167 > ...     daoRSObj.MoveNext()
168 > ...    
169 > >>> daoRSObj.Close()
170 > >>> len(newList)
171 > 138407
172 > >>> newList.sort()
173 > >>> fullList = []
174 > fullList = []
175 > >>> for i in newList:
176 > ...     if i:
177 > ...             if i == "0":
178 > ...                     pass
179 > ...             else:
180 > ...                     fullList.append(str(i))
181 > ...                    
182 > >>> len(fullList)
183 > 82527
184 > >>> fullList.append('363107041')
185 > >>> fullList.append('464528121')
186 > >>> fullList.sort()
187 > >>> fullList[400]
188 > '035207139'
189 >
190 > >>> contents = open(r"W:\Manny\Client\Narco\20131105_Request\PEC_Internal_Report for 1125 CRMC claims - UAT 11.5.2013.txt").readlines()
191 > >>> masterMatrix = {}
192 > >>> for i in contents:
193 > ...     parts = i.split("\t")
194 > ...     masterMatrix[parts[3]] = i
195 > ...    
196 > >>> len(masterMatrix.keys())
197 >
198 > headder = contents[0]
199 > >>> outputFile = open(r"W:\Manny\Client\Narco\20131105_Request\PEC_Summation_Crossref_output.txt",'w')
200 > >>> outputFile.write(headder)
201 > >>> for ssn in fullList:
202 > ...     if ssn in masterMatrix.keys():
203 > ...             outputFile.write(masterMatrix[ssn])
204 > ...
205 > >>> outputFile.close()

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)