ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Redgrave/EndoMultipleRowDataCompare.py
Revision: 763
Committed: Fri Jul 30 14:45:31 2021 UTC (4 years, 7 months ago) by nino.borges
Content type: text/x-python
File size: 2786 byte(s)
Log Message:
This program will take the results from EndoMultipleTableFieldCompare and will check the rows in those tables to see if they are also the same. This is slightly less useful if you only have a top 50 row sample.  better if it's the full table dumps.

File Contents

# Content
1 """
2
3 EndoMultipleRowDataCompare
4
5 Created by:
6 Emanuel Borges
7 07.27.2021
8
9 This program will take the results from EndoMultipleTableFieldCompare and will
10 check the rows in those tables to see if they are also the same.
11
12 """
13
14 import os
15 from datetime import datetime
16
17 if __name__ == '__main__':
18 ## Main directory of exported csv files.
19 mainDir = r"C:\Users\eborges\Downloads\all_csv_test\csv\SFA"
20 fieldReportFileName = r"C:\Users\eborges\Documents\Cases\Endo\Temp\DatabaseReports\20210723_Tables_Rows\csvVersion\sfa_MannyAnalysis(identicalTo).txt"
21 #fieldNameStart = "endo_master_retore_"
22 fieldNameStart = "SFA_"
23
24
25
26 print("Checking file consistencies...")
27 consistencyFlag = True
28 for f in os.listdir(mainDir):
29 contents = open(os.path.join(mainDir,f), encoding='UTF16').readlines()
30 if len(contents) < 53:
31 pass
32 else:
33 consistencyFlag = False
34
35 if consistencyFlag == True:
36 print("Consistency test passed.")
37 contents = open(fieldReportFileName).readlines()
38 compareMatrix = {}
39 for line in contents:
40 line = line.replace("\n","")
41 line = line.replace("The field list in ","")
42 line = line.split(" is identical to fields in ")
43 if line[0] in list(compareMatrix.keys()):
44 compareMatrix[line[0]].append(line[1])
45 else:
46 compareMatrix[line[0]] = [line[1],]
47
48 print ("%s keys to compare"% len(compareMatrix.keys()))
49
50 matchList = []
51 for t in list(compareMatrix.keys()):
52 sourceFileName = "%s%s_top_50.csv"%(fieldNameStart,t)
53 sourceFileName = sourceFileName.replace(":","-")
54 sourceContents = open(os.path.join(mainDir, sourceFileName), encoding='UTF-16').readlines()
55 sourceContents = sourceContents[2:]
56 for sT in compareMatrix[t]:
57 targetFileName = "%s%s_top_50.csv"%(fieldNameStart,sT)
58 targetFileName = targetFileName.replace(":","-")
59 targetContents = open(os.path.join(mainDir, targetFileName), encoding='UTF-16').readlines()
60 targetContents = targetContents[2:]
61 print("now comparing %s to %s"% (t,sT))
62 if targetContents == sourceContents:
63 matchList.append([t,sT])
64
65 newMatchList = []
66 for elem in matchList:
67 elem.sort()
68 if elem not in newMatchList:
69 newMatchList.append(elem)
70
71 print("Process Finished.\nThere are %s match pairs."% len(newMatchList))
72 for i in newMatchList:
73 print(i)
74
75 else:
76 print("There are consistency issues.")