diff options
-rw-r--r-- | scripts/getresultdetails2.py | 77 |
1 files changed, 31 insertions, 46 deletions
diff --git a/scripts/getresultdetails2.py b/scripts/getresultdetails2.py index b0d429c..8678b52 100644 --- a/scripts/getresultdetails2.py +++ b/scripts/getresultdetails2.py @@ -1,3 +1,6 @@ +import sys +import json + from dbaccess import execQuery from misc import textToId, printJSONHeader @@ -29,60 +32,42 @@ class GetResultDetails2: self.metric_id = textToId("metric", metric) def execute(self): - self.sample1, self.sample2 = self.fetchSamples() + self.sample2 = self.fetchSample(self.host1_id, self.platform1_id, + self.branch1_id, self.sha11_id, self.benchmark_id, + self.metric_id) + self.sample2 = self.fetchSample(self.host2_id, self.platform2_id, + self.branch2_id, self.sha12_id, self.benchmark_id, + self.metric_id) self.writeOutput() # Fetches the sample (i.e. individual observations) for both contexts. - def fetchSamples(self): + @classmethod + def fetchSample(cls, host, platform, branch, sha1, benchmark, metric): - sample1 = execQuery( - "SELECT value, valid, extract(epoch FROM startTime)::int " + - "FROM result, upload WHERE uploadId = upload.id" + - " AND hostId = " + str(self.host1_id) + - " AND platformId = " + str(self.platform1_id) + " AND branchId = " + - str(self.branch1_id) + " AND sha1Id = " + str(self.sha11_id) + - " AND benchmarkId = " + str(self.benchmark_id) + - " AND metricId = " + str(self.metric_id) + - " ORDER BY value DESC;" - ) - sample2 = execQuery( - "SELECT value, valid, extract(epoch FROM startTime)::int " + - "FROM result, upload WHERE uploadId = upload.id" + - " AND hostId = " + str(self.host2_id) + - " AND platformId = " + str(self.platform2_id) + " AND branchId = " + - str(self.branch2_id) + " AND sha1Id = " + str(self.sha12_id) + - " AND benchmarkId = " + str(self.benchmark_id) + - " AND metricId = " + str(self.metric_id) + - " ORDER BY value DESC;" - ) + sample = [] + for value, valid, timestamp in execQuery( + "SELECT value, valid, EXTRACT(EPOCH FROM startTime)::INT" + " FROM result, upload" + " WHERE uploadId = upload.id" + " AND hostId = %d" + " AND platformId = %d" + " AND branchId = %d" + " AND sha1Id = %d" + " AND benchmarkId = %d" + " AND metricId = %d" + " ORDER BY value DESC;" + % (host, platform, branch, sha1, benchmark, metric)): + sample.append({ + 'value' : value, + 'valid' : valid, + 'timestamp' : timestamp + }) - return sample1, sample2 + return sample def writeOutputAsJSON(self): printJSONHeader() - print "{" - - first_sample_row = True; - for s in (("1", self.sample1), ("2", self.sample2)): - if not first_sample_row: - print "," - first_sample_row = False - - print "\"sample" + s[0] + "\": [" - first_obs_row = True - for obs in s[1]: - if not first_obs_row: - print "," - first_obs_row = False - - print ( - "{\"value\": \"" + str(obs[0]) + "\", \"valid\": " + - ("1" if obs[1] else "0") + ", \"timestamp\":" + - "\"" + str(obs[2]) + "\" }"); - print "]" - - print "}" - + json.dump({ 'sample1' : self.sample1, 'sample2' : self.sample2 }, sys.stdout) class GetResultDetails2AsJSON(GetResultDetails2): def writeOutput(self): |