Ignore:
Timestamp:
08/01/15 19:01:31 (9 years ago)
Author:
tim
Message:

.

File:
1 edited

Legend:

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

    r11 r16  
    77import threading
    88import sqlite3
    9 
    10 import numpy
     9try:
     10    import numpy
     11except:
     12    sys.stderr.write('ERROR: Could not import numpy module.  Ensure it is installed.\n')
     13    sys.stderr.write('       Under Debian, the package name is "python3-numpy"\n.')
     14    sys.exit(1)
     15
    1116# Don't trust numpy's seeding
    1217numpy.random.seed(random.SystemRandom().randint(0,2**32-1))
     
    3944                                      tcpts_mean REAL,
    4045                                      tcpts_stddev REAL,
    41                                       tcpts_slopes TEXT)
     46                                      tcpts_slopes TEXT,
     47                                      unusual_case TEXT,
     48                                      greater INTEGER)
    4249                """)
    4350
     
    196203    def addPackets(self, pkts, window_size):
    197204        query = ("INSERT INTO packets (id,probe_id,sent,observed,tsval,payload_len,tcpseq,tcpack)"
    198                  " VALUES(randomblob(16),"
     205                 " VALUES(hex(randomblob(16)),"
    199206                 "(SELECT id FROM probes WHERE local_port=:local_port AND :observed>time_of_day"
    200207                 " AND :observed<time_of_day+userspace_rtt+%d"
     
    254261        self.conn.execute(query, params)
    255262        self.conn.commit()
    256        
     263   
     264    def setUnusualCase(self, unusual_case, greater):
     265        query = """SELECT * FROM meta LIMIT 1"""
     266        cursor = self.conn.cursor()
     267        cursor.execute(query)
     268        row = cursor.fetchone()
     269        if row == None:
     270            params = {"id":_newid()}
     271        else:
     272            params = dict(row)
     273
     274        params["unusual_case"]=unusual_case
     275        params["greater"]=greater
     276       
     277        keys = params.keys()
     278        columns = ','.join(keys)
     279        placeholders = ':'+', :'.join(keys)
     280       
     281        query = """INSERT OR REPLACE INTO meta (%s) VALUES (%s)""" % (columns, placeholders)
     282        cursor.execute(query, params)
     283       
     284       
     285    def getUnusualCase(self):
     286        query = """SELECT unusual_case,greater FROM meta LIMIT 1"""
     287        cursor = self.conn.cursor()
     288        cursor.execute(query)
     289        row = cursor.fetchone()
     290        if row == None or row[0] == None or row[1] == None:
     291            return None
     292        else:
     293            return tuple(row)
Note: See TracChangeset for help on using the changeset viewer.