Package teamwork :: Package examples :: Package Thespian :: Module report
[hide private]
[frames] | no frames]

Source Code for Module teamwork.examples.Thespian.report

  1  import string 
  2  import sys 
  3  
 
  4  
 
5 -def searchForAct(actions,c,exist=1):
6 if exist == 1: 7 for action in actions: 8 if action.find(c) > -1: 9 return 1 10 return 0 11 else: 12 found = 0 13 for action in actions: 14 if action.find(c) > -1: 15 found = 1 16 break 17 18 if found == 1: 19 return 0 20 else: 21 return 1
22 23 24 ## by default bad paths are defined as 25 ## 1. the actor performs the same action for more than 60% of the turns 26 ## 2. the actor repeat the same actions for more than 3 times continuously 27 ## 3.
28 -def selectReport(path,actor,criteria={'hunter-kill-wolf':'0'}):
29 path = path.strip('[') 30 path = path.strip(']\n') 31 actions = string.split(path,', ') 32 33 count = {} 34 totalStep = 0 35 lastAct = LastAct2 = '' 36 result = [] 37 38 ## 2. the actor repeat the same actions for more than 3 times continuously 39 for action in actions: 40 ## this action is performed by this actor 41 if action.find(actor) == 0: 42 totalStep += 1 43 44 if action == lastAct and action == lastAct2: 45 result.append(2) 46 47 lastAct2 = lastAct 48 lastAct = action 49 50 if not count.has_key(action): 51 count[action] = 1 52 else: 53 count[action] += 1 54 55 ## 1. the actor performs the same action for more than 60% of the turns 56 for action in count: 57 if count[action] > totalStep*.75: 58 result.append(1) 59 60 ## assum an AND relationship among criteria 61 for c in criteria: 62 if criteria[c] == '1': 63 res = searchForAct(actions,c,1) 64 else: 65 res = searchForAct(actions,c,0) 66 if res == 0: 67 break 68 else: 69 result.append(3) 70 71 if result == []: 72 result.append(0) 73 return result
74
75 -def diff(f1,f2):
76 fileHandle = open (f1) 77 78 pathList1 = fileHandle.readlines() 79 80 fileHandle.close() 81 82 fileHandle = open (f2) 83 84 pathList2 = fileHandle.readlines() 85 86 fileHandle.close() 87 88 diff1 = [] 89 diff2 = [] 90 91 for path in pathList1: 92 if path[0] == '[': 93 if not path in pathList2: 94 diff1.append(path) 95 96 for path in pathList2: 97 if path[0] == '[': 98 if not path in pathList1: 99 diff2.append(path) 100 101 102 print 'path in file ',f1,' but not in file ',f2 103 print 'totle number: ',len(diff1) 104 105 print 'path in file ',f2,' but not in file ',f1 106 print 'totle number: ',len(diff2) 107 108 for i in range(len(diff1)): 109 print diff1[i]
110 111 112
113 -def printResult(totalRecord,distinctRecord,reportList,report):
114 print "Total numbers of record in file: ",totalRecord 115 print "Total numbers of distinct record in file: ",distinctRecord 116 print "Number of record prompt for attention: ",len(reportList) 117 print "Number of record selected by default huristics: ", report[4] 118 print report[1],report[2] 119 print "Number of record selected by plot point: ", report[3] 120 print "Number of record satisfy all filtering criteria: ", report[0] 121 print 122 print
123
124 -def ProcessResults(fnames):
125 totalList = [] 126 reportList = [] 127 128 for fname in fnames: 129 fileHandle = open (fname) 130 131 pathList = fileHandle.readlines() 132 133 fileHandle.close() 134 135 reportList = [] 136 137 totalRecord = 0 138 139 distinctRecord = 0 140 141 criteria={'hunter-kill-wolf':'0','wolf-eat-granny':'1'} 142 143 i = 0 144 145 report = [0]*5 146 d = 0 147 for path in pathList: 148 if path.find('red')==0: 149 printResult(totalRecord,distinctRecord,reportList,report) 150 print path 151 totalRecord = 0 152 distinctRecord = 0 153 report = [0]*5 154 reportList = [] 155 d = pathList.index(path) 156 elif path[0] == '[': 157 totalRecord += 1 158 if pathList[d+1:].index(path) + d + 1 == i: 159 distinctRecord += 1 160 res = selectReport(path,'wolf',criteria) 161 if not 0 in res: 162 if not path in reportList: 163 reportList.append(path) 164 if 1 in res: 165 report[1]+=1 166 if 2 in res: 167 report[2]+=1 168 if 3 in res: 169 report[3]+=1 170 if (1 in res) and (2 in res) and (3 in res): 171 report[0]+=1 172 if (1 in res) or (2 in res): 173 report[4]+=1 174 175 i += 1 176 printResult(totalRecord,distinctRecord,reportList,report)
177 178 ## for path in reportList: 179 ## if not path in totalList: 180 ## totalList.append(path) 181 182 ## print "Total number of paths: ,",len(totalList) 183 184 185 if __name__ == '__main__': 186 ## ProcessResults('0425result-goodwolf.txt') 187 ## ProcessResults('result-0425-evil-wolf-depth-2.txt') 188 ## ProcessResults('0426result-phrygian-bad-wolf-relax-fin.txt') 189 190 ## diff('result-0425-evil-wolf-depth-2.txt', '0426result-phrygian-bad-wolf-relax-fin.txt') 191 ## diff('0426result-phrygian-bad-wolf-depth-2-phrygian.txt', '0426result-phrygian-bad-wolf-relax-fin.txt') 192 193 ## ProcessResults('result-0426-good-wolf-boston-fin.txt') 194 ## ProcessResults('0426result-phrygian-bad-wolf-depth-2-phrygian.txt') 195 196 ProcessResults(['result-0426-good-wolf-boston-fin.txt','0426result-phrygian-bad-wolf-depth-2-phrygian.txt']) 197 ProcessResults(['result-0429-varygoal-2-depth-boston.txt']) 198 ProcessResults(['0428-vary-goal-bad-wolf.txt']) 199