# Applied Python PRISM
# (PRISM) PaRametrIc System Model
#
# Written by Charlie Taylor <cet@appliedpython.com>
# Oct,21 2005
from prism.Summary import Summary
from prism.MassItem import MassItem
def compareItemNames(tup1, tup2):
return cmp(tup1[0].upper(), tup2[0].upper())
def compareItemMass(tup1, tup2):
return cmp(tup2[1], tup1[1])
class Misc_Weights( MassItem ):
'''Mass Item in PRISM'''
def __init__(self, name="Misc. Mass Items", type="inert", mass_lbm=0.0):
MassItem.__init__(self, name, type=type)
self.name = name
self.type = type # type can be "fluid", "inert", "propellant", etc.
self.itemsList = []
self.mass_lbm = mass_lbm # if add_item never called, this mass remains
def reCalc(self):
'''Override this routine for non-constant mass items'''
pass
def add_item(self, name="misc item", mass_lbm=0.0 ):
self.itemsList.append( (name, mass_lbm) )
self.mass_lbm = 0.0
self.itemsList.sort( compareItemNames )
for n,m in self.itemsList:
self.mass_lbm += m
def getMassStr(self):
return '%12.3f lbm %s'%(self.mass_lbm,self.name)
def buildSummary(self):
summ = Summary( summName='Miscellaneous Mass Items',
componentName=self.name, mass_lbm=self.mass_lbm, type=self.type)
summ.addAssumption( 'All items are of type: ' + self.type )
if len(self.itemsList)>1:
summ.addInput(' ===SORT ORDER===','Alphabetical', '', '%s')
for n,m in self.itemsList:
# add inputs
summ.addInput(n, m, 'lbm', '%7.3f')
dummyList = self.itemsList[:]
dummyList.sort(compareItemMass)
if len(self.itemsList)>1:
summ.addOutput(' ===SORT ORDER===','Mass', '', '%s')
for n,m in dummyList:
# add inputs
summ.addOutput(n, m, 'lbm', '%7.3f')
return summ
def getItemTextSummary(self):
summ = self.buildSummary()
return summ.getItemTextSummary()
def getSummary(self):
return self.getItemTextSummary()
def getItemHTMLSummary(self):
summ = self.buildSummary()
return summ.getItemHTMLSummary()
if __name__ == "__main__": #self test
h = Misc_Weights(name="Test Articles", mass_lbm=1.12345)
print h.getMassStr()
h.add_item("item #1", 1.111)
h.add_item("item #6", 6.666)
h.add_item("item #2", 2.222)
h.add_item("item #4", 4.444)
h.add_item("item #5", 5.555)
h.add_item("item #3", 3.333)
print
print h.getSummary()
print
#print h.getItemHTMLSummary()