From 71fa408f0b046d8447b2062b6bb0dc66e8591bbc Mon Sep 17 00:00:00 2001 From: sam hatchett Date: Thu, 17 Dec 2015 13:29:47 -0500 Subject: [PATCH 1/5] removes fake python comparator --- tests/compare_enb.py | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 tests/compare_enb.py diff --git a/tests/compare_enb.py b/tests/compare_enb.py deleted file mode 100644 index be35d1d..0000000 --- a/tests/compare_enb.py +++ /dev/null @@ -1,5 +0,0 @@ -import sys -print "running fake python script..." -print "Comparing: ", str(sys.argv[1:]) -print "no idea if these are the same. i have no brains. it's probably fine." -sys.exit(0) \ No newline at end of file From eb629b83920a8ecd133a9047efe9afff2fba04e6 Mon Sep 17 00:00:00 2001 From: sam hatchett Date: Thu, 17 Dec 2015 13:33:33 -0500 Subject: [PATCH 2/5] better debug output --- tools/outputapi/ENBinaryOutDiff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/outputapi/ENBinaryOutDiff.py b/tools/outputapi/ENBinaryOutDiff.py index 0b6e06f..178ddd8 100644 --- a/tools/outputapi/ENBinaryOutDiff.py +++ b/tools/outputapi/ENBinaryOutDiff.py @@ -1 +1 @@ -''' Compares Two EPANET binary output files. Author: Bryant E. McDonnell Date: 12/16/2015 Compares the absolute value of two values against a given threshold value. ******************* Command Line Arguments: python <*.out 1> <*.out 2> Returns True / False (Pass / Fail, respectively) ******************* ''' import sys import os from math import log from ENOutputWrapper import * def BinCompare(args): # Some Error Checking for Command Line Arguments.... if len(args) < 3: raise Exception("Not Enough Input Arguments: python <*.out 1> <*.out 2>") # if not args[1].endswith('.out') or not args[2].endswith('.out'): # raise Exception("Wrong file extension: python <*.out 1> <*.out 2>") print(sys.argv[1],sys.argv[2]) dllLoc = '' if (sys.platform == 'linux2' or sys.platform == 'darwin'): dllLoc = os.getcwd() + '/libENBinaryOut.so' else: raise Exception("only implemented on mac/linux") BinFile1 = OutputObject(dllLoc) BinFile1.OpenOutputFile(args[1]) BinFile1.get_NetSize() BinFile1.get_Times() BinFile2 = OutputObject(dllLoc) BinFile2.OpenOutputFile(args[2]) ####ENR_NodeAttribute; ##ENR_demand = 0 ##ENR_head = 1 ##ENR_pressure = 2 ##ENR_quality = 3 NumberOfNodeAttr = 4 ####ENR_LinkAttribute; ##ENR_flow = 0 ##ENR_velocity = 1 ##ENR_headloss = 2 ##ENR_avgQuality = 3 ##ENR_status = 4 ##ENR_setting = 5 ##ENR_rxRate = 6 ##ENT_frctnFctr = 7 NumberOfLinkAttr = 8 NumberOfPeriods = BinFile1.numPeriods # Set Tolerances for each attribute # demand, head, pressure, quality NodeAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6] # flow, velocity, headloss, avgQuality, status, setting, rxRate, frctnFctr LinkAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6] #Compare Node Attributes for nodeAttrInd in range(NumberOfNodeAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all nodes at time t NodeAttributeOut1 = BinFile1.get_NodeAttribute(nodeAttrInd, TSind) #Get 1 attribute for all nodes at time t NodeAttributeOut2 = BinFile2.get_NodeAttribute(nodeAttrInd, TSind) for Nodeind, NodeAttrVal in enumerate(NodeAttributeOut1): if abs(NodeAttrVal - NodeAttributeOut2[Nodeind]) > 0: diff = abs(NodeAttrVal - NodeAttributeOut2[Nodeind] ) if diff > NodeAttributeTolerances[nodeAttrInd]: return False #Compare Link Attributes for linkAttrInd in range(NumberOfLinkAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all links at time t LinkAttributeOut1 = BinFile1.get_NodeAttribute(linkAttrInd, TSind) #Get 1 attribute for all links at time t LinkAttributeOut2 = BinFile2.get_NodeAttribute(linkAttrInd, TSind) for linkind, LinkAttrVal in enumerate(LinkAttributeOut1): if abs(LinkAttrVal - LinkAttributeOut2[linkind]) > 0: diff = abs(LinkAttrVal - LinkAttributeOut2[linkind] ) if diff > LinkAttributeTolerances[linkAttrInd]: return False return True if __name__ == '__main__': if(BinCompare(sys.argv)): sys.exit(0) else: sys.exit(1) \ No newline at end of file +''' Compares Two EPANET binary output files. Author: Bryant E. McDonnell Date: 12/16/2015 Compares the absolute value of two values against a given threshold value. ******************* Command Line Arguments: python <*.out 1> <*.out 2> Returns True / False (Pass / Fail, respectively) ******************* ''' import sys import os from math import log from ENOutputWrapper import * def BinCompare(args): # Some Error Checking for Command Line Arguments.... if len(args) < 3: raise Exception("Not Enough Input Arguments: python <*.out 1> <*.out 2>") # if not args[1].endswith('.out') or not args[2].endswith('.out'): # raise Exception("Wrong file extension: python <*.out 1> <*.out 2>") print(sys.argv[1],sys.argv[2]) dllLoc = '' if (sys.platform == 'linux2' or sys.platform == 'darwin'): dllLoc = os.getcwd() + '/libENBinaryOut.so' else: raise Exception("only implemented on mac/linux") BinFile1 = OutputObject(dllLoc) BinFile1.OpenOutputFile(args[1]) BinFile1.get_NetSize() BinFile1.get_Times() BinFile2 = OutputObject(dllLoc) BinFile2.OpenOutputFile(args[2]) ####ENR_NodeAttribute; ##ENR_demand = 0 ##ENR_head = 1 ##ENR_pressure = 2 ##ENR_quality = 3 NumberOfNodeAttr = 4 ####ENR_LinkAttribute; ##ENR_flow = 0 ##ENR_velocity = 1 ##ENR_headloss = 2 ##ENR_avgQuality = 3 ##ENR_status = 4 ##ENR_setting = 5 ##ENR_rxRate = 6 ##ENT_frctnFctr = 7 NumberOfLinkAttr = 8 NumberOfPeriods = BinFile1.numPeriods # Set Tolerances for each attribute # demand, head, pressure, quality NodeAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6] # flow, velocity, headloss, avgQuality, status, setting, rxRate, frctnFctr LinkAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6] #Compare Node Attributes for nodeAttrInd in range(NumberOfNodeAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all nodes at time t NodeAttributeOut1 = BinFile1.get_NodeAttribute(nodeAttrInd, TSind) #Get 1 attribute for all nodes at time t NodeAttributeOut2 = BinFile2.get_NodeAttribute(nodeAttrInd, TSind) for Nodeind, NodeAttrVal in enumerate(NodeAttributeOut1): if abs(NodeAttrVal - NodeAttributeOut2[Nodeind]) > 0: diff = abs(NodeAttrVal - NodeAttributeOut2[Nodeind] ) if diff > NodeAttributeTolerances[nodeAttrInd]: print "Node " + string(Nodeind) + " attribute " + string(nodeAttrInd) + "exceeded tolerance" return False #Compare Link Attributes for linkAttrInd in range(NumberOfLinkAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all links at time t LinkAttributeOut1 = BinFile1.get_NodeAttribute(linkAttrInd, TSind) #Get 1 attribute for all links at time t LinkAttributeOut2 = BinFile2.get_NodeAttribute(linkAttrInd, TSind) for linkind, LinkAttrVal in enumerate(LinkAttributeOut1): if abs(LinkAttrVal - LinkAttributeOut2[linkind]) > 0: diff = abs(LinkAttrVal - LinkAttributeOut2[linkind] ) if diff > LinkAttributeTolerances[linkAttrInd]: print "Link " + string(linkind) + " attribute " + string(linkAttrInd) + "exceeded tolerance" return False return True if __name__ == '__main__': if(BinCompare(sys.argv)): sys.exit(0) else: sys.exit(1) \ No newline at end of file From 81fa79745a4cb65e7361753bd3c7092fefcc9bf6 Mon Sep 17 00:00:00 2001 From: sam hatchett Date: Thu, 17 Dec 2015 13:36:53 -0500 Subject: [PATCH 3/5] fixing python printing --- tools/outputapi/ENBinaryOutDiff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/outputapi/ENBinaryOutDiff.py b/tools/outputapi/ENBinaryOutDiff.py index 178ddd8..4821a47 100644 --- a/tools/outputapi/ENBinaryOutDiff.py +++ b/tools/outputapi/ENBinaryOutDiff.py @@ -1 +1 @@ -''' Compares Two EPANET binary output files. Author: Bryant E. McDonnell Date: 12/16/2015 Compares the absolute value of two values against a given threshold value. ******************* Command Line Arguments: python <*.out 1> <*.out 2> Returns True / False (Pass / Fail, respectively) ******************* ''' import sys import os from math import log from ENOutputWrapper import * def BinCompare(args): # Some Error Checking for Command Line Arguments.... if len(args) < 3: raise Exception("Not Enough Input Arguments: python <*.out 1> <*.out 2>") # if not args[1].endswith('.out') or not args[2].endswith('.out'): # raise Exception("Wrong file extension: python <*.out 1> <*.out 2>") print(sys.argv[1],sys.argv[2]) dllLoc = '' if (sys.platform == 'linux2' or sys.platform == 'darwin'): dllLoc = os.getcwd() + '/libENBinaryOut.so' else: raise Exception("only implemented on mac/linux") BinFile1 = OutputObject(dllLoc) BinFile1.OpenOutputFile(args[1]) BinFile1.get_NetSize() BinFile1.get_Times() BinFile2 = OutputObject(dllLoc) BinFile2.OpenOutputFile(args[2]) ####ENR_NodeAttribute; ##ENR_demand = 0 ##ENR_head = 1 ##ENR_pressure = 2 ##ENR_quality = 3 NumberOfNodeAttr = 4 ####ENR_LinkAttribute; ##ENR_flow = 0 ##ENR_velocity = 1 ##ENR_headloss = 2 ##ENR_avgQuality = 3 ##ENR_status = 4 ##ENR_setting = 5 ##ENR_rxRate = 6 ##ENT_frctnFctr = 7 NumberOfLinkAttr = 8 NumberOfPeriods = BinFile1.numPeriods # Set Tolerances for each attribute # demand, head, pressure, quality NodeAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6] # flow, velocity, headloss, avgQuality, status, setting, rxRate, frctnFctr LinkAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6] #Compare Node Attributes for nodeAttrInd in range(NumberOfNodeAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all nodes at time t NodeAttributeOut1 = BinFile1.get_NodeAttribute(nodeAttrInd, TSind) #Get 1 attribute for all nodes at time t NodeAttributeOut2 = BinFile2.get_NodeAttribute(nodeAttrInd, TSind) for Nodeind, NodeAttrVal in enumerate(NodeAttributeOut1): if abs(NodeAttrVal - NodeAttributeOut2[Nodeind]) > 0: diff = abs(NodeAttrVal - NodeAttributeOut2[Nodeind] ) if diff > NodeAttributeTolerances[nodeAttrInd]: print "Node " + string(Nodeind) + " attribute " + string(nodeAttrInd) + "exceeded tolerance" return False #Compare Link Attributes for linkAttrInd in range(NumberOfLinkAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all links at time t LinkAttributeOut1 = BinFile1.get_NodeAttribute(linkAttrInd, TSind) #Get 1 attribute for all links at time t LinkAttributeOut2 = BinFile2.get_NodeAttribute(linkAttrInd, TSind) for linkind, LinkAttrVal in enumerate(LinkAttributeOut1): if abs(LinkAttrVal - LinkAttributeOut2[linkind]) > 0: diff = abs(LinkAttrVal - LinkAttributeOut2[linkind] ) if diff > LinkAttributeTolerances[linkAttrInd]: print "Link " + string(linkind) + " attribute " + string(linkAttrInd) + "exceeded tolerance" return False return True if __name__ == '__main__': if(BinCompare(sys.argv)): sys.exit(0) else: sys.exit(1) \ No newline at end of file +''' Compares Two EPANET binary output files. Author: Bryant E. McDonnell Date: 12/16/2015 Compares the absolute value of two values against a given threshold value. ******************* Command Line Arguments: python <*.out 1> <*.out 2> Returns True / False (Pass / Fail, respectively) ******************* ''' import sys import os from math import log from ENOutputWrapper import * def BinCompare(args): # Some Error Checking for Command Line Arguments.... if len(args) < 3: raise Exception("Not Enough Input Arguments: python <*.out 1> <*.out 2>") # if not args[1].endswith('.out') or not args[2].endswith('.out'): # raise Exception("Wrong file extension: python <*.out 1> <*.out 2>") print(sys.argv[1],sys.argv[2]) dllLoc = '' if (sys.platform == 'linux2' or sys.platform == 'darwin'): dllLoc = os.getcwd() + '/libENBinaryOut.so' else: raise Exception("only implemented on mac/linux") BinFile1 = OutputObject(dllLoc) BinFile1.OpenOutputFile(args[1]) BinFile1.get_NetSize() BinFile1.get_Times() BinFile2 = OutputObject(dllLoc) BinFile2.OpenOutputFile(args[2]) ####ENR_NodeAttribute; ##ENR_demand = 0 ##ENR_head = 1 ##ENR_pressure = 2 ##ENR_quality = 3 NumberOfNodeAttr = 4 ####ENR_LinkAttribute; ##ENR_flow = 0 ##ENR_velocity = 1 ##ENR_headloss = 2 ##ENR_avgQuality = 3 ##ENR_status = 4 ##ENR_setting = 5 ##ENR_rxRate = 6 ##ENT_frctnFctr = 7 NumberOfLinkAttr = 8 NumberOfPeriods = BinFile1.numPeriods # Set Tolerances for each attribute # demand, head, pressure, quality NodeAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6] # flow, velocity, headloss, avgQuality, status, setting, rxRate, frctnFctr LinkAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6] #Compare Node Attributes for nodeAttrInd in range(NumberOfNodeAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all nodes at time t NodeAttributeOut1 = BinFile1.get_NodeAttribute(nodeAttrInd, TSind) #Get 1 attribute for all nodes at time t NodeAttributeOut2 = BinFile2.get_NodeAttribute(nodeAttrInd, TSind) for Nodeind, NodeAttrVal in enumerate(NodeAttributeOut1): if abs(NodeAttrVal - NodeAttributeOut2[Nodeind]) > 0: diff = abs(NodeAttrVal - NodeAttributeOut2[Nodeind] ) if diff > NodeAttributeTolerances[nodeAttrInd]: print ("Node ", Nodeind, " attribute ", nodeAttrInd, "exceeded tolerance") return False #Compare Link Attributes for linkAttrInd in range(NumberOfLinkAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all links at time t LinkAttributeOut1 = BinFile1.get_NodeAttribute(linkAttrInd, TSind) #Get 1 attribute for all links at time t LinkAttributeOut2 = BinFile2.get_NodeAttribute(linkAttrInd, TSind) for linkind, LinkAttrVal in enumerate(LinkAttributeOut1): if abs(LinkAttrVal - LinkAttributeOut2[linkind]) > 0: diff = abs(LinkAttrVal - LinkAttributeOut2[linkind] ) if diff > LinkAttributeTolerances[linkAttrInd]: print ("Link ", linkind, " attribute ", linkAttrInd, "exceeded tolerance") return False return True if __name__ == '__main__': if(BinCompare(sys.argv)): sys.exit(0) else: sys.exit(1) \ No newline at end of file From 8fe3bbef2369035a50e210e5d5ccd5014061c7da Mon Sep 17 00:00:00 2001 From: sam hatchett Date: Thu, 17 Dec 2015 13:46:32 -0500 Subject: [PATCH 4/5] fixes diff script --- tools/outputapi/ENBinaryOutDiff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/outputapi/ENBinaryOutDiff.py b/tools/outputapi/ENBinaryOutDiff.py index 4821a47..cf188ea 100644 --- a/tools/outputapi/ENBinaryOutDiff.py +++ b/tools/outputapi/ENBinaryOutDiff.py @@ -1 +1 @@ -''' Compares Two EPANET binary output files. Author: Bryant E. McDonnell Date: 12/16/2015 Compares the absolute value of two values against a given threshold value. ******************* Command Line Arguments: python <*.out 1> <*.out 2> Returns True / False (Pass / Fail, respectively) ******************* ''' import sys import os from math import log from ENOutputWrapper import * def BinCompare(args): # Some Error Checking for Command Line Arguments.... if len(args) < 3: raise Exception("Not Enough Input Arguments: python <*.out 1> <*.out 2>") # if not args[1].endswith('.out') or not args[2].endswith('.out'): # raise Exception("Wrong file extension: python <*.out 1> <*.out 2>") print(sys.argv[1],sys.argv[2]) dllLoc = '' if (sys.platform == 'linux2' or sys.platform == 'darwin'): dllLoc = os.getcwd() + '/libENBinaryOut.so' else: raise Exception("only implemented on mac/linux") BinFile1 = OutputObject(dllLoc) BinFile1.OpenOutputFile(args[1]) BinFile1.get_NetSize() BinFile1.get_Times() BinFile2 = OutputObject(dllLoc) BinFile2.OpenOutputFile(args[2]) ####ENR_NodeAttribute; ##ENR_demand = 0 ##ENR_head = 1 ##ENR_pressure = 2 ##ENR_quality = 3 NumberOfNodeAttr = 4 ####ENR_LinkAttribute; ##ENR_flow = 0 ##ENR_velocity = 1 ##ENR_headloss = 2 ##ENR_avgQuality = 3 ##ENR_status = 4 ##ENR_setting = 5 ##ENR_rxRate = 6 ##ENT_frctnFctr = 7 NumberOfLinkAttr = 8 NumberOfPeriods = BinFile1.numPeriods # Set Tolerances for each attribute # demand, head, pressure, quality NodeAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6] # flow, velocity, headloss, avgQuality, status, setting, rxRate, frctnFctr LinkAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6] #Compare Node Attributes for nodeAttrInd in range(NumberOfNodeAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all nodes at time t NodeAttributeOut1 = BinFile1.get_NodeAttribute(nodeAttrInd, TSind) #Get 1 attribute for all nodes at time t NodeAttributeOut2 = BinFile2.get_NodeAttribute(nodeAttrInd, TSind) for Nodeind, NodeAttrVal in enumerate(NodeAttributeOut1): if abs(NodeAttrVal - NodeAttributeOut2[Nodeind]) > 0: diff = abs(NodeAttrVal - NodeAttributeOut2[Nodeind] ) if diff > NodeAttributeTolerances[nodeAttrInd]: print ("Node ", Nodeind, " attribute ", nodeAttrInd, "exceeded tolerance") return False #Compare Link Attributes for linkAttrInd in range(NumberOfLinkAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all links at time t LinkAttributeOut1 = BinFile1.get_NodeAttribute(linkAttrInd, TSind) #Get 1 attribute for all links at time t LinkAttributeOut2 = BinFile2.get_NodeAttribute(linkAttrInd, TSind) for linkind, LinkAttrVal in enumerate(LinkAttributeOut1): if abs(LinkAttrVal - LinkAttributeOut2[linkind]) > 0: diff = abs(LinkAttrVal - LinkAttributeOut2[linkind] ) if diff > LinkAttributeTolerances[linkAttrInd]: print ("Link ", linkind, " attribute ", linkAttrInd, "exceeded tolerance") return False return True if __name__ == '__main__': if(BinCompare(sys.argv)): sys.exit(0) else: sys.exit(1) \ No newline at end of file +''' Compares Two EPANET binary output files. Author: Bryant E. McDonnell Date: 12/16/2015 Compares the absolute value of two values against a given threshold value. ******************* Command Line Arguments: python <*.out 1> <*.out 2> Returns True / False (Pass / Fail, respectively) ******************* ''' import sys import os from math import log from ENOutputWrapper import * def BinCompare(args): # Some Error Checking for Command Line Arguments.... if len(args) < 3: raise Exception("Not Enough Input Arguments: python <*.out 1> <*.out 2>") # if not args[1].endswith('.out') or not args[2].endswith('.out'): # raise Exception("Wrong file extension: python <*.out 1> <*.out 2>") print(sys.argv[1],sys.argv[2]) dllLoc = '' if (sys.platform == 'linux2' or sys.platform == 'darwin'): dllLoc = os.getcwd() + '/libENBinaryOut.so' else: raise Exception("only implemented on mac/linux") BinFile1 = OutputObject(dllLoc) BinFile1.OpenOutputFile(args[1]) BinFile1.get_NetSize() BinFile1.get_Times() BinFile2 = OutputObject(dllLoc) BinFile2.OpenOutputFile(args[2]) ####ENR_NodeAttribute; ##ENR_demand = 0 ##ENR_head = 1 ##ENR_pressure = 2 ##ENR_quality = 3 NumberOfNodeAttr = 4 ####ENR_LinkAttribute; ##ENR_flow = 0 ##ENR_velocity = 1 ##ENR_headloss = 2 ##ENR_avgQuality = 3 ##ENR_status = 4 ##ENR_setting = 5 ##ENR_rxRate = 6 ##ENT_frctnFctr = 7 NumberOfLinkAttr = 8 NumberOfPeriods = BinFile1.numPeriods # Set Tolerances for each attribute # demand, head, pressure, quality NodeAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6] # flow, velocity, headloss, avgQuality, status, setting, rxRate, frctnFctr LinkAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6] #Compare Node Attributes for nodeAttrInd in range(NumberOfNodeAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all nodes at time t NodeAttributeOut1 = BinFile1.get_NodeAttribute(nodeAttrInd, TSind) #Get 1 attribute for all nodes at time t NodeAttributeOut2 = BinFile2.get_NodeAttribute(nodeAttrInd, TSind) for Nodeind, NodeAttrVal in enumerate(NodeAttributeOut1): if abs(NodeAttrVal - NodeAttributeOut2[Nodeind]) > 0: diff = abs(NodeAttrVal - NodeAttributeOut2[Nodeind] ) if diff > NodeAttributeTolerances[nodeAttrInd]: print("Node {0} attribute {1} exceeded tolerance. value 1 = {3} :: value 2 = {4} :: delta = {5}".format(Nodeind, nodeAttrInd, NodeAttrVal, NodeAttributeOut2[Nodeind], diff) ) return False #Compare Link Attributes for linkAttrInd in range(NumberOfLinkAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all links at time t LinkAttributeOut1 = BinFile1.get_LinkAttribute(linkAttrInd, TSind) #Get 1 attribute for all links at time t LinkAttributeOut2 = BinFile2.get_LinkAttribute(linkAttrInd, TSind) for linkind, LinkAttrVal in enumerate(LinkAttributeOut1): if abs(LinkAttrVal - LinkAttributeOut2[linkind]) > 0: diff = abs(LinkAttrVal - LinkAttributeOut2[linkind] ) if diff > LinkAttributeTolerances[linkAttrInd]: print("Link {0} attribute {1} exceeded tolerance. value 1 = {3} :: value 2 = {4} :: delta = {5}".format(linkind, linkAttrInd, LinkAttrVal, LinkAttributeOut2[linkind], diff) ) return False return True if __name__ == '__main__': if(BinCompare(sys.argv)): sys.exit(0) else: sys.exit(1) \ No newline at end of file From ff6225372a69ee630a35c3a9b00fa2a1853ec1bd Mon Sep 17 00:00:00 2001 From: sam hatchett Date: Thu, 17 Dec 2015 13:49:23 -0500 Subject: [PATCH 5/5] there are two hard problems. naming things and counting things --- tools/outputapi/ENBinaryOutDiff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/outputapi/ENBinaryOutDiff.py b/tools/outputapi/ENBinaryOutDiff.py index cf188ea..9754a2a 100644 --- a/tools/outputapi/ENBinaryOutDiff.py +++ b/tools/outputapi/ENBinaryOutDiff.py @@ -1 +1 @@ -''' Compares Two EPANET binary output files. Author: Bryant E. McDonnell Date: 12/16/2015 Compares the absolute value of two values against a given threshold value. ******************* Command Line Arguments: python <*.out 1> <*.out 2> Returns True / False (Pass / Fail, respectively) ******************* ''' import sys import os from math import log from ENOutputWrapper import * def BinCompare(args): # Some Error Checking for Command Line Arguments.... if len(args) < 3: raise Exception("Not Enough Input Arguments: python <*.out 1> <*.out 2>") # if not args[1].endswith('.out') or not args[2].endswith('.out'): # raise Exception("Wrong file extension: python <*.out 1> <*.out 2>") print(sys.argv[1],sys.argv[2]) dllLoc = '' if (sys.platform == 'linux2' or sys.platform == 'darwin'): dllLoc = os.getcwd() + '/libENBinaryOut.so' else: raise Exception("only implemented on mac/linux") BinFile1 = OutputObject(dllLoc) BinFile1.OpenOutputFile(args[1]) BinFile1.get_NetSize() BinFile1.get_Times() BinFile2 = OutputObject(dllLoc) BinFile2.OpenOutputFile(args[2]) ####ENR_NodeAttribute; ##ENR_demand = 0 ##ENR_head = 1 ##ENR_pressure = 2 ##ENR_quality = 3 NumberOfNodeAttr = 4 ####ENR_LinkAttribute; ##ENR_flow = 0 ##ENR_velocity = 1 ##ENR_headloss = 2 ##ENR_avgQuality = 3 ##ENR_status = 4 ##ENR_setting = 5 ##ENR_rxRate = 6 ##ENT_frctnFctr = 7 NumberOfLinkAttr = 8 NumberOfPeriods = BinFile1.numPeriods # Set Tolerances for each attribute # demand, head, pressure, quality NodeAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6] # flow, velocity, headloss, avgQuality, status, setting, rxRate, frctnFctr LinkAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6] #Compare Node Attributes for nodeAttrInd in range(NumberOfNodeAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all nodes at time t NodeAttributeOut1 = BinFile1.get_NodeAttribute(nodeAttrInd, TSind) #Get 1 attribute for all nodes at time t NodeAttributeOut2 = BinFile2.get_NodeAttribute(nodeAttrInd, TSind) for Nodeind, NodeAttrVal in enumerate(NodeAttributeOut1): if abs(NodeAttrVal - NodeAttributeOut2[Nodeind]) > 0: diff = abs(NodeAttrVal - NodeAttributeOut2[Nodeind] ) if diff > NodeAttributeTolerances[nodeAttrInd]: print("Node {0} attribute {1} exceeded tolerance. value 1 = {3} :: value 2 = {4} :: delta = {5}".format(Nodeind, nodeAttrInd, NodeAttrVal, NodeAttributeOut2[Nodeind], diff) ) return False #Compare Link Attributes for linkAttrInd in range(NumberOfLinkAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all links at time t LinkAttributeOut1 = BinFile1.get_LinkAttribute(linkAttrInd, TSind) #Get 1 attribute for all links at time t LinkAttributeOut2 = BinFile2.get_LinkAttribute(linkAttrInd, TSind) for linkind, LinkAttrVal in enumerate(LinkAttributeOut1): if abs(LinkAttrVal - LinkAttributeOut2[linkind]) > 0: diff = abs(LinkAttrVal - LinkAttributeOut2[linkind] ) if diff > LinkAttributeTolerances[linkAttrInd]: print("Link {0} attribute {1} exceeded tolerance. value 1 = {3} :: value 2 = {4} :: delta = {5}".format(linkind, linkAttrInd, LinkAttrVal, LinkAttributeOut2[linkind], diff) ) return False return True if __name__ == '__main__': if(BinCompare(sys.argv)): sys.exit(0) else: sys.exit(1) \ No newline at end of file +''' Compares Two EPANET binary output files. Author: Bryant E. McDonnell Date: 12/16/2015 Compares the absolute value of two values against a given threshold value. ******************* Command Line Arguments: python <*.out 1> <*.out 2> Returns True / False (Pass / Fail, respectively) ******************* ''' import sys import os from math import log from ENOutputWrapper import * def BinCompare(args): # Some Error Checking for Command Line Arguments.... if len(args) < 3: raise Exception("Not Enough Input Arguments: python <*.out 1> <*.out 2>") # if not args[1].endswith('.out') or not args[2].endswith('.out'): # raise Exception("Wrong file extension: python <*.out 1> <*.out 2>") print(sys.argv[1],sys.argv[2]) dllLoc = '' if (sys.platform == 'linux2' or sys.platform == 'darwin'): dllLoc = os.getcwd() + '/libENBinaryOut.so' else: raise Exception("only implemented on mac/linux") BinFile1 = OutputObject(dllLoc) BinFile1.OpenOutputFile(args[1]) BinFile1.get_NetSize() BinFile1.get_Times() BinFile2 = OutputObject(dllLoc) BinFile2.OpenOutputFile(args[2]) ####ENR_NodeAttribute; ##ENR_demand = 0 ##ENR_head = 1 ##ENR_pressure = 2 ##ENR_quality = 3 NumberOfNodeAttr = 4 ####ENR_LinkAttribute; ##ENR_flow = 0 ##ENR_velocity = 1 ##ENR_headloss = 2 ##ENR_avgQuality = 3 ##ENR_status = 4 ##ENR_setting = 5 ##ENR_rxRate = 6 ##ENT_frctnFctr = 7 NumberOfLinkAttr = 8 NumberOfPeriods = BinFile1.numPeriods # Set Tolerances for each attribute # demand, head, pressure, quality NodeAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6] # flow, velocity, headloss, avgQuality, status, setting, rxRate, frctnFctr LinkAttributeTolerances = [1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6, 1e-6] #Compare Node Attributes for nodeAttrInd in range(NumberOfNodeAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all nodes at time t NodeAttributeOut1 = BinFile1.get_NodeAttribute(nodeAttrInd, TSind) #Get 1 attribute for all nodes at time t NodeAttributeOut2 = BinFile2.get_NodeAttribute(nodeAttrInd, TSind) for Nodeind, NodeAttrVal in enumerate(NodeAttributeOut1): if abs(NodeAttrVal - NodeAttributeOut2[Nodeind]) > 0: diff = abs(NodeAttrVal - NodeAttributeOut2[Nodeind] ) if diff > NodeAttributeTolerances[nodeAttrInd]: print("Node {0} attribute {1} exceeded tolerance. value 1 = {2} :: value 2 = {3} :: delta = {4}".format(Nodeind, nodeAttrInd, NodeAttrVal, NodeAttributeOut2[Nodeind], diff) ) return False #Compare Link Attributes for linkAttrInd in range(NumberOfLinkAttr): for TSind in range(NumberOfPeriods): #Get 1 attribute for all links at time t LinkAttributeOut1 = BinFile1.get_LinkAttribute(linkAttrInd, TSind) #Get 1 attribute for all links at time t LinkAttributeOut2 = BinFile2.get_LinkAttribute(linkAttrInd, TSind) for linkind, LinkAttrVal in enumerate(LinkAttributeOut1): if abs(LinkAttrVal - LinkAttributeOut2[linkind]) > 0: diff = abs(LinkAttrVal - LinkAttributeOut2[linkind] ) if diff > LinkAttributeTolerances[linkAttrInd]: print("Link {0} attribute {1} exceeded tolerance. value 1 = {2} :: value 2 = {3} :: delta = {4}".format(linkind, linkAttrInd, LinkAttrVal, LinkAttributeOut2[linkind], diff) ) return False return True if __name__ == '__main__': if(BinCompare(sys.argv)): sys.exit(0) else: sys.exit(1) \ No newline at end of file