Changeset 22 for trunk/lib/nanownlib
- Timestamp:
- 11/09/15 20:37:05 (9 years ago)
- Location:
- trunk/lib/nanownlib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/nanownlib/__init__.py
r20 r22 206 206 cursor.execute(query, params) 207 207 differences = [row[0] for row in cursor] 208 208 209 209 return septasummary(differences),mad(differences) 210 210 … … 253 253 for probe_id,packets in packet_cache: 254 254 try: 255 analysis,s,r = analyzePackets(packets, timestamp_precision )255 analysis,s,r = analyzePackets(packets, timestamp_precision,strim,rtrim) 256 256 analysis['probe_id'] = probe_id 257 257 analyses.append(analysis) … … 261 261 #traceback.print_exc() 262 262 sys.stderr.write("WARN: couldn't find enough packets for probe_id=%s\n" % probe_id) 263 264 start = time.time() 263 265 db.addTrimAnalyses(analyses) 264 266 db.conn.commit() 267 print("addTrimAnalyses: %f" % (time.time()-start)) 268 265 269 return statistics.mode(sent_tally),statistics.mode(rcvd_tally) 266 270 … … 275 279 num_sent,num_rcvd = processPackets(packet_cache, 0, 0) 276 280 print("num_sent: %d, num_rcvd: %d" % (num_sent,num_rcvd)) 277 278 for strim in range(0,num_sent):279 for rtrim in range(0,num_rcvd):280 #print(strim,rtrim)281 if strim == 0 and rtrim == 0:282 continue # no point in doing 0,0 again283 processPackets(packet_cache, strim, rtrim)284 285 286 281 unusual_case,delta = findUnusualTestCase(db, (0,0)) 287 evaluations = {} 288 for strim in range(0,num_sent): 289 for rtrim in range(0,num_rcvd): 290 evaluations[(strim,rtrim)] = evaluateTrim(db, unusual_case, strim, rtrim) 291 292 import pprint 293 pprint.pprint(evaluations) 294 282 print("unusual_case: %s, delta: %f" % (unusual_case,delta)) 283 295 284 delta_margin = 0.15 296 285 best_strim = 0 297 286 best_rtrim = 0 298 good_delta,good_mad = evaluations[(0,0)] 299 287 288 good_delta,good_mad = evaluateTrim(db, unusual_case, best_strim, best_rtrim) 289 print("trim (%d,%d): delta=%f, mad=%f" % (best_strim,best_rtrim, good_delta, good_mad)) 290 300 291 for strim in range(1,num_sent): 301 delta,mad = evaluations[(strim,0)] 292 processPackets(packet_cache, strim, best_rtrim) 293 delta,mad = evaluateTrim(db, unusual_case, strim, best_rtrim) 294 print("trim (%d,%d): delta=%f, mad=%f" % (strim,best_rtrim, delta, mad)) 302 295 if delta*good_delta > 0.0 and (abs(good_delta) - abs(delta)) < abs(delta_margin*good_delta) and mad < good_mad: 303 296 best_strim = strim 297 good_delta,good_mad = delta,mad 304 298 else: 305 299 break 306 300 307 good_delta,good_mad = evaluations[(best_strim,0)]308 301 for rtrim in range(1,num_rcvd): 309 delta,mad = evaluations[(best_strim,rtrim)] 302 processPackets(packet_cache, best_strim, rtrim) 303 delta,mad = evaluateTrim(db, unusual_case, best_strim, rtrim) 304 print("trim (%d,%d): delta=%f, mad=%f" % (best_strim, rtrim, delta, mad)) 310 305 if delta*good_delta > 0.0 and (abs(good_delta) - abs(delta)) < abs(delta_margin*good_delta) and mad < good_mad: 311 306 best_rtrim = rtrim -
trunk/lib/nanownlib/storage.py
r16 r22 189 189 placeholders = ':'+', :'.join(keys) 190 190 query = "INSERT INTO %s (id,%s) VALUES ('%s',%s)" % (table, columns, rid, placeholders) 191 #print( row)191 #print(query,row) 192 192 self.conn.execute(query, row) 193 193 return rid 194 194 195 def _insertMany(self, table, rows): 196 if len(rows) < 1: 197 return 198 199 keys = rows[0].keys() 200 columns = ','.join(keys) 201 placeholders = ':'+', :'.join(keys) 202 query = "INSERT INTO %s (id,%s) VALUES (hex(randomblob(16)),%s)" % (table, columns, placeholders) 203 #print(query,row) 204 self.conn.executemany(query, rows) 205 195 206 def addMeta(self, meta): 196 207 ret_val = self._insert('meta', meta) … … 220 231 221 232 def addTrimAnalyses(self, analyses): 222 return [self._insert('trim_analysis', row) for row in analyses]233 self._insertMany('trim_analysis', analyses) 223 234 224 235 def addClassifierResult(self, results):
Note: See TracChangeset
for help on using the changeset viewer.