[LNT] r249107 - New graphing JSON API

Chris Matthews via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 17:02:36 PDT 2015


Author: cmatthews
Date: Thu Oct  1 19:02:36 2015
New Revision: 249107

URL: http://llvm.org/viewvc/llvm-project?rev=249107&view=rev
Log:
New graphing JSON API

Modified:
    lnt/trunk/lnt/server/ui/api.py
    lnt/trunk/tests/server/ui/test_api.py

Modified: lnt/trunk/lnt/server/ui/api.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/api.py?rev=249107&r1=249106&r2=249107&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/api.py (original)
+++ lnt/trunk/lnt/server/ui/api.py Thu Oct  1 19:02:36 2015
@@ -2,6 +2,8 @@ from flask import current_app, g
 from flask import request
 from sqlalchemy.orm.exc import NoResultFound
 from flask_restful import Resource, reqparse, fields, marshal_with, abort
+from lnt.testing import PASS
+from collections import namedtuple
 
 parser = reqparse.RequestParser()
 parser.add_argument('db', type=str)
@@ -154,8 +156,59 @@ class Order(Resource):
         return changes
 
 
+graph_fields = {
+    'val': fields.Float,
+    'rev': fields.String,
+    'time': fields.DateTime(dt_format=DATE_FORMAT),
+    }
+graph_list_fields = {
+    fields.List(fields.Nested(graph_fields)),
+}
+
+
+class Graph(Resource):
+    """List all the machines and give summary information."""
+    method_decorators = [in_db]
+
+    @marshal_with(graph_fields)
+    def get(self, machine_id, test_id, field_index):
+        """Get the data for a particular line in a graph."""
+        ts = request.get_testsuite()
+        # Maybe we don't need to do this?
+        try:
+            machine = ts.query(ts.Machine) \
+                .filter(ts.Machine.id == machine_id) \
+                .one()
+            test = ts.query(ts.Test) \
+                .filter(ts.Test.id == test_id) \
+                .one()
+            field = ts.sample_fields[field_index]
+        except NoResultFound:
+            print "Foo"
+            return abort(402)
+
+        q = ts.query(field.column, ts.Order.llvm_project_revision, ts.Run.start_time) \
+            .join(ts.Run) \
+            .join(ts.Order) \
+            .filter(ts.Run.machine_id == machine.id) \
+            .filter(ts.Sample.test == test) \
+            .filter(field.column != None)
+
+        if field.status_field:
+            q = q.filter((field.status_field.column == PASS) |
+                         (field.status_field.column == None))
+
+        samples = [{'val': val, 'rev': rev, 'time': time} for val, rev, time in q.all()]
+        import pprint
+        print "Samples"
+        pprint.pprint(samples)
+        return samples
+
+
 def load_api_resources(api):
     api.add_resource(Machines, ts_path("machines"))
     api.add_resource(Machine, ts_path("machine/<int:machine_id>"))
     api.add_resource(Runs, ts_path("run/<int:run_id>"))
     api.add_resource(Order, ts_path("order/<int:order_id>"))
+    graph_url = "graph/<int:machine_id>/<int:test_id>/<int:field_index>"
+    api.add_resource(Graph, ts_path(graph_url))

Modified: lnt/trunk/tests/server/ui/test_api.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/test_api.py?rev=249107&r1=249106&r2=249107&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/test_api.py (original)
+++ lnt/trunk/tests/server/ui/test_api.py Thu Oct  1 19:02:36 2015
@@ -58,6 +58,12 @@ order_expected_response = {u'id': 1,
                            u'next_order_id': 0,
                            u'previous_order_id': 2}
 
+graph_data = [{u'time': u'2012-05-01T16:28:23',
+               u'rev': u'152292',
+               u'val': 1.0},
+              {u'time': u'2012-05-03T16:28:24',
+               u'rev': u'152293',
+               u'val': 10.0}]
 
 class JSONAPITester(unittest.TestCase):
     """Test the REST api."""
@@ -97,6 +103,11 @@ class JSONAPITester(unittest.TestCase):
         j = check_json(client, 'api/db_default/v4/nts/order/1')
         self.assertEquals(j, order_expected_response)
 
+    def test_graph_api(self):
+        """Check that /graph/x/y/z returns what we expect."""
+        client = self.client
+        j = check_json(client, 'api/db_default/v4/nts/graph/2/88/3')
+        self.assertEqual(graph_data, j)
 
 if __name__ == '__main__':
     unittest.main(argv=[sys.argv[0], ])




More information about the llvm-commits mailing list