Merge pull request #62 from OpenWaterAnalytics/dev-2.1-debug-python-test

Dev 2.1 debug python test
This commit is contained in:
Sam Hatchett
2015-12-17 13:52:52 -05:00
2 changed files with 1 additions and 6 deletions
-5
View File
@@ -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)
+1 -1
View File
@@ -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 <OutDiff.py> <*.out 1> <*.out 2> ␍␍␍Returns True / False (Pass / Fail, respectively)␍␍␍*******************␍'''import sysimport osfrom math import logfrom ENOutputWrapper import *def BinCompare(args): # Some Error Checking for Command Line Arguments....␍ if len(args) < 3:␍ raise Exception("Not Enough Input Arguments: python <ENBinaryOutDiff.py> <*.out 1> <*.out 2>")␍# if not args[1].endswith('.out') or not args[2].endswith('.out'):␍# raise Exception("Wrong file extension: python <ENBinaryOutDiff.py> <*.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)␍
'''␍␍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 <OutDiff.py> <*.out 1> <*.out 2> ␍␍␍Returns True / False (Pass / Fail, respectively)␍␍␍*******************␍'''import sysimport osfrom math import logfrom ENOutputWrapper import *def BinCompare(args): # Some Error Checking for Command Line Arguments....␍ if len(args) < 3:␍ raise Exception("Not Enough Input Arguments: python <ENBinaryOutDiff.py> <*.out 1> <*.out 2>")␍# if not args[1].endswith('.out') or not args[2].endswith('.out'):␍# raise Exception("Wrong file extension: python <ENBinaryOutDiff.py> <*.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)␍