Changeset - 77eaccba654e
[Not reviewed]
default
0 6 0
Drew Perttula - 8 years ago 2017-06-10 07:17:20
drewp@bigasterisk.com
try to fix timeline sending empty ctx to rdfdb
Ignore-this: f778183e90f073b9914d9b6736560d99
6 files changed with 33 insertions and 14 deletions:
0 comments (0 inline, 0 general)
light9/rdfdb/rdflibpatch.py
Show inline comments
 
@@ -67,12 +67,13 @@ def graphFromQuads(q):
 
        #g.get_context(c).add((s,p,o)) # kind of works with broken rdflib nquad serializer code; you need this for json_ld serialize to work :(
 
        g.store.add((s,p,o), c) # no effect on nquad output
 
    return g
 

	
 
def graphFromNQuad(text):
 
    g1 = ConjunctiveGraph()
 
    # text might omit ctx on some lines. rdflib just puts in a bnode, which shows up later.
 
    g1.parse(data=text, format='nquads')
 
    return g1
 

	
 
from rdflib.plugins.serializers.nt import _quoteLiteral
 
def serializeQuad(g):
 
    """
light9/web/effects/effects.coffee
Show inline comments
 
Polymer
 
  is: "light9-effects"
 
  properties: 
 
    graph: {type: Object}
 
    effectClasses: { type: Array }
 
  ready: ->
 
    @graph.runHandler(@getClasses.bind(@))
 
    @graph.runHandler(@getClasses.bind(@), 'getClasses')
 

	
 
  getClasses: ->
 
    U = (x) => @graph.Uri(x)
 
    @effectClasses = _.sortBy(@graph.subjects(U('rdf:type'), U(':Effect')))
 

	
 
Polymer
light9/web/graph.coffee
Show inline comments
 
@@ -68,12 +68,15 @@ class AutoDependencies
 
    @handlers = new Handler(null) # tree of all known Handlers (at least those with non-empty patterns). Top node is not a handler.
 
    @handlerStack = [@handlers] # currently running
 
    
 
  runHandler: (func, label) ->
 
    # what if we have this func already? duplicate is safe?
 

	
 
    if not label?
 
      throw new Error("missing label")
 

	
 
    h = new Handler(func, label)
 
    @handlerStack[@handlerStack.length - 1].innerHandlers.push(h)
 
    console.time("handler #{label}")
 
    @_rerunHandler(h, null)
 
    console.timeEnd("handler #{label}")
 
    
 
@@ -124,25 +127,29 @@ class window.SyncedGraph
 
    # prefixes can be used in Uri(curie) calls.
 
    @_watchers = new GraphWatchers() # old
 
    @_autoDeps = new AutoDependencies() # replaces GraphWatchers
 
    @clearGraph()
 

	
 
    if @patchSenderUrl
 
      @_client = new RdfDbClient(@patchSenderUrl, @clearGraph.bind(@),
 
      @_client = new RdfDbClient(@patchSenderUrl, @_clearGraphOnNewConnection.bind(@),
 
                                 @_applyPatch.bind(@), @setStatus)
 
    
 
  clearGraph: -> # for debugging
 
  clearGraph: ->
 
    # just deletes the statements; watchers are unaffected.
 
    if @graph?
 
      @_applyPatch({addQuads: [], delQuads: @graph.find()})
 

	
 
    # if we had a Store already, this lets N3.Store free all its indices/etc
 
    @graph = N3.Store()
 
    @_addPrefixes(@prefixes)
 
    @cachedFloatValues = new Map();
 
    
 

	
 
  _clearGraphOnNewConnection: -> # must not send a patch to the server!
 
    log('graph: clearGraphOnNewConnection')
 
    @clearGraph()
 
    log('graph: clearGraphOnNewConnection done')
 
      
 
  _addPrefixes: (prefixes) ->
 
    @graph.addPrefixes(prefixes)
 
        
 
  Uri: (curie) ->
 
    N3.Util.expandPrefixedName(curie, @graph._prefixes)
 
@@ -172,12 +179,19 @@ class window.SyncedGraph
 
  quads: () -> # for debugging
 
    [q.subject, q.predicate, q.object, q.graph] for q in @graph.find()
 

	
 
  applyAndSendPatch: (patch) ->
 
    if !Array.isArray(patch.addQuads) || !Array.isArray(patch.delQuads)
 
      throw new Error("corrupt patch: #{patch}")
 

	
 
    for qs in [patch.addQuads, patch.delQuads]
 
      for q in qs
 
        if not q.graph?
 
          throw new Error("corrupt patch: #{q}")
 

	
 
    log('graph: patch', patch)
 
    @_applyPatch(patch)
 
    @_client.sendPatch(patch) if @_client
 

	
 
  _applyPatch: (patch) ->
 
    # In most cases you want applyAndSendPatch.
 
    # 
light9/web/live/live.coffee
Show inline comments
 
@@ -154,13 +154,13 @@ Polymer
 
    patch = {addQuads: addQuads, delQuads: []}
 
    log('save', patch)
 
    @graph.applyAndSendPatch(patch)
 
    @newEffectName = ''
 

	
 
  onGraph: ->
 
    @graph.runHandler(@update.bind(@))
 
    @graph.runHandler(@update.bind(@), 'controls')
 
  resendAll: ->
 
    for llc in @getElementsByTagName("light9-live-control")
 
      llc.resend()
 
  clearAll: ->
 
    for llc in @getElementsByTagName("light9-live-control")
 
      llc.clear()
light9/web/rdfdbclient.coffee
Show inline comments
 
@@ -49,13 +49,13 @@ parseJsonPatch = (jsonPatch, cb) ->
 
                    cb()
 

	
 
  async.parallel([parseAdds, parseDels], ((err) => cb(patch)))
 

	
 
class window.RdfDbClient
 
  # Send and receive patches from rdfdb
 
  constructor: (@patchSenderUrl, @clearGraph, @applyPatch, @setStatus) ->
 
  constructor: (@patchSenderUrl, @clearGraphOnNewConnection, @applyPatch, @setStatus) ->
 
    @_patchesToSend = []
 
    @_lastPingMs = -1
 
    @_patchesReceived = 0
 
    @_patchesSent = 0
 

	
 
    @_reconnectionTimeout = null
 
@@ -74,35 +74,35 @@ class window.RdfDbClient
 
      #{@_patchesReceived} recv;
 
      #{@_patchesSent} sent;
 
      #{@_patchesToSend.length} pending;
 
      #{ping}ms")
 
 
 
  sendPatch: (patch) ->
 
    console.log('queue patch to server ', patchSizeSummary(patch))
 
    console.log('rdfdbclient: queue patch to server ', patchSizeSummary(patch))
 
    @_patchesToSend.push(patch)
 
    @_updateStatus()
 
    @_continueSending()           
 

	
 
  _newConnection: ->
 
    wsOrWss = window.location.protocol.replace('http', 'ws')
 
    fullUrl = wsOrWss + '//' + window.location.host + @patchSenderUrl
 
    @ws.close() if @ws?
 
    @ws = new WebSocket(fullUrl)
 

	
 
    @ws.onopen = =>
 
      log('connected to', fullUrl)
 
      log('rdfdbclient: connected to', fullUrl)
 
      @_updateStatus()
 
      @clearGraph()
 
      @clearGraphOnNewConnection()
 
      @_pingLoop()
 

	
 
    @ws.onerror = (e) =>
 
      log('ws error ' + e)
 
      log('rdfdbclient: ws error ' + e)
 
      @ws.onclose()
 

	
 
    @ws.onclose = =>
 
      log('ws close')
 
      log('rdfdbclient: ws close')
 
      @_updateStatus()
 
      clearTimeout(@_reconnectionTimeout) if @_reconnectionTimeout?
 
      @_reconnectionTimeout = setTimeout(@_newConnection.bind(@), 1000)
 

	
 
    @ws.onmessage = @_onMessage.bind(@)
 

	
 
@@ -131,13 +131,13 @@ class window.RdfDbClient
 

	
 
    # we could call this less often and coalesce patches together to optimize
 
    # the dragging cases.
 

	
 
    sendOne = (patch, cb) =>
 
        toJsonPatch(patch, (json) =>
 
          log('send patch to server, ' + json.length + ' bytes')
 
          log('rdfdbclient: send patch to server, ' + json.length + ' bytes')
 
          @ws.send(json)
 
          @_patchesSent++
 
          @_updateStatus()
 
          cb(null)
 
      )
 

	
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -282,13 +282,13 @@ Polymer
 
    graph: { type: Object, notify: true }
 
    selection: { type: Object, notify: true }
 
    dia: { type: Object, notify: true }
 
    song: { type: String, notify: true }
 
    zoomInX: { type: Object, notify: true }
 
    rows: { value: [0...ROW_COUNT] }
 
    zoom: { type: Object, notify: true, observer: 'onZoom' }
 
    zoom: { type: Object, notify: true, observer: 'onZoom' } # viewState.zoomSpec
 
    zoomFlattened: { type: Object, notify: true }
 
  onZoom: ->
 
    updateZoomFlattened = ->
 
      log('updateZoomFlattened')
 
      @zoomFlattened = ko.toJS(@zoom)
 
    ko.computed(updateZoomFlattened.bind(@))
 
@@ -361,12 +361,13 @@ Polymer
 
        quad(newCurve, U(':attr'), U(':strength'))
 
      ]        
 
    pointQuads = []
 

	
 
    desiredWidthX = @offsetWidth * .3
 
    desiredWidthT = @zoomInX.invert(desiredWidthX) - @zoomInX.invert(0)
 
    desiredWidthT = Math.min(desiredWidthT, @zoom.duration() - dropTime)
 
    
 
    for i in [0...4]
 
      pt = points[i]
 
      pointQuads.push(quad(newCurve, U(':point'), pt))
 
      pointQuads.push(quad(pt, U(':time'), @graph.LiteralRoundedFloat(i/3 * desiredWidthT)))
 
      pointQuads.push(quad(pt, U(':value'), @graph.LiteralRoundedFloat(i == 1 or i == 2)))
 
@@ -627,12 +628,15 @@ Polymer
 
    if @colorScale == @colorScaleFromGraph
 
      return
 
    @editAttr(@song, @uri, U(':colorScale'), @graph.Literal(@colorScale))
 

	
 
  editAttr: (song, note, attr, value) ->
 
    U = (x) => @graph.Uri(x)
 
    if not song?
 
      log("can't edit inline attr yet, no song")
 
      return
 
    quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: song}
 

	
 
    existingColorScaleSetting = null
 
    for setting in @graph.objects(note, U(':setting'))
 
      ea = @graph.uriValue(setting, U(':effectAttr'))
 
      if ea == attr
 
@@ -647,13 +651,13 @@ Polymer
 
        quad(setting, U(':effectAttr'), attr)
 
        quad(setting, U(':value'), value)
 
        ]}
 
      @graph.applyAndSendPatch(patch)
 
    
 
  addHandler: ->
 
    @graph.runHandler(@update.bind(@))
 
    @graph.runHandler(@update.bind(@), "update inline attrs #{@uri}")
 
    
 
  update: ->
 
    #console.time('attrs update')
 
    U = (x) => @graph.Uri(x)
 
    @effect = @graph.uriValue(@uri, U(':effectClass'))
 
    @effectLabel = @graph.stringValue(@effect, U('rdfs:label')) or (@effect.replace(/.*\//, ''))
0 comments (0 inline, 0 general)