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 558 by nino.borges, Thu Dec 19 17:01:14 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  

Diff Legend

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