Prechádzať zdrojové kódy

add jobs to gridviewer

olivier.massot 8 rokov pred
rodič
commit
53dc29145a

+ 13 - 5
tools/gridviewer/GridViewer.py

@@ -179,10 +179,10 @@ class GridViewer(QMainWindow):
         self.update_selected_cells(result)
 
         saved = self.saved_result_for(callstr)
+        msg = "Exec. in {0:.2f} ms.".format(ittime)
         if saved:
-            self.ui.lbl_job_exectime.setText("Exec. in {0:.2f} ms. / Saved: {1:.2f} ms. / Same result: {2:}".format(ittime, saved[3], str(result) == saved[2]))
-        else:
-            self.ui.lbl_job_exectime.setText("Exec. in {0:.2f} ms.".format(ittime))
+            msg += " (saved: {1:.2f} ms., same result: {2:})".format(saved[3], str(result) == saved[2])
+        self.ui.lbl_job_exectime.setText(msg)
 
     @staticmethod
     def get_job_names():
@@ -192,10 +192,16 @@ class GridViewer(QMainWindow):
 
     @staticmethod
     def run_job(job_name):
+        QApplication.setOverrideCursor(Qt.WaitCursor)
         with open("jobs.yml", "r") as f:
             jobs = yaml.load(f)
-        callstrings = [(gridstr, "{}.{}".format(gridstr, funcstr)) for gridstr, calls in jobs[job_name].items() for funcstr in calls]
-        return [(gridstr, callstr, eval(callstr), GridViewer.ittime(callstr)) for gridstr, callstr in callstrings]
+        job = jobs[job_name]
+        callstrings = ((gridstr, "{}.{}".format(gridstr, funcstr)) for gridstr in job["grids"] for funcstr in job["calls"])
+
+        results = [(gridstr, callstr, eval(callstr), GridViewer.ittime(callstr)) for gridstr, callstr in callstrings]
+
+        QApplication.restoreOverrideCursor()
+        return results
 
     @staticmethod
     def ittime(callstr):
@@ -230,6 +236,8 @@ class GridViewer(QMainWindow):
 
     @staticmethod
     def save_result(gridstr, callstr, result, ittime):
+        if len(result) > 1000000:
+            raise IOError("too large to be stored")
         data = GridViewer.saved_results()
         data[callstr] = [gridstr, callstr, str(result), ittime]
         with open("results.yml", "w+") as f:

+ 102 - 14
tools/gridviewer/jobs.yml

@@ -1,18 +1,6 @@
 job_lines:
-  SquareGrid(101, 101):
-  - "line(0, 0, 0, 0)"  
-  - "line(0, 0, 1, 1)"
-  - "line(0, 0, 10, 10)"
-  - "line(0, 0, 100, 100)"
-  - "line(10, 10, 10, 5)"
-  - "line(10, 10, 15, 5)"
-  - "line(10, 10, 15, 10)"
-  - "line(10, 10, 15, 15)"
-  - "line(10, 10, 10, 15)"
-  - "line(10, 10, 5, 15)"
-  - "line(10, 10, 5, 10)"
-  - "line(10, 10, 5, 5)"
-  FHexGrid(101, 101):
+  grids: ["SquareGrid(101, 101)", "FHexGrid(101, 101)"]
+  calls:
   - "line(0, 0, 0, 0)"  
   - "line(0, 0, 1, 1)"
   - "line(0, 0, 10, 10)"
@@ -25,3 +13,103 @@ job_lines:
   - "line(10, 10, 5, 15)"
   - "line(10, 10, 5, 10)"
   - "line(10, 10, 5, 5)"
