changeset 789:ea8ca6502255

refactor to prepare for submasters to work out of the main graph Ignore-this: a5d4b63cf6b7daf52cce9bbfc3e0c5b3
author drewp@bigasterisk.com
date Mon, 18 Jun 2012 01:34:40 +0000
parents 8d87a3528369
children 690c837f8842
files bin/curvecalc light9/Submaster.py light9/curvecalc/subtermview.py
diffstat 3 files changed, 31 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/bin/curvecalc	Mon Jun 18 01:13:18 2012 +0000
+++ b/bin/curvecalc	Mon Jun 18 01:34:40 2012 +0000
@@ -34,6 +34,7 @@
 from light9.curvecalc.output import Output
 from light9.gtkpyconsole import togglePyConsole
 
+@prof.logTime
 def makeGraph():
     graphOrig = showconfig.getGraph()
     graph = Graph() # a copy, since we're going to add subs into it
@@ -374,4 +375,5 @@
 
     prof.run(reactor.run, profile=False)
 
-main()
+prof.run(main, profile=False)
+
--- a/light9/Submaster.py	Mon Jun 18 01:13:18 2012 +0000
+++ b/light9/Submaster.py	Mon Jun 18 01:34:40 2012 +0000
@@ -1,5 +1,5 @@
 from __future__ import division
-import os, logging
+import os, logging, time
 from rdflib import Graph
 from rdflib import RDFS, Literal, BNode
 from light9.namespaces import L9, XSD
@@ -75,22 +75,29 @@
                     pass
                 else:
                     inFile = showconfig.subFile(self.name)
-                    log.info("reading %s", inFile)
+
+                    t1 = time.time()
                     graph.parse(inFile, format="n3")
-            self.uri = L9['sub/%s' % self.name]
-            for lev in graph.objects(self.uri, L9['lightLevel']):
-                chan = graph.value(lev, L9['channel'])
-                val = graph.value(lev, L9['level'])
-                name = patchGraph.label(chan)
-                if not name:
-                    log.error("sub %r has channel %r with no name- leaving out that channel" % (self.name, chan))
-                    continue
-                self.levels[name] = float(val)
-
+                    log.info("reading %s in %.1fms", inFile, 1000 * (time.time() - t1))
+                    
+                self.setLevelsFromGraph(graph, patchGraph)
+                
             if (not quiet) and (oldlevels != self.levels):
                 log.info("sub %s changed" % self.name)
         except IOError, e:
             log.error("Can't read file for sub: %r (%s)" % (self.name, e))
+
+    def setLevelsFromGraph(self, graph, patchGraph):
+        self.uri = L9['sub/%s' % self.name]
+        for lev in graph.objects(self.uri, L9['lightLevel']):
+            chan = graph.value(lev, L9['channel'])
+            val = graph.value(lev, L9['level'])
+            name = patchGraph.label(chan)
+            if not name:
+                log.error("sub %r has channel %r with no name- leaving out that channel" % (self.name, chan))
+                continue
+            self.levels[name] = float(val)
+
     def save(self):
         if self.temporary:
             log.info("not saving temporary sub named %s",self.name)
@@ -231,14 +238,15 @@
         self.submasters = {}
 
         files = os.listdir(showconfig.subsDir())
-
+        t1 = time.time()
         for filename in files:
             # we don't want these files
             if filename.startswith('.') or filename.endswith('~') or \
                filename.startswith('CVS'):
                 continue
             self.submasters[filename] = Submaster(filename, graph=graph)
-        log.info("loaded subs %s", self.submasters)
+        log.info("loaded all submasters in %.1fms" % ((time.time() - t1) * 1000))
+        
     def get_all_subs(self):
         "All Submaster objects"
         l = self.submasters.items()
--- a/light9/curvecalc/subtermview.py	Mon Jun 18 01:13:18 2012 +0000
+++ b/light9/curvecalc/subtermview.py	Mon Jun 18 01:34:40 2012 +0000
@@ -67,8 +67,12 @@
     if expr is None:
         expr = '%s(t)' % subname
 
-    term = Subterm(Submaster.Submaster(graph=graph, name=subname, sub=subUri),
-                   Subexpr(curveset, expr, graph))
+    # this is what I'd like to have, but the name replacement above is
+    # too unclear for me to make the change now
+    #get_global_submasters(graph).get_sub_by_name(
+        
+    sub = Submaster.Submaster(graph=graph, name=subname, sub=subUri)
+    term = Subterm(sub, Subexpr(curveset, expr, graph))
     subterms.append(term)
 
     stv = Subtermview(graph, term)