ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Narco_Deficiency_Report.py
Revision: 481
Committed: Wed Nov 6 19:49:08 2013 UTC (12 years, 4 months ago) by nino.borges
Content type: text/x-python
File size: 4050 byte(s)
Log Message:
This program will help us crft the deviciency reports from Narco, post query.

File Contents

# User Rev Content
1 nino.borges 481 """
2     Narco_Deficiency.py
3    
4     Created by Emanuel Borges
5     11.04.13
6    
7     This program will create the Deficiency report from two different spreadsheets from adler.
8    
9     """
10    
11     if __name__ == '__main__':
12     mainReportContents = open(r"C:\Client\Narco\CNX Deficiency Draft (Submission 1-9) 1142013 Revised.txt").readlines()
13     commentsReportContents = open(r"C:\Client\Narco\CNX Deficiency Draft Comments (Submission 1-9) 1142013 Revised.txt").readlines()
14     outputFile = open(r"C:\Client\Narco\CNX Deficiency Draft (Submission 1-9) 1142013 Revised_OUTPUT.txt",'w')
15     boxMatrix = {}
16     claimNumberMatrix = {}
17     nameMatrix = {}
18     defReasonMatrix = {}
19     errMainReport = False
20     errCommentReport = False
21    
22     ## Verify that the number of fields is correct. 16 for comments and 13 for main
23     print "Testing file integrity..."
24     for i in mainReportContents:
25     i = i.replace("\n","")
26     i = i.split("\t")
27     if len(i) == 13:
28     pass
29     else:
30     errMainReport = 1
31     for i in commentsReportContents:
32     i = i.replace("\n","")
33     i = i.split("\t")
34     if len(i) == 16:
35     pass
36     else:
37     errCommentReport = 1
38    
39     if errMainReport:
40     print "Main report file integrity failed! Exiting."
41     elif errCommentReport:
42     print "Comment report file integrity failed! Exiting."
43     else:
44     print "Files passed integrity report. Working..."
45    
46     ## Build a matrix where ssn is the key but test for box and claim number consistency.
47     ## Granted that there can be diff people with the same name, but report this as a warning.
48     for line in mainReportContents:
49     line = line.replace("\n","")
50     line = line.split("\t")
51     boxNo = line[0]
52     claimNo = line[1]
53     ssnNo = line[2]
54     name = line[3]
55     deficiency = line[5]
56     try:
57     existingBox = boxMatrix[ssnNo]
58     if existingBox == boxNo:
59     pass
60     else:
61     print "WARNING: Found a ssn with a different box number..."
62     except:
63     boxMatrix[ssnNo] = boxNo
64     try:
65     existingClaim = claimNumberMatrix[ssnNo]
66     if existingClaim == claimNo:
67     pass
68     else:
69     print "Warning: Found a ssn with a different claim number..."
70     except:
71     claimNumberMatrix[ssnNo] = claimNo
72     try:
73     existingName = nameMatrix[ssnNo]
74     if existingName == name:
75     pass
76     else:
77     print "WARNING: Found a ssn with a different name..."
78     except:
79     nameMatrix[ssnNo] = name
80     try:
81     defReasonMatrix[ssnNo].append(deficiency)
82     except:
83     defReasonMatrix[ssnNo] = [deficiency,]
84    
85     ## Cross reference this against the second report, pivioting on the claim number
86     for line in commentsReportContents:
87     line = line.replace("\n","")
88     line = line.split("\t")
89     ssn = line[8]
90     defComment = line[15]
91     try:
92     defReasonMatrix[ssn].append(defComment)
93     except:
94     defReasonMatrix[ssn] = [defComment,]
95    
96     ## Make a report that has each claiment on one line, with all def reasons, include the comment in
97     ## second report as a def reason.
98     outputFile.write("Box\tClaim\tSSN\tName\tDeficiency Reasons\n")
99     for ssn in defReasonMatrix.keys():
100     try:
101     outputFile.write(boxMatrix[ssn] + "\t" + claimNumberMatrix[ssn]+ "\t"+ssn+ "\t"+nameMatrix[ssn])
102     except:
103     outputFile.write("\t\t"+ssn+"\t")
104     for DR in defReasonMatrix[ssn]:
105     outputFile.write("\t"+DR)
106     outputFile.write("\n")
107    
108