[llvm-commits] [zorg] r147162 - in /zorg/trunk/lnt/lnt/server: db/testsuitedb.py ui/views.py

Daniel Dunbar daniel at zuster.org
Thu Dec 22 11:24:15 PST 2011


Author: ddunbar
Date: Thu Dec 22 13:24:15 2011
New Revision: 147162

URL: http://llvm.org/viewvc/llvm-project?rev=147162&view=rev
Log:
[lnt/v0.4]: lnt.server.db.testsuitedb: Move get_adjacent_runs_on_machine onto TestSuiteDB.

Modified:
    zorg/trunk/lnt/lnt/server/db/testsuitedb.py
    zorg/trunk/lnt/lnt/server/ui/views.py

Modified: zorg/trunk/lnt/lnt/server/db/testsuitedb.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/db/testsuitedb.py?rev=147162&r1=147161&r2=147162&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/server/db/testsuitedb.py (original)
+++ zorg/trunk/lnt/lnt/server/db/testsuitedb.py Thu Dec 22 13:24:15 2011
@@ -571,3 +571,49 @@
 
     def getRun(self, id):
         return self.query(self.Run).filter_by(id=id).one()
+
+    def get_adjacent_runs_on_machine(self, run, N, direction = -1):
+        """
+        get_adjacent_runs_on_machine(run, N, direction = -1) -> [Run*]
+
+        Return the N runs which have been submitted to the same machine and are
+        adjacent to the given run.
+
+        The actual number of runs returned may be greater than N in situations
+        where multiple reports were received for the same order.
+
+        The runs will be reported starting with the runs closest to the given
+        run's order.
+
+        The direction must be -1 or 1 and specified whether or not the
+        preceeding or following runs should be returned.
+        """
+        assert direction in (-1, 1), "invalid direction"
+
+        ordinal = run.order.ordinal + direction
+        # FIXME: This probably isn't a great way to limit our search, at least
+        # for SQLite which can't answer this quickly.
+        last_ordinal = self.query(self.Order).count()
+        while 0 <= ordinal <= last_ordinal and N > 0:
+            # Find all the runs on this machine for the current ordinal.
+            found_any = False
+            for item in self.query(self.Run).\
+                    join(self.Order).\
+                    filter(self.Order.ordinal == ordinal).\
+                    filter(self.Run.machine == run.machine):
+                yield item
+                found_any = True
+
+            # If we found any, decrement the number of orders remaining to find
+            # runs for.
+            if found_any:
+                N -= 1
+
+            # Update the ordinal we are searching for runs for.
+            ordinal += direction
+
+    def get_previous_runs_on_machine(self, run, N):
+        return self.get_adjacent_runs_on_machine(run, N, direction = -1)
+
+    def get_next_runs_on_machine(self, run, N):
+        return self.get_adjacent_runs_on_machine(run, N, direction = 1)

Modified: zorg/trunk/lnt/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/ui/views.py?rev=147162&r1=147161&r2=147162&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/server/ui/views.py (original)
+++ zorg/trunk/lnt/lnt/server/ui/views.py Thu Dec 22 13:24:15 2011
@@ -638,34 +638,6 @@
                            testsuite_name=g.testsuite_name, id=id,
                            associated_runs=associated_runs)
 
-def get_adjacent_runs_on_machine(ts, run, N):
-    prev_runs = []
-    ordinal = run.order.ordinal - 1
-    while ordinal >= 0 and (len(prev_runs) < N or
-                           run.order.ordinal - ordinal < N):
-        # Find all the runs on this machine from the previous order.
-        prev_runs.extend(ts.query(ts.Run).\
-                             join(ts.Order).\
-                             filter(ts.Order.ordinal == ordinal).\
-                             filter(ts.Run.machine == run.machine))
-        ordinal = ordinal - 1
-
-    next_runs = []
-    ordinal = run.order.ordinal + 1
-    # FIXME: This probably isn't a great way to limit our search, at least for
-    # SQLite which can't answer this quickly.
-    last_ordinal = ts.query(ts.Order).count()
-    while ordinal != last_ordinal and (len(next_runs) < N or
-                                       ordinal - run.order.ordinal < N):
-        # Find all the runs on this machine from the next order.
-        next_runs.extend(ts.query(ts.Run).\
-            join(ts.Order).\
-            filter(ts.Order.ordinal == ordinal).\
-            filter(ts.Run.machine == run.machine))
-        ordinal = ordinal + 1
-
-    return next_runs[::-1] + [run] + prev_runs
-
 @v4_route("/<int:id>/report")
 def v4_report(id):
     db = request.get_db()
@@ -699,7 +671,9 @@
     run = ts.getRun(id)
 
     # Find the neighboring runs, by order.
-    neighboring_runs = get_adjacent_runs_on_machine(ts, run, N = 3)
+    prev_runs = list(ts.get_previous_runs_on_machine(run, N = 3))
+    next_runs = list(ts.get_next_runs_on_machine(run, N = 3))
+    neighboring_runs = next_runs[::-1] + [run] + prev_runs
 
     # Parse the view options.
     options = {}





More information about the llvm-commits mailing list