def ensureC21(obj_snmp): """The input quantity and the max unit must have the same dimension """ if obj_snmp.maxQuantityAbs: convPQinpQuantity = convertQuantity(obj_snmp.inpQuantity) convPQmaxQuantityAbs = convertQuantity(obj_snmp.maxQuantityAbs) physFactor = convPQinpQuantity / convPQmaxQuantityAbs if not physFactor.dimensionless(): raise Invalid("The input quantity '%s' and the "\ "max unit '%s'"\ " must have the same dimension" \ % (convPQinpQuantity, convPQmaxQuantityAbs))
def ensureCapacityUnit(physicalMedia): if physicalMedia.capacity is not None: physicalInput = convertQuantity(physicalMedia.capacity) if not physicalInput.isBitUnit(): raise Invalid( "No capacity specification: '%s'." % \ (physicalMedia.capacity))
def ensureAnnualChargesUnit(contract): if contract.annualCharges is not None: annualCharges = convertQuantity(contract.annualCharges) if not annualCharges.isCurrency(): raise Invalid( "No currency specification: '%s'." % \ (contract.annualCharges))
def ensureC1(obj_snmp): """The input quantity must have a dimension """ convPQinpQuantity = convertQuantity(obj_snmp.inpQuantity) if convPQinpQuantity.dimensionless(): raise Invalid("The input quantity '%s' must have a dimension" \ % (convPQinpQuantity))
def ensureLengthUnit(link): if link.length is not None: physicalInput = convertQuantity(link.length) if not physicalInput.isLength(): raise Invalid( "No length specification: '%s'." % \ (link.length))
def ensureC23(obj_snmp): """The input quantity and the max unit (acceleration) * s * s must have the same dimension """ if obj_snmp.maxQuantityAcceleration: convPQinpQuantity = convertQuantity(obj_snmp.inpQuantity) convPQmaxQuantityAcceleration = convertQuantity(\ obj_snmp.maxQuantityAcceleration) physFactor = convPQmaxQuantityAcceleration \ / convPQinpQuantity \ * physq(1.0, "s2") if not physFactor.dimensionless(): raise Invalid("The input quantity '%s' and the "\ "max unit (acceleration) '%s' * s * s"\ " must have the same dimension" \ % (convPQinpQuantity, convPQmaxQuantityAcceleration))
def ensureC22(obj_snmp): """The input quantity and the max unit (velocity) '%s' * s must have the same dimension """ if obj_snmp.maxQuantityVelocity: convPQinpQuantity = convertQuantity(obj_snmp.inpQuantity) convPQmaxQuantityVelocity = convertQuantity(\ obj_snmp.maxQuantityVelocity) physFactor = convPQmaxQuantityVelocity \ / convPQinpQuantity \ * physq(1.0, "s") if not physFactor.dimensionless(): raise Invalid("The input quantity '%s' and the "\ "max unit (velocity) '%s' * s"\ " must have the same dimension" \ % (convPQinpQuantity, convPQmaxQuantityVelocity))
def ensureMaxLength4LinkType(link): if link.length is not None: physicalInput = convertQuantity(link.length) physicalMaxLength = maxLength4LinkType(link.mediaType) if physicalInput > physicalMaxLength: raise Invalid( "Length over: '%s'." % \ (physicalMaxLength))
def getMaxQuantity(self): """get unit tuple (maxQuantity, maxString) """ maxQuantity = None maxString = None if self.inptype == u"cnt": if self.maxQuantityVelocity is not None: maxQuantity = convertQuantity(self.maxQuantityVelocity) maxString = str(self.maxQuantityVelocity) elif self.inptype == u"gauge": if self.maxQuantityAbs is not None: maxQuantity = convertQuantity(self.maxQuantityAbs) maxString = str(self.maxQuantityAbs) else: if self.maxQuantityVelocity is not None: maxQuantity = convertQuantity(self.maxQuantityVelocity) maxString = str(self.maxQuantityVelocity) return (maxQuantity, maxString)
def ensureC3(obj_snmp): """The input quantity and the display unit must have the same dimension """ convPQinpQuantity = convertQuantity(obj_snmp.inpQuantity) convPUdisplUnitAbs = convertUnit(obj_snmp.displUnitAbs) physFactor = convPUdisplUnitAbs / convPQinpQuantity if not physFactor.dimensionless(): raise Invalid("The input quantity '%s' and the "\ "display unit '%s'"\ " must have the same dimension" \ % (convPQinpQuantity, convPUdisplUnitAbs))
def convertQuantity(self, quantityString): return convertQuantity(quantityString)
def maxLength4LinkType(linkType): return convertQuantity('100 m');
def generateValuePng(self, params=None): """generate Picture """ rrdFile = self.getRrdFilename() if not os.path.exists(self.getRrdFilename()): return None unitInRrd = convertQuantity(self.inpQuantity) \ / convertQuantity("1.0 s") (displUnit, displayString) = self.getDisplayUnit() (minQuantity, minString) = self.getMinQuantity() (maxQuantity, maxString) = self.getMaxQuantity() if unitInRrd is not None and \ displUnit is not None: multiplier = float(unitInRrd / displUnit) else: multiplier = 1.0 if 1: ##fileage > 60: rrdFile = self.getRrdFilename() argList = [] argList.append(params['targetname']) # Defs self.rrdConfigureDefs(argList, rrdFile) # CDefs if self.snmpIndexType == u"index": self.rrdConfigureCDefsIndex(argList, multiplier) else: self.rrdConfigureCDefs(argList, multiplier) # Minimum settings if self.snmpIndexType == u"index": self.rrdConfigureMinimumIndex(argList) else: self.rrdConfigureMinimum(argList) # Maximum settings if self.snmpIndexType == u"index": self.rrdConfigureMaximumIndex(argList) else: self.rrdConfigureMaximum(argList) argList.append("--start=%d" % params['starttime']) argList.append("--end=%d" % params['endtime']) try: if params['width'] is not None: argList.append("--width=%d" % int(params['width'])) else: argList.append("--width=540") except ValueError: argList.append("--width=540") try: if params['height'] is not None: argList.append("--height=%d" % int(params['height'])) else: argList.append("--height=120") except ValueError: argList.append("--height=120") argList.append("--color=SHADEA#E5FFF9") argList.append("--color=SHADEB#E5FFF9") argList.append("--color=BACK#E5FFF9") argList.append("--color=CANVAS#ffffff") argList.append("--watermark=ICT-OK.ORG") argList.append("--vertical-label=%s" % displayString) # Legend self.rrdConfigureLegend(argList) # Graph if self.snmpIndexType == u"index": self.rrdConfigureGraphsIndex(argList) else: self.rrdConfigureGraphs(argList) argList.append("--imgformat=PNG") argList.append("--imginfo=<IMG SRC=\"/img/%s\" WIDTH=\"%lu\" " \ "HEIGHT=\"%lu\" ALT=\"Demo\">") #print "argList: ", argList rrdtool.graph(*argList)
def getPQmaxQuantityAcceleration(self): return convertQuantity(self.maxQuantityAcceleration)
def getPQmaxQuantityVelocity(self): return convertQuantity(self.maxQuantityVelocity)
def getPQmaxQuantityAbs(self): return convertQuantity(self.maxQuantityAbs)
def getPQinpQuantity(self): return convertQuantity(self.inpQuantity)