本文整理匯總了Python中pxStats.lib.StatsDateLib.StatsDateLib.isoDateDashed方法的典型用法代碼示例。如果您正苦於以下問題:Python StatsDateLib.isoDateDashed方法的具體用法?Python StatsDateLib.isoDateDashed怎麽用?Python StatsDateLib.isoDateDashed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pxStats.lib.StatsDateLib.StatsDateLib
的用法示例。
在下文中一共展示了StatsDateLib.isoDateDashed方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: findValues
# 需要導入模塊: from pxStats.lib.StatsDateLib import StatsDateLib [as 別名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import isoDateDashed [as 別名]
def findValues( statsTypes, line = "", lineType = "[INFO]", fileType = "tx",logger = None ):
"""
@summary : This method is used to find specific values within a line.
@note : If stats type cannot be found the 0 value will be returned.
A key named "valuesNotFound" will be added. It's value will
be an array containing the list of statsType for which no
values were found.
@precondition: Requires _ translator to have been set prior to calling this function.
@return : returns a dictionary containing the statsType->foundValue associations.
"""
global _
values = {} #in case of an unknown type
splitLine = line.split( " " )
if line != "" and line != "\n" :
for statsType in statsTypes :
try:
if statsType == "departure" : #is at the same place for every lineType
values[ statsType ] = line.split( "," )[0]
elif lineType == "[INFO]" :
if statsType == "latency":
d1 = line[:19]
d2 = splitLine[6].split(":")[6]
result = (datetime.datetime( int(d1[0:4]), int(d1[5:7]), int(d1[8:10]), int(d1[11:13]), int(d1[14:16]), int(d1[17:19])) - datetime.datetime( int(d2[0:4]),int(d2[4:6]),int(d2[6:8]),int(d2[8:10]),int(d2[10:12]),int(d2[12:14]) ) )
values[statsType] = result.seconds + (result.days*24*60*60)
if values[statsType] < 0 :
values[statsType] = 0
elif statsType == "arrival":
values[statsType] = StatsDateLib.isoDateDashed( splitLine[6].split( ":" )[6] )
elif statsType == "bytecount":
start = line.find( "(" )
end = line.find( "Bytes" )
start = start +1
end = end -1
values[statsType] = int( line[start:end] )
elif statsType == "fileName":
if fileType == "tx" :
values[statsType] = os.path.basename(splitLine[6])#.split( ":" )[0]
else:
split = line.split( "/" )
lastPart = split[ len( split ) -1 ]
values[ statsType ] = lastPart.split( ":" )[0] #in case something is added after line ends.
elif statsType == "productType":
if fileType == "tx":
values[statsType] = os.path.basename(splitLine[6])#.split( ":" )[0]
else: # rx has a very different format for product.
split = line.split( "/" )
lastPart = split[ len( split ) -1 ]
values[ statsType ] = lastPart.split( ":" )[0] #in case something is added after line ends.
elif statsType == "errors" :
values[statsType] = 0
elif lineType == "[ERROR]":
if statsType == "errors" :
values[statsType] = 1
elif statsType == "productType" :
values[statsType] = ""
else:
values[statsType] = 0
#elif lineType == "[OTHER]" :
except:
if logger is not None :
logger.error(_("could not find %s value in line %s.") %( statsType,line ) )
#.........這裏部分代碼省略.........