Changeset 11 for trunk/bin/graph
- Timestamp:
- 07/16/15 20:40:01 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/graph
r10 r11 40 40 41 41 42 def differences(db, unusual_case, column='packet_rtt'): 43 cursor = db.conn.cursor() 44 query=""" 45 SELECT %(column)s-(SELECT avg(%(column)s) FROM probes,analysis 46 WHERE analysis.probe_id=probes.id AND probes.test_case!=:unusual_case AND probes.type in ('train','test') AND sample=u.sample) 47 FROM (SELECT probes.sample,%(column)s FROM probes,analysis 48 WHERE analysis.probe_id=probes.id AND probes.test_case =:unusual_case AND probes.type in ('train','test')) u 49 """ % {"column":column} 50 params = {"unusual_case":unusual_case} 51 cursor.execute(query, params) 52 for row in cursor: 53 yield row[0] 42 def differences(db, unusual_case, rtt_type='packet'): 43 ret_val = [s['unusual_'+rtt_type]-s['other_'+rtt_type] for s in db.subseries('train', unusual_case)] 44 ret_val += [s['unusual_'+rtt_type]-s['other_'+rtt_type] for s in db.subseries('test', unusual_case)] 45 return ret_val 46 47 def null_differences(db, unusual_case, rtt_type='packet'): 48 ret_val = [s['unusual_'+rtt_type]-s['other_'+rtt_type] for s in db.subseries('train_null', unusual_case)] 49 return ret_val 54 50 55 51 … … 91 87 print('packet_rtt diff ubersummary: %f' % ubersummary(diffs)) 92 88 print('packet_rtt diff MAD: %f' % mad(diffs)) 93 print('reported diff trimean: %f' % trimean(reported_diffs)) 94 print('reported diff quadsummary: %f' % quadsummary(reported_diffs)) 95 print('reported diff ubersummary: %f' % ubersummary(reported_diffs)) 96 print('reported diff MAD: %f' % mad(reported_diffs)) 97 98 import cProfile 99 kresults = kfilter({},diffs) 100 #print('packet_rtt diff kfilter: ', numpy.mean(kresults['est']), kresults['var']) 101 print('packet_rtt diff kfilter: ', kresults['est'][-1], kresults['var'][-1]) 102 kresults = kfilter({},reported_diffs) 103 #print('reported diff kfilter: ', numpy.mean(kresults['est']), kresults['var'][-1]) 104 print('reported diff kfilter: ', kresults['est'][-1], kresults['var'][-1]) 89 try: 90 print('reported diff trimean: %f' % trimean(reported_diffs)) 91 print('reported diff quadsummary: %f' % quadsummary(reported_diffs)) 92 print('reported diff ubersummary: %f' % ubersummary(reported_diffs)) 93 print('reported diff MAD: %f' % mad(reported_diffs)) 94 95 import cProfile 96 start = time.time() 97 kresults = kfilter({},diffs) 98 #print('packet_rtt diff kfilter: ', numpy.mean(kresults['est']), kresults['var']) 99 print('packet_rtt diff kfilter: ', kresults['est'][-1], kresults['var'][-1]) 100 kresults = kfilter({},reported_diffs) 101 #print('reported diff kfilter: ', numpy.mean(kresults['est']), kresults['var'][-1]) 102 print('reported diff kfilter: ', kresults['est'][-1], kresults['var'][-1]) 103 print("kfilter time: %f" % (time.time()-start)) 104 except: 105 pass 106 107 print('tsval diff mean: %f' % numpy.mean(differences(db, 'long', 'tsval'))) 108 print('tsval null diff mean: %f' % numpy.mean(null_differences(db, 'long', 'tsval'))) 109 print('tsval diff weighted mean: %f' % tsvalwmean(db.subseries('train','long')+db.subseries('test','long'))) 110 print('tsval null diff weighted mean: %f' % tsvalwmean(db.subseries('train_null','long'))) 105 111 106 112 … … 110 116 #cut_off_high = all_data[int(len(all_data)*0.997)] 111 117 118 119 def plotSingleProbe(probe_id=None): 120 if probe_id == None: 121 cursor = db.conn.cursor() 122 query="""SELECT probe_id FROM analysis WHERE suspect='' ORDER BY probe_id DESC limit 1 OFFSET 10""" 123 cursor.execute(query) 124 probe_id = cursor.fetchone()[0] 125 126 cursor = db.conn.cursor() 127 query="""SELECT observed,payload_len FROM packets WHERE probe_id=? AND sent=1""" 128 cursor.execute(query, (probe_id,)) 129 pkts = cursor.fetchall() 130 sent_payload = [row[0] for row in pkts if row[1] != 0] 131 sent_other = [row[0] for row in pkts if row[1] == 0] 132 133 query="""SELECT observed,payload_len FROM packets WHERE probe_id=? AND sent=0""" 134 cursor.execute(query, (probe_id,)) 135 pkts = cursor.fetchall() 136 rcvd_payload = [row[0] for row in pkts if row[1] != 0] 137 rcvd_other = [row[0] for row in pkts if row[1] == 0] 138 139 #query="""SELECT reported,time_of_day FROM probes WHERE id=?""" 140 #cursor.execute(query, (probe_id,)) 141 #reported,tod = cursor.fetchone() 142 #userspace_times = [sent_times[0]-reported/3.0, sent_times[0]+reported] 143 144 print("single probe counts:",len(sent_payload),len(sent_other),len(rcvd_payload),len(rcvd_other)) 145 plt.clf() 146 plt.title("Single HTTP Request - Packet Times") 147 sp = plt.eventplot(sent_payload, colors=('red',), lineoffsets=8, linewidths=2, alpha=0.6,label='sent') 148 so = plt.eventplot(sent_other, colors=('red',), lineoffsets=6, linewidths=2, alpha=0.6,label='sent') 149 rp = plt.eventplot(rcvd_payload, colors=('blue',), lineoffsets=4, linewidths=2, alpha=0.6,label='received') 150 ro = plt.eventplot(rcvd_other, colors=('blue',), lineoffsets=2, linewidths=2, alpha=0.6,label='received') 151 #plt.legend((s,r), ('sent','received')) 152 #plt.savefig('../img/http-packet-times.svg') 153 plt.show() 154 155 #plotSingleProbe() 156 157 158 def graphTestResults(): 159 plt.clf() 160 plt.title("Test Results") 161 plt.xlabel('sample size') 162 plt.ylabel('error rate') 163 legend = [] 164 colors = ['red','blue','green','purple','orange','black','brown'] 165 color_id = 0 166 167 cursor = db.conn.cursor() 168 query = """ 169 SELECT classifier FROM classifier_results GROUP BY classifier ORDER BY classifier; 170 """ 171 cursor.execute(query) 172 classifiers = [] 173 for c in cursor: 174 classifiers.append(c[0]) 175 176 for classifier in classifiers: 177 query=""" 178 SELECT params FROM classifier_results 179 WHERE trial_type='test' 180 AND classifier=:classifier 181 AND (false_positives+false_negatives)/2.0 < 5.0 182 ORDER BY num_observations,(false_positives+false_negatives) 183 LIMIT 1 184 """ 185 cursor.execute(query, {'classifier':classifier}) 186 row = cursor.fetchone() 187 if row == None: 188 query=""" 189 SELECT params FROM classifier_results 190 WHERE trial_type='test' and classifier=:classifier 191 ORDER BY (false_positives+false_negatives),num_observations 192 LIMIT 1 193 """ 194 cursor.execute(query, {'classifier':classifier}) 195 row = cursor.fetchone() 196 if row == None: 197 sys.stderr.write("WARN: couldn't find test results for classifier '%s'.\n" % classifier) 198 continue 199 200 best_params = row[0] 201 query=""" 202 SELECT num_observations,(false_positives+false_negatives)/2.0 FROM classifier_results 203 WHERE trial_type='test' 204 AND classifier=:classifier 205 AND params=:params 206 ORDER BY num_observations 207 """ 208 cursor.execute(query, {'classifier':classifier,'params':best_params}) 209 210 num_obs = [] 211 performance = [] 212 for row in cursor: 213 num_obs.append(row[0]) 214 performance.append(row[1]) 215 #print(num_obs,performance) 216 path = plt.scatter(num_obs, performance, color=colors[color_id], s=4, alpha=0.8, linewidths=3.0) 217 plt.plot(num_obs, performance, color=colors[color_id], alpha=0.8) 218 legend.append((classifier,path)) 219 color_id = (color_id+1) % len(colors) 220 221 plt.legend([l[1] for l in legend], [l[0] for l in legend], scatterpoints=1, fontsize='xx-small') 222 plt.show() 223 224 graphTestResults() 225 226 sys.exit(0) 112 227 113 228 plt.clf() … … 122 237 plt.show() 123 238 239 240 241 plt.clf() 242 plt.title("Simple HTTP Request") 243 plt.xlabel('Time of Day') 244 plt.ylabel('') 245 s = plt.scatter(sent_times, [2]*len(sent_times), s=3, color='red', alpha=0.9) 246 r = plt.scatter(rcvd_times, [1]*len(rcvd_times), s=3, color='blue', alpha=0.9) 247 plt.legend((s,r), ('sent','received'), scatterpoints=1) 248 plt.show() 249 250 sys.exit(0) 124 251 short_overtime,long_overtime,diff_overtime = None,None,None 125 252
Note: See TracChangeset
for help on using the changeset viewer.