Changeset - 2239d5648932
[Not reviewed]
default
0 3 0
Drew Perttula - 8 years ago 2017-05-30 07:57:52
drewp@bigasterisk.com
captureDevice saves all pics
Ignore-this: eae0e07b8f6d4a9b719a1193830f866

it used to drop the last one
3 files changed with 43 insertions and 32 deletions:
0 comments (0 inline, 0 general)
bin/captureDevice
Show inline comments
 
@@ -43,73 +43,80 @@ class Camera(object):
 
        except OSError:
 
            pass
 
        with open(writePath, 'w') as out:
 
            out.write(jpg)
 
        log.info('wrote %s', writePath)
 

	
 

	
 
def deferSleep(sec):
 
    d = Deferred()
 
    reactor.callLater(sec, d.callback, None)
 
    return d
 
    
 
class Capture(object):
 
    firstMoveTime = 5
 
    firstMoveTime = 3
 
    settleTime = .5
 
    def __init__(self, graph):
 
    def __init__(self, graph, dev):
 
        self.graph = graph
 
        
 
        def steps(a, b, n):
 
            return [round(a + (b - a) * i / n, 5) for i in range(n)]
 

	
 
        startTime = time.time()
 
        self.captureId = 'cap%s' % (int(startTime) - 1495170000)
 
        self.toGather = []
 

	
 
        row = 0
 
        for ry in steps(0.85, .92, 6):
 
            xSteps = steps(.24, .45, 12)
 
        for ry in steps(0.82, .92, 6):
 
            xSteps = steps(.23, .42, 12)
 
            if row % 2:
 
                xSteps.reverse()
 
            row += 1
 
            for rx in xSteps:
 
                self.toGather.append(DeviceSettings(graph, [
 
                    (L9['device/moving1'], L9['rx'], rx),
 
                    (L9['device/moving1'], L9['ry'], ry),
 
                    (dev, L9['rx'], rx),
 
                    (dev, L9['ry'], ry),
 
                    (dev, L9['color'], '#ffffff'),
 
                ]))
 

	
 
        self.numPics = 0
 
        self.settingsCache = set()
 
        self.step().addErrback(log.error)
 

	
 
    def off(self):
 
        return sendToCollector(client='captureDevice', session='main',
 
                               settings=DeviceSettings(self.graph, []))
 
        
 
    @inlineCallbacks
 
    def step(self):
 
        if not self.toGather:
 
            yield self.off()
 
            yield deferSleep(1)
 
            reactor.stop()
 
            return
 
        settings = self.toGather.pop()
 
        
 
        log.info('move to %r', settings)
 
        yield sendToCollector(client='captureDevice', session='main', settings=settings)
 
        log.info('[%s left] move to %r', len(self.toGather), settings)
 
        yield sendToCollector(client='captureDevice', session='main',
 
                              settings=settings)
 
        
 
        d = Deferred()
 
        reactor.callLater(self.firstMoveTime if self.numPics == 0 else self.settleTime,
 
                          d.callback, None)
 
        yield d
 
        dev = settings.devices()[0]
 

	
 
        devTail = dev.rsplit('/')[-1]
 
        yield deferSleep(self.firstMoveTime if self.numPics == 0 else
 
                         self.settleTime)
 
        
 
        dev = settings.devices()[0]
 
        devTail = dev.rsplit('/')[-1]
 
        picId = 'pic%s' % self.numPics
 
        path = '/'.join(['capture', devTail, self.captureId, picId])
 
        ctx = URIRef('/'.join([showconfig.showUri(), 'capture', devTail, self.captureId,
 
                               'index']))
 
        uri = URIRef('/'.join([showconfig.showUri(), 'capture', devTail, self.captureId,
 
                               picId]))
 
                     
 
        relOutPath = path + '.jpg'
 
        path = '/'.join(['capture', devTail, self.captureId, picId]) + '.jpg'
 
        ctx = URIRef('/'.join([showconfig.showUri(),
 
                               'capture', devTail, self.captureId, 'index']))
 
        uri = URIRef('/'.join([showconfig.showUri(),
 
                               'capture', devTail, self.captureId, picId]))
 
        
 
        yield camera.takePic(uri, os.path.join(showconfig.root(), relOutPath))
 
        yield camera.takePic(uri, os.path.join(showconfig.root(), path))
 
        self.numPics += 1
 

	
 
        writeCaptureDescription(self.graph, ctx, uri, dev, relOutPath,
 
        writeCaptureDescription(self.graph, ctx, uri, dev, path,
 
                                self.settingsCache, settings)
 
        
 
        reactor.callLater(0, self.step)
 

	
 
        
 

	
 
@@ -120,13 +127,13 @@ class Attrs(PrettyErrorHandler, cyclone.
 
        with stats.setAttr.time():
 
            client, clientSession, settings, sendTime = parseJsonMessage(self.request.body)
 
            self.set_status(202)
 

	
 
def launch(graph):
 

	
 
    cap = Capture(graph)
 
    cap = Capture(graph, dev=L9['device/moving1'])
 
    reactor.listenTCP(networking.captureDevice.port,
 
                      cyclone.web.Application(handlers=[
 
                          (r'/()', cyclone.web.StaticFileHandler,
 
                           {"path" : "light9/web", "default_filename" : "captureDevice.html"}),
 
                          (r'/stats', StatsForCyclone),
 
                      ]),
light9/paint/capture.py
Show inline comments
 
@@ -2,21 +2,24 @@ import os
 
from rdflib import URIRef
 
from light9 import showconfig
 
from light9.rdfdb.patch import Patch
 
from light9.namespaces import L9, RDF
 
from light9.paint.solve import loadNumpy
 

	
 
def writeCaptureDescription(graph, ctx, uri, dev, relOutPath, settingsSubgraphCache, settings):
 
def writeCaptureDescription(graph, ctx, uri, dev, outPath, settingsSubgraphCache,
 
                            settings):
 
    graph.patch(Patch(addQuads=settings.statements(
 
        uri, ctx=ctx,
 
        settingRoot=URIRef('/'.join([showconfig.showUri(), 'capture', dev.rsplit('/')[1]])),
 
        settingRoot=URIRef('/'.join([
 
            showconfig.showUri(), 'capture', dev.rsplit('/')[1]])),
 
        settingsSubgraphCache=settingsSubgraphCache)))
 
    graph.patch(Patch(addQuads=[
 
        (dev, L9['capture'], uri, ctx),
 
        (uri, RDF.type, L9['LightSample'], ctx),
 
        (uri, L9['imagePath'], URIRef('/'.join([showconfig.showUri(), relOutPath])), ctx),
 
        (uri, L9['imagePath'], URIRef('/'.join([
 
            showconfig.showUri(), outPath])), ctx),
 
        ]))
 
    graph.suggestPrefixes(ctx, {'cap': uri.rsplit('/', 1)[0] + '/',
 
                                'showcap': showconfig.showUri() + '/capture/'})
 
    
 
class CaptureLoader(object):
 
    def __init__(self, graph):
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -299,24 +299,25 @@ Polymer
 
    effect = U(uri + '/effect')
 
    quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: effect}
 
    
 
    quads = [
 
      quad(effect, U('rdf:type'), U(':Effect')),
 
      quad(effect, U(':copiedFrom'), uri),
 
      quad(effect, U('rdfs:label'), @graph.Literal('')),
 
      quad(effect, U('rdfs:label'), @graph.Literal(uri.replace(/.*capture\//, ''))),
 
      quad(effect, U(':publishAttr'), U(':strength')),
 
      ]
 

	
 
    fromSettings = @graph.objects(uri, U(':setting'))
 

	
 
    toSettings = @graph.nextNumberedResources(effect + '_set', fromSettings.length)
 
      
 
    for fs in fromSettings
 
      ts = toSettings.pop()
 
      # full copies of these since I may have to delete captures
 
      quads.push(quad(effect, U(':setting'), ts))
 
      quads.push(quad(ts, U(':device'), @graph.uriValue(fs, U(':device'))))
 
      quads.push(quad(ts, U(':deviceAttr'), @graph.uriValue(fs, U(':deviceAttr'))))
 
      quads.push(quad(ts, U(':value'), @graph.uriValue(fs, U(':value'))))
 

	
 
    @graph.applyAndSendPatch({delQuads: [], addQuads: quads})
 
    return effect
 
        
 
@@ -495,13 +496,13 @@ Polymer
 
    @dia.setNote(@uri, screenPts, effect)
 

	
 
    leftX = Math.max(2, screenPts[Math.min(1, screenPts.length - 1)].e(1) + 5)
 
    rightX = screenPts[Math.min(2, screenPts.length - 1)].e(1) - 5
 
    if screenPts.length < 3
 
      rightX = leftX + 120
 
    w = 114
 
    w = 150
 
    h = 80
 
    @inlineRect = {
 
      left: leftX,
 
      top: @offsetTop + @offsetHeight - h - 5,
 
      width: w,
 
      height: h,
 
@@ -600,13 +601,13 @@ Polymer
 
    @graph.runHandler(@update.bind(@))
 
    
 
  update: ->
 
    console.time('attrs update')
 
    U = (x) -> @graph.Uri(x)
 
    @effect = @graph.uriValue(@uri, U(':effectClass'))
 
    @effectLabel = @effect.replace(/.*\//, '')
 
    @effectLabel = @graph.stringValue(@effect, U('rdfs:label')) or (@effect.replace(/.*\//, ''))
 
    @noteLabel = @uri.replace(/.*\//, '')
 

	
 
    @existingColorScaleSetting = null
 
    for setting in @graph.objects(@uri, U(':setting'))
 
      ea = @graph.uriValue(setting, U(':effectAttr'))
 
      value = @graph.stringValue(setting, U(':value'))
0 comments (0 inline, 0 general)