+
+job_zone:
+  grids: ["SquareGrid(51, 51)", "FHexGrid(51, 51)"]
+  calls:
+  - "zone(25,25,0)"
+  - "zone(25,25,1)"
+  - "zone(25,25,2)"
+  - "zone(25,25,3)"
+  - "zone(25,25,4)"
+  - "zone(25,25,5)"
+  - "zone(25,25,15)"
+
+job_triangle1:
+  grids: ["SquareGrid(51, 51)", "FHexGrid(51, 51)"]
+  calls:
+  - "triangle(10, 10, 10, 10, 1)"  
+#  - "triangle(10, 10, 10, 5, 1)"
+  - "triangle(10, 10, 15, 5, 1)"
+  - "triangle(10, 10, 15, 10, 1)"
+  - "triangle(10, 10, 15, 15, 1)"
+  - "triangle(10, 10, 10, 15, 1)"
+  - "triangle(10, 10, 5, 15, 1)"
+  - "triangle(10, 10, 5, 10, 1)"
+  - "triangle(10, 10, 5, 5, 1)"
+  
+job_triangle2:
+  grids: ["SquareGrid(51, 51)", "FHexGrid(51, 51)"]
+  calls:
+#  - "triangle(10, 10, 10, 5, 2)"
+  - "triangle(10, 10, 15, 5, 2)"
+  - "triangle(10, 10, 15, 10, 2)"
+  - "triangle(10, 10, 15, 15, 2)"
+  - "triangle(10, 10, 10, 15, 2)"
+  - "triangle(10, 10, 5, 15, 2)"
+  - "triangle(10, 10, 5, 10, 2)"
+  - "triangle(10, 10, 5, 5, 2)"
+  
+job_triangle3:
+  grids: ["SquareGrid(51, 51)", "FHexGrid(51, 51)"]
+  calls:
+#  - "triangle(10, 10, 10, 5, 3)"
+  - "triangle(10, 10, 15, 5, 3)"
+  - "triangle(10, 10, 15, 10, 3)"
+  - "triangle(10, 10, 15, 15, 3)"
+  - "triangle(10, 10, 10, 15, 3)"
+  - "triangle(10, 10, 5, 15, 3)"
+  - "triangle(10, 10, 5, 10, 3)"
+  - "triangle(10, 10, 5, 5, 3)"
+  
+job_rectangle:
+  grids: ["SquareGrid(51, 51)", "FHexGrid(51, 51)"]
+  calls:
+  - "rectangle(10,10,10,10)"
+  - "rectangle(10,10,11,11)"
+  - "rectangle(10,10,15,15)"
+  - "rectangle(10,10,5,5)"
+  - "rectangle(5,10,5,5)"
+  - "rectangle(10,5,5,5)"  
+  - "rectangle(10,10,30,30)"
+  
+job_hollow_rectangle:
+  grids: ["SquareGrid(51, 51)", "FHexGrid(51, 51)"]
+  calls:
+  - "hollow_rectangle(10,10,10,10)"
+  - "hollow_rectangle(10,10,11,11)"
+  - "hollow_rectangle(10,10,15,15)"
+  - "hollow_rectangle(10,10,5,5)"
+  - "hollow_rectangle(5,10,5,5)"
+  - "hollow_rectangle(10,5,5,5)"  
+  - "hollow_rectangle(10,10,30,30)"
+  
+job_rotate:
+  grids: ["SquareGrid(51, 51)", "FHexGrid(51, 51)"]
+  calls:
+  - "rotate((10,10), [], 0)"
+  - "rotate((10,10), [], 1)"
+  - "rotate((10,10), [(10,10)], 0)"
+  - "rotate((10,10), [(10,10)], 1)"
+  - "rotate((10,10), [(11,10)], 0)"
+  - "rotate((10,10), [(11,10)], 1)"
+  - "rotate((10,10), [(11,10)], 2)"
+  - "rotate((10,10), [(11,10)], 3)"
+  - "rotate((10,10), [(11,10)], 4)"
+  - "rotate((10,10), [(11,10)], 5)"
+  - "rotate((10,10), [(11,10)], 6)"
+  - "rotate((10,10), [(11,11), (12,12), (13,13)], 0)"
+  - "rotate((10,10), [(11,11), (12,12), (13,13)], 1)"
+  - "rotate((10,10), [(11,11), (12,12), (13,13)], 2)"
+  - "rotate((10,10), [(11,11), (12,12), (13,13)], 3)"
+  - "rotate((10,10), [(11,11), (12,12), (13,13)], 4)"
+  - "rotate((10,10), [(11,11), (12,12), (13,13)], 5)"
+  - "rotate((10,10), [(11,11), (12,12), (13,13)], 6)"
+  - "rotate((10,10), [(12, 13), (12, 14), (13, 13), (14, 14), (15, 14), (14, 15), (13, 15), (14, 16), (15, 16), (14, 17), (14, 18), (16, 14), (17, 13), (17, 11)], 0)"
+  - "rotate((10,10), [(12, 13), (12, 14), (13, 13), (14, 14), (15, 14), (14, 15), (13, 15), (14, 16), (15, 16), (14, 17), (14, 18), (16, 14), (17, 13), (17, 11)], 1)"
+  - "rotate((10,10), [(12, 13), (12, 14), (13, 13), (14, 14), (15, 14), (14, 15), (13, 15), (14, 16), (15, 16), (14, 17), (14, 18), (16, 14), (17, 13), (17, 11)], 2)"
+  - "rotate((10,10), [(12, 13), (12, 14), (13, 13), (14, 14), (15, 14), (14, 15), (13, 15), (14, 16), (15, 16), (14, 17), (14, 18), (16, 14), (17, 13), (17, 11)], 3)"
+  - "rotate((10,10), [(12, 13), (12, 14), (13, 13), (14, 14), (15, 14), (14, 15), (13, 15), (14, 16), (15, 16), (14, 17), (14, 18), (16, 14), (17, 13), (17, 11)], 4)"
+  - "rotate((10,10), [(12, 13), (12, 14), (13, 13), (14, 14), (15, 14), (14, 15), (13, 15), (14, 16), (15, 16), (14, 17), (14, 18), (16, 14), (17, 13), (17, 11)], 5)"
+  - "rotate((10,10), [(12, 13), (12, 14), (13, 13), (14, 14), (15, 14), (14, 15), (13, 15), (14, 16), (15, 16), (14, 17), (14, 18), (16, 14), (17, 13), (17, 11)], 6)"
+  

+ 27 - 34
tools/gridviewer/qt_viewer.ui

@@ -20,7 +20,7 @@
    <string>GridViewer</string>
   </property>
   <widget class="QWidget" name="centralwidget">
-   <layout class="QHBoxLayout" name="horizontalLayout" stretch="2,0">
+   <layout class="QHBoxLayout" name="horizontalLayout" stretch="2">
     <property name="spacing">
      <number>3</number>
     </property>
@@ -253,28 +253,32 @@
        </widget>
       </item>
       <item>
-       <widget class="QGraphicsView" name="view">
-        <property name="font">
-         <font>
-          <stylestrategy>PreferAntialias</stylestrategy>
-         </font>
-        </property>
-        <property name="verticalScrollBarPolicy">
-         <enum>Qt::ScrollBarAsNeeded</enum>
-        </property>
-        <property name="horizontalScrollBarPolicy">
-         <enum>Qt::ScrollBarAsNeeded</enum>
-        </property>
-        <property name="transformationAnchor">
-         <enum>QGraphicsView::AnchorUnderMouse</enum>
-        </property>
-        <property name="resizeAnchor">
-         <enum>QGraphicsView::AnchorUnderMouse</enum>
-        </property>
-        <property name="viewportUpdateMode">
-         <enum>QGraphicsView::BoundingRectViewportUpdate</enum>
-        </property>
-       </widget>
+       <layout class="QHBoxLayout" name="horizontalLayout_5">
+        <item>
+         <widget class="QGraphicsView" name="view">
+          <property name="font">
+           <font>
+            <stylestrategy>PreferAntialias</stylestrategy>
+           </font>
+          </property>
+          <property name="verticalScrollBarPolicy">
+           <enum>Qt::ScrollBarAsNeeded</enum>
+          </property>
+          <property name="horizontalScrollBarPolicy">
+           <enum>Qt::ScrollBarAsNeeded</enum>
+          </property>
+          <property name="transformationAnchor">
+           <enum>QGraphicsView::AnchorUnderMouse</enum>
+          </property>
+          <property name="resizeAnchor">
+           <enum>QGraphicsView::AnchorUnderMouse</enum>
+          </property>
+          <property name="viewportUpdateMode">
+           <enum>QGraphicsView::BoundingRectViewportUpdate</enum>
+          </property>
+         </widget>
+        </item>
+       </layout>
       </item>
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout_4">
@@ -336,16 +340,6 @@
       </item>
      </layout>
     </item>
-    <item>
-     <layout class="QVBoxLayout" name="verticalLayout_2">
-      <property name="spacing">
-       <number>2</number>
-      </property>
-      <property name="leftMargin">
-       <number>0</number>
-      </property>
-     </layout>
-    </item>
    </layout>
   </widget>
   <widget class="QStatusBar" name="statusbar"/>
@@ -356,7 +350,6 @@
   </action>
  </widget>
  <tabstops>
-  <tabstop>view</tabstop>
   <tabstop>btn_new_grid</tabstop>
   <tabstop>cb_jobs</tabstop>
   <tabstop>btn_list_view</tabstop>