Changeset - 3a15fb921b9c
[Not reviewed]
default
0 3 0
Drew Perttula - 12 years ago 2013-06-10 09:52:15
drewp@bigasterisk.com
more tripleFilter speedups. accept Decimals coming in from n3 files, which happens with the 2012 code
Ignore-this: 5a63ec4776bf9c4ffc3d6b4f20242ac0
3 files changed with 20 insertions and 7 deletions:
0 comments (0 inline, 0 general)
light9/Submaster.py
Show inline comments
 
@@ -181,16 +181,16 @@ class PersistentSubmaster(Submaster):
 
                log.error("name %r val %r" % (name, val))
 
                raise
 

	
 
    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
 
                self.graph.patch(Patch(addQuads=[
 
                    (self.uri, RDF.type, L9['Submaster'], ctx),
 
                    ]))
light9/dmxchanedit.py
Show inline comments
 
@@ -16,12 +16,13 @@ proposal for new attribute system:
 
- we have to stop packing these into the names. Names should be like 'b33' or 'blue3' or just '44'. maybe 'blacklight'.
 

	
 
"""
 
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)
 

	
 
def gradient(lev, low=(80,80,180), high=(255,55,50)):
 
     out = [int(l+lev*(h-l)) for h,l in zip(high,low)]
 
@@ -188,12 +189,15 @@ class Levelbox(tk.Frame):
 
            raise ValueError("currentSub is %r" % submaster)
 

	
 
        remaining = set(self.levelFromUri.keys())
 
        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:
 
            self.levelFromUri[channel].setTo(0)
 

	
 
    def onLevelChange(self, chan, newLevel):
light9/rdfdb/grapheditapi.py
Show inline comments
 
@@ -40,27 +40,36 @@ class GraphEditApi(object):
 
             ?valuePred ?newValue ] .
 

	
 
        There should be a complementary readMapping that gets you a
 
        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" %
 
                                 random.randrange(999999999))
 
                adds.update([
 
                    (subject, predicate, setting, context),
 
                    (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))
 

	
 
            if adds != dels:
 
                self.patch(Patch(delQuads=dels, addQuads=adds))
 

	
0 comments (0 inline, 0 general)