Changeset 16 for trunk/lib/nanownlib/storage.py
- Timestamp:
- 08/01/15 19:01:31 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/nanownlib/storage.py
r11 r16 7 7 import threading 8 8 import sqlite3 9 10 import numpy 9 try: 10 import numpy 11 except: 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 11 16 # Don't trust numpy's seeding 12 17 numpy.random.seed(random.SystemRandom().randint(0,2**32-1)) … … 39 44 tcpts_mean REAL, 40 45 tcpts_stddev REAL, 41 tcpts_slopes TEXT) 46 tcpts_slopes TEXT, 47 unusual_case TEXT, 48 greater INTEGER) 42 49 """) 43 50 … … 196 203 def addPackets(self, pkts, window_size): 197 204 query = ("INSERT INTO packets (id,probe_id,sent,observed,tsval,payload_len,tcpseq,tcpack)" 198 " VALUES( randomblob(16),"205 " VALUES(hex(randomblob(16))," 199 206 "(SELECT id FROM probes WHERE local_port=:local_port AND :observed>time_of_day" 200 207 " AND :observed<time_of_day+userspace_rtt+%d" … … 254 261 self.conn.execute(query, params) 255 262 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.