Changeset 11 for trunk/lib/nanownlib/storage.py
- Timestamp:
- 07/16/15 20:40:01 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/nanownlib/storage.py
r10 r11 115 115 116 116 117 def subseries(self, probe_type, unusual_case, size=None, offset=None, field='packet_rtt'): 118 cache_key = (probe_type,unusual_case,field) 119 117 def subseries(self, probe_type, unusual_case, size=None, offset=None): 118 cache_key = (probe_type,unusual_case) 120 119 if cache_key not in self._population_cache: 121 120 query=""" 122 SELECT %(field)s AS unusual_case, 123 (SELECT avg(%(field)s) FROM probes,analysis 124 WHERE analysis.probe_id=probes.id AND probes.test_case!=:unusual_case AND probes.type=:probe_type AND sample=u.sample) AS other_cases 125 FROM (SELECT probes.sample,%(field)s FROM probes,analysis 121 SELECT packet_rtt AS unusual_packet, 122 (SELECT avg(packet_rtt) FROM probes,analysis 123 WHERE analysis.probe_id=probes.id AND probes.test_case!=:unusual_case AND probes.type=:probe_type AND sample=u.sample) AS other_packet, 124 125 tsval_rtt AS unusual_tsval, 126 (SELECT avg(tsval_rtt) FROM probes,analysis 127 WHERE analysis.probe_id=probes.id AND probes.test_case!=:unusual_case AND probes.type=:probe_type AND sample=u.sample) AS other_tsval, 128 129 reported AS unusual_reported, 130 (SELECT avg(reported) FROM probes,analysis 131 WHERE analysis.probe_id=probes.id AND probes.test_case!=:unusual_case AND probes.type=:probe_type AND sample=u.sample) AS other_reported 132 133 FROM (SELECT probes.sample,packet_rtt,tsval_rtt,reported FROM probes,analysis 126 134 WHERE analysis.probe_id=probes.id AND probes.test_case =:unusual_case AND probes.type=:probe_type) u 127 """ % {"field":field}135 """ 128 136 129 137 params = {"probe_type":probe_type, "unusual_case":unusual_case} … … 207 215 return [self._insert('trim_analysis', row) for row in analyses] 208 216 209 def addClassifierResult s(self, results):217 def addClassifierResult(self, results): 210 218 ret_val = self._insert('classifier_results', results) 211 219 self.conn.commit() 212 220 return ret_val 213 221 214 def fetchClassifierResult(self, classifier, trial_type, num_observations ):222 def fetchClassifierResult(self, classifier, trial_type, num_observations, params=None): 215 223 query = """ 216 224 SELECT * FROM classifier_results 217 WHERE classifier=? AND trial_type=? AND num_observations=? 218 ORDER BY false_positives+false_negatives 219 LIMIT 1; 225 WHERE classifier=:classifier 226 AND trial_type=:trial_type 227 AND num_observations=:num_observations""" 228 if params != None: 229 query += """ 230 AND params=:params""" 231 query += """ 232 ORDER BY false_positives+false_negatives 233 LIMIT 1 220 234 """ 235 236 qparams = {'classifier':classifier, 'trial_type':trial_type, 237 'num_observations':num_observations,'params':params} 221 238 cursor = self.conn.cursor() 222 cursor.execute(query, (classifier, trial_type, num_observations))239 cursor.execute(query, qparams) 223 240 ret_val = cursor.fetchone() 224 225 241 if ret_val != None: 226 242 ret_val = dict(ret_val) 227 243 return ret_val 228 244 229 245 def deleteClassifierResults(self, classifier, trial_type, num_observations=None): 230 246 params = {"classifier":classifier,"trial_type":trial_type,"num_observations":num_observations}
Note: See TracChangeset
for help on using the changeset viewer.