- Timestamp:
- 07/09/15 19:01:23 (9 years ago)
- Location:
- trunk/lib/nanownlib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/nanownlib/stats.py
r7 r8 311 311 ret_val = [] 312 312 for t in range(num_trials): 313 ret_val.append(estimator( subseries(db,probe_type, unusual_case, subseries_size)))313 ret_val.append(estimator(db.subseries(probe_type, unusual_case, subseries_size))) 314 314 315 315 return ret_val … … 344 344 # 0 if it isn't unusual 345 345 # -1 if it is unusual in the wrong direction 346 def multiBoxTest(params, unusual_case, greater, samples): 347 #XXX: packet_rtt field from params 348 dists = samples2Distributions(samples, 'packet_rtt') 349 350 uc = dists[unusual_case] 351 rest = [] 352 for tc,d in dists.items(): 353 if tc != unusual_case: 354 rest.extend(d) 355 346 def multiBoxTest(params, greater, samples): 347 uc = [s['unusual_case'] for s in samples] 348 rest = [s['other_cases'] for s in samples] 349 356 350 uc_high = numpy.percentile(uc, params['high']) 357 351 rest_low = numpy.percentile(rest, params['low']) … … 379 373 380 374 mh = midhinge(diffs, params['distance']) 375 #mh = trimean(diffs, params['distance']) 381 376 if greater: 382 377 if mh > params['threshold']: -
trunk/lib/nanownlib/storage.py
r7 r8 6 6 import threading 7 7 import sqlite3 8 9 import numpy 8 10 9 11 def _newid(): … … 15 17 cursor = None 16 18 _population_sizes = None 19 _population_cache = None 17 20 18 21 def __init__(self, path): … … 22 25 self.conn.row_factory = sqlite3.Row 23 26 self._population_sizes = {} 27 self._population_cache = {} 24 28 25 29 if not exists: … … 89 93 self.conn.close() 90 94 95 91 96 def populationSize(self, probe_type): 92 97 if probe_type in self._population_sizes: … … 101 106 print(e) 102 107 return 0 108 109 110 def subseries(self, probe_type, unusual_case, size=None, offset=None, field='packet_rtt'): 111 if (probe_type,unusual_case,field) not in self._population_cache: 112 query=""" 113 SELECT %(field)s AS unusual_case, 114 (SELECT avg(%(field)s) FROM probes,analysis 115 WHERE analysis.probe_id=probes.id AND probes.test_case!=:unusual_case AND probes.type=:probe_type AND sample=u.sample) AS other_cases 116 FROM (SELECT probes.sample,%(field)s FROM probes,analysis 117 WHERE analysis.probe_id=probes.id AND probes.test_case =:unusual_case AND probes.type=:probe_type) u 118 """ % {"field":field} 119 120 params = {"probe_type":probe_type, "unusual_case":unusual_case} 121 cursor = self.conn.cursor() 122 cursor.execute(query, params) 123 self._population_cache[(probe_type,unusual_case,field)] = [dict(row) for row in cursor.fetchall()] 124 125 population = self._population_cache[(probe_type,unusual_case,field)] 126 127 if size == None or size > len(population): 128 size = len(population) 129 if offset == None or offset >= len(population) or offset < 0: 130 offset = numpy.random.random_integers(0,len(population)-1) 131 132 ret_val = population[offset:offset+size] 133 if len(ret_val) < size: 134 ret_val += population[0:size-len(ret_val)] 135 136 return ret_val 137 138 139 def clearCache(self): 140 self._population_cache = {} 141 103 142 104 143 def _insert(self, table, row):
Note: See TracChangeset
for help on using the changeset viewer.