changeset 910:3a15fb921b9c

more tripleFilter speedups. accept Decimals coming in from n3 files, which happens with the 2012 code Ignore-this: 5a63ec4776bf9c4ffc3d6b4f20242ac0
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 10 Jun 2013 09:52:15 +0000
parents 39f4d6d4483e
children 4b9997ab0e4f
files light9/Submaster.py light9/dmxchanedit.py light9/rdfdb/grapheditapi.py
diffstat 3 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/light9/Submaster.py	Mon Jun 10 09:42:23 2013 +0000
+++ b/light9/Submaster.py	Mon Jun 10 09:52:15 2013 +0000
@@ -184,10 +184,10 @@
     def _saveContext(self):
         """the context in which we should save all the lightLevel triples for
         this sub"""
-        with self.graph.currentState() as g:
+        typeStmt = (self.uri, RDF.type, L9['Submaster'])
+        with self.graph.currentState(tripleFilter=typeStmt) as current:
             try:
-                ctx = g.contextsForStatement(
-                    (self.uri, RDF.type, L9['Submaster']))[0]
+                ctx = current.contextsForStatement(typeStmt)[0]
             except IndexError:
                 log.info("declaring %s to be a submaster" % self.uri)
                 ctx = self.uri
--- a/light9/dmxchanedit.py	Mon Jun 10 09:42:23 2013 +0000
+++ b/light9/dmxchanedit.py	Mon Jun 10 09:52:15 2013 +0000
@@ -19,6 +19,7 @@
 from __future__ import nested_scopes,division
 import Tkinter as tk
 from rdflib import RDF, Literal
+from decimal import Decimal
 from light9.namespaces import L9
 
 stdfont = ('Arial', 9)
@@ -191,6 +192,9 @@
         for ll in self.graph.objects(sub, L9['lightLevel']):
             chan = self.graph.value(ll, L9['channel'])
             lev = self.graph.value(ll, L9['level']).toPython()
+            if isinstance(lev, Decimal):
+                 lev = float(lev)
+            assert isinstance(lev, (int, long, float)), repr(lev)
             self.levelFromUri[chan].setTo(lev)
             remaining.remove(chan)
         for channel in remaining:
--- a/light9/rdfdb/grapheditapi.py	Mon Jun 10 09:42:23 2013 +0000
+++ b/light9/rdfdb/grapheditapi.py	Mon Jun 10 09:52:15 2013 +0000
@@ -43,10 +43,17 @@
         value since that's tricky too
         """
 
-        with self.currentState() as graph:
+        # as long as currentState is expensive and has the
+        # tripleFilter optimization, this looks like a mess. If
+        # currentState became cheap, a lot of code here could go away.
+        
+        with self.currentState(tripleFilter=(subject, predicate, None)) as current:
             adds = set([])
-            for setting in graph.objects(subject, predicate):
-                if graph.value(setting, keyPred) == newKey:
+            for setting in current.objects(subject, predicate):
+                with self.currentState(tripleFilter=(setting, keyPred, None)) as current2:
+                
+                    match = current2.value(setting, keyPred) == newKey
+                if match:
                     break
             else:
                 setting = URIRef(subject + "/map/%s" %
@@ -56,8 +63,10 @@
                     (setting, RDF.type, nodeClass, context),
                     (setting, keyPred, newKey, context),
                     ])
+
+        with self.currentState(tripleFilter=(setting, valuePred, None)) as current:
             dels = set([])
-            for prev in graph.objects(setting, valuePred):
+            for prev in current.objects(setting, valuePred):
                 dels.add((setting, valuePred, prev, context))
             adds.add((setting, valuePred, newValue, context))