3 from datetime import datetime
8 def __init__(self, txnId, startTime, operations):
10 self.operations = operations
11 self.startTime = datetime.strptime(startTime,
12 '%Y-%m-%d,%H:%M:%S,%f')
13 self.reachedTime = None
14 self.completeTime = None
16 def setReachedTime(self, reachedTime):
17 self.reachedTime = datetime.strptime(reachedTime,
18 '%Y-%m-%d,%H:%M:%S,%f')
20 def setCompleteTime(self, completeTime):
21 self.completeTime = datetime.strptime(completeTime,
22 '%Y-%m-%d,%H:%M:%S,%f')
25 return Transaction.diffInMicros(self.startTime, self.completeTime)
27 def transferTime(self):
28 return Transaction.diffInMicros(self.startTime, self.reachedTime)
31 def diffInMicros(start, end):
32 if end is not None and start is not None:
34 seconds = delta.seconds
35 microseconds = delta.microseconds
36 return (seconds * 1000000 + microseconds) / 1000
40 return "transactionId = " + self.txnId + ", " \
41 + "operations = " + unicode(self.operations) + ", " \
42 + "startTime = " + unicode(self.startTime) + ", " \
43 + "reachedTime = " + unicode(self.reachedTime) + ", " \
44 + "completeTime = " + unicode(self.completeTime) + ", " \
45 + "transferTime = " + unicode(self.transferTime()) + ", " \
46 + "totalTime = " + unicode(self.totalTime())
49 return unicode(self.startTime) + "," \
51 + unicode(self.operations) + "," \
52 + unicode(self.transferTime()) + "," \
53 + unicode(self.totalTime())
57 return "Start Time,Transaction Id,Operations,Transfer Time," \
62 txns = collections.OrderedDict()
63 txnBegin = open("txnbegin.txt", "r")
66 txns[arr[3]] = Transaction(arr[3],
67 arr[0] + "," + arr[1] + "," + arr[2],
70 txnReached = open("txnreached.txt", "r")
71 for line in txnReached:
73 txnId = arr[3].strip()
76 txn.setReachedTime(arr[0] + "," + arr[1] + "," + arr[2])
78 txnComplete = open("txnend.txt", "r")
79 for line in txnComplete:
81 txnId = arr[3].strip()
84 txn.setCompleteTime(arr[0] + "," + arr[1] + "," + arr[2])
89 def filterTransactionsByTimeToComplete(timeToComplete):
93 if txns[txn].totalTime() > timeToComplete:
95 totalTime += txns[txn].totalTime()
97 print "Total time for these transactions = " + unicode(totalTime)
101 txns = processFiles()
102 print Transaction.csv_header()
104 print txns[txn].csv()