Ignore:
Timestamp:
07/16/15 20:40:01 (9 years ago)
Author:
tim
Message:

.

File:
1 edited

Legend:

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

    r10 r11  
    115115
    116116
    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)
    120119        if cache_key not in self._population_cache:
    121120            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
    126134                    WHERE analysis.probe_id=probes.id AND probes.test_case =:unusual_case AND probes.type=:probe_type) u
    127             """ % {"field":field}
     135            """
    128136   
    129137            params = {"probe_type":probe_type, "unusual_case":unusual_case}
     
    207215        return [self._insert('trim_analysis', row) for row in analyses]
    208216
    209     def addClassifierResults(self, results):
     217    def addClassifierResult(self, results):
    210218        ret_val = self._insert('classifier_results', results)
    211219        self.conn.commit()
    212220        return ret_val
    213221
    214     def fetchClassifierResult(self, classifier, trial_type, num_observations):
     222    def fetchClassifierResult(self, classifier, trial_type, num_observations, params=None):
    215223        query = """
    216224          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
    220234        """
     235
     236        qparams = {'classifier':classifier, 'trial_type':trial_type,
     237                   'num_observations':num_observations,'params':params}
    221238        cursor = self.conn.cursor()
    222         cursor.execute(query, (classifier, trial_type, num_observations))
     239        cursor.execute(query, qparams)
    223240        ret_val = cursor.fetchone()
    224 
    225241        if ret_val != None:
    226242            ret_val = dict(ret_val)
    227243        return ret_val
    228 
     244   
    229245    def deleteClassifierResults(self, classifier, trial_type, num_observations=None):
    230246        params = {"classifier":classifier,"trial_type":trial_type,"num_observations":num_observations}
Note: See TracChangeset for help on using the changeset viewer.