Changeset 22 for trunk


Ignore:
Timestamp:
11/09/15 20:37:05 (9 years ago)
Author:
tim
Message:

Fixed a bug in processPackets where trim parameters weren't passed through

Reorganized analyzeProbes to work as a O(max(S,R)) algorithm, rather than O(S*R)

Sped up addTrimAnalyses by using a new _insertMany primative

Location:
trunk/lib/nanownlib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/nanownlib/__init__.py

    r20 r22  
    206206    cursor.execute(query, params)
    207207    differences = [row[0] for row in cursor]
    208    
     208
    209209    return septasummary(differences),mad(differences)
    210210
     
    253253        for probe_id,packets in packet_cache:
    254254            try:
    255                 analysis,s,r = analyzePackets(packets, timestamp_precision)
     255                analysis,s,r = analyzePackets(packets, timestamp_precision,strim,rtrim)
    256256                analysis['probe_id'] = probe_id
    257257                analyses.append(analysis)
     
    261261                #traceback.print_exc()
    262262                sys.stderr.write("WARN: couldn't find enough packets for probe_id=%s\n" % probe_id)
     263
     264        start = time.time()   
    263265        db.addTrimAnalyses(analyses)
    264266        db.conn.commit()
     267        print("addTrimAnalyses: %f" % (time.time()-start))
     268
    265269        return statistics.mode(sent_tally),statistics.mode(rcvd_tally)
    266270   
     
    275279        num_sent,num_rcvd = processPackets(packet_cache, 0, 0)
    276280        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 again
    283                 processPackets(packet_cache, strim, rtrim)
    284 
    285    
    286281        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       
    295284        delta_margin = 0.15
    296285        best_strim = 0
    297286        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       
    300291        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))
    302295            if delta*good_delta > 0.0 and (abs(good_delta) - abs(delta)) < abs(delta_margin*good_delta) and mad < good_mad:
    303296                best_strim = strim
     297                good_delta,good_mad = delta,mad
    304298            else:
    305299                break
    306300
    307         good_delta,good_mad = evaluations[(best_strim,0)]
    308301        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))           
    310305            if delta*good_delta > 0.0 and (abs(good_delta) - abs(delta)) < abs(delta_margin*good_delta) and mad < good_mad:
    311306                best_rtrim = rtrim
  • trunk/lib/nanownlib/storage.py

    r16 r22  
    189189        placeholders = ':'+', :'.join(keys)
    190190        query = "INSERT INTO %s (id,%s) VALUES ('%s',%s)" % (table, columns, rid, placeholders)
    191         #print(row)
     191        #print(query,row)
    192192        self.conn.execute(query, row)
    193193        return rid
    194194
     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   
    195206    def addMeta(self, meta):
    196207        ret_val = self._insert('meta', meta)
     
    220231
    221232    def addTrimAnalyses(self, analyses):
    222         return [self._insert('trim_analysis', row) for row in analyses]
     233        self._insertMany('trim_analysis', analyses)
    223234
    224235    def addClassifierResult(self, results):
Note: See TracChangeset for help on using the changeset viewer.