def timeStep(self): #TODO: type checking. clean this up (outputs, recursions) = self.processResponse(self.sensorResponseQueue, \ self.recursiveResponseQueue) self.sensorResponseQueue = [] self.recursiveResponseQueue = recursions main_log.debug(self['Id'] + ' Ouputs ' + str(outputs)) return self.addMapperToResponse(outputs)
def initializeComponent(self, config): components = [] if config != None: for configItem in config.getchildren(): try: [module,className] = configItem.find('Class').text.split('.') except: main_log.error('Module must have Class element') continue try: exec('from ' + module+'.'+className + ' import *') main_log.debug(module +'.' +className + 'imported') except Exception as inst: main_log.error('Error importing ' + module+'.'+className+ '. Component not\ initialized.') main_log.error(str(inst)) continue args = configGetter.pullArgsFromItem(configItem) args['parentScope'] = self try: new_component = eval(className+'(args)') new_component.addDieListener(self) components.append(new_component) main_log.info(className + 'initialized with args ' + str(args)) except Exception as inst: main_log.error('Failure while initializing ' + className + ' with ' + str(args)) main_log.error(str(inst)) return components
def processResponse(self, sensorInputs, recursiveInputs): debug_string = "DebugBehavior<" + self['Id'] + ">\n" if sensorInputs == [] and 'Quiet' in self.argDict and self['Quiet']: return ([], []) if sensorInputs == []: debug_string += "\tNO INPUTS" else: for sensorInput in sensorInputs: debug_string += '\t' + str(sensorInput) + '\n' if 'Output' in self.argDict: if self['Output'] == 'print': print debug_string elif self['Output'] == 'error': main_log.error(debug_string) elif self['Output'] == 'debug': main_log.debug(debug_string) elif self['Output'] == 'info': main_log.info(debug_string) else: if sensorInputs != []: main_log.error('Sensor Inputs: ' + str(sensorInputs)) if 'PassThrough' in self.argDict: if self['PassThrough']: return (sensorInputs, []) else: return ([], []) return ([], [])
def mainLoop(self): lastLoopTime = clock.time() refreshInterval = 30 runCount = 0 dieCount = -1 print 'Starting Main Loop' while not self.dieNow: #dieNow is set if one of its constituents sends a die request. runCount += 1 dieCount -= 1 if dieCount == 0: self.dieNow = True runCount = runCount % 30 loopStart = clock.time() responses = self.evaluateBehaviors() self.timer.start() [self.screen.respond(response) for response in responses if response != []] self.screen.timeStep(loopStart) [r.render(self.screen, loopStart) for r in self.renderers] loopElapsed = clock.time()-loopStart if runCount == 0: print 'FPS: ', 1000 / loopElapsed sleepTime = max(0,refreshInterval-loopElapsed) #print 1000/loopElapsed if loopElapsed > 100: print 'SLOOOWWWW!', 1000 / loopElapsed main_log.debug('Loop complete in {0} ms. Sleeping for {1} ms.'.format(loopElapsed, sleepTime)) self.timer.stop() if sleepTime > 0: time.sleep(sleepTime/1000)
def initializeComponent(self, config): components = [] if config != None: for configItem in config.getchildren(): try: [module, className] = configItem.find("Class").text.split(".") except: main_log.error("Module must have Class element") continue try: exec("from " + module + "." + className + " import *") main_log.debug(module + "." + className + "imported") except Exception as inst: main_log.error( "Error importing " + module + "." + className + ". Component not\ initialized." ) main_log.error(str(inst)) continue args = configGetter.pullArgsFromItem(configItem) args["parentScope"] = self try: new_component = eval(className + "(args)") new_component.addDieListener(self) components.append(new_component) main_log.info(className + "initialized with args " + str(args)) except Exception as inst: main_log.error("Failure while initializing " + className + " with " + str(args)) main_log.error(str(inst)) return components
def configureInstallation(self, installationConfig): defaults = configGetter.generateArgDict(installationConfig.find('Defaults')) for defaultSelection in defaults: componentToMap = compReg.getComponent(defaults[defaultSelection]) compReg.registerComponent(compReg.getComponent(defaults[defaultSelection]),\ 'Default'+defaultSelection) main_log.debug('Default Set: ' + defaultSelection + 'set to ' +\ defaults[defaultSelection])
def timeStep(self): #TODO: type checking. clean this up (outputs, recursions) = self.processResponse(self.sensorResponseQueue, \ self.recursiveResponseQueue) self.clearInputs() self.recursiveResponseQueue = recursions self.setLastOutput(outputs) main_log.debug(self['Id'] + ' Ouputs ' + str(outputs)) return self.addMapperToResponse(outputs)
def doUpdate(self, cid, paramName, newParamValue, currentObject, callback): if paramName == 'RenderToScreen': if newParamValue == True: newParamValue = True elif newParamValue == False: newParamValue = False else: newParamValue = None if newParamValue is not None: currentObject['RenderToScreen'] = newParamValue elif currentObject.argDict.has_key( 'Mutable') and currentObject.argDict['Mutable'].has_key( paramName): paramName = paramName.strip('()') if paramName in dir( currentObject ): #paramName == 'command_reset' or paramName == 'command_skip': member = currentObject.__getattribute__(paramName) if hasattr(member, '__call__') and newParamValue: try: member() callback(paramName[8:]) except: callback('no ' + paramName[8:]) elif type(member) is type(newParamValue) and \ self.isValidValue(currentObject.argDict['Mutable'][paramName], newParamValue): currentObject.__setattr__(paramName, newParamValue) if currentObject.argDict.has_key(paramName): currentObject[paramName] = newParamValue callback('OK') else: callback('FailedWeird') elif currentObject.argDict.has_key(paramName): if self.isValidValue( currentObject.argDict['Mutable'][paramName], newParamValue): currentObject[paramName] = newParamValue main_log.debug("Modified Correctly") callback('OK') else: main_log.error("Invalid modifier, type: " + str(type(newParamValue)) + " value:" + str(newParamValue)) callback('Failed') else: main_log.error("Invalid mutable for this object.") callback("'" + paramName + "' is invalid method or parameter for this object") else: raise Exception( 'Non-mutable parameter specified.' ) # don't allow anything else for security purposes
def registerComponent(component, cid=None): if cid != None: globals()['Registry'][cid] = component else: try: cid = component['Id'] except KeyError: cid = getNewId() component['Id'] = cid main_log.debug(cid + 'automatically assigned') globals()['Registry'][cid] = component return cid
def registerComponent(component, cid=None): global Registry if cid != None: Registry[cid] = component else: cid = component['Id'] if cid == None: cid = getNewId() component['Id'] = cid main_log.debug(cid + 'automatically assigned') if cid in Registry: main_log.warn(cid + 'overwritten.') Registry[cid] = component return cid
def mainLoop(self): lastLoopTime = clock.time() refreshInterval = 30 while not self.dieNow: # dieNow is set if one of its constituents sends a die request. loopStart = clock.time() responses = self.evaluateBehaviors() self.timer.start() [self.screen.respond(response) for response in responses if response != []] self.screen.timeStep(loopStart) [r.render(self.screen, loopStart) for r in self.renderers] loopElapsed = clock.time() - loopStart sleepTime = max(0, refreshInterval - loopElapsed) main_log.debug("Loop complete in " + str(loopElapsed) + "ms. Sleeping for " + str(sleepTime)) self.timer.stop() if sleepTime > 0: time.sleep(sleepTime / 1000)
def processResponse(self, responseInfo, currentTime=None): #we need to make a new dict for #each to prevent interference if currentTime == None: currentTime = timeops.time() if type(responseInfo) != type(dict()): pass if 'Mapper' in responseInfo: mapper = compReg.getComponent(responseInfo['Mapper']) else: mapper = compReg.getComponent(Strings.DEFAULT_MAPPER) pixelWeightList = mapper.mapEvent(responseInfo['Location'], self) main_log.debug('Screen processing response. ' + str(len(pixelWeightList)) + ' events\ generated') PixelEvent.addPixelEventIfMissing(responseInfo) for (pixel, weight) in pixelWeightList: pixel.processInput(responseInfo['PixelEvent'], 0,weight, currentTime) #TODO: z-index
def doUpdate(self, cid, paramName, newParamValue, currentObject, callback): if paramName == 'RenderToScreen': if newParamValue == True: newParamValue = True elif newParamValue == False: newParamValue = False else: newParamValue = None if newParamValue is not None: currentObject['RenderToScreen'] = newParamValue elif currentObject.argDict.has_key('Mutable') and currentObject.argDict['Mutable'].has_key(paramName): paramName = paramName.strip('()') if paramName in dir(currentObject): #paramName == 'command_reset' or paramName == 'command_skip': member = currentObject.__getattribute__(paramName) if hasattr(member,'__call__') and newParamValue: try: member() callback(paramName[8:]) except: callback('no '+paramName[8:]) elif type(member) is type(newParamValue) and \ self.isValidValue(currentObject.argDict['Mutable'][paramName], newParamValue): currentObject.__setattr__(paramName,newParamValue) if currentObject.argDict.has_key(paramName): currentObject[paramName] = newParamValue callback('OK') else: callback('FailedWeird') elif currentObject.argDict.has_key(paramName): if self.isValidValue(currentObject.argDict['Mutable'][paramName], newParamValue): currentObject[paramName] = newParamValue main_log.debug("Modified Correctly") callback('OK') else: main_log.error("Invalid modifier, type: "+str(type(newParamValue))+" value:"+str(newParamValue)) callback('Failed') else: main_log.error("Invalid mutable for this object.") callback("'"+paramName+"' is invalid method or parameter for this object") else: raise Exception('Non-mutable parameter specified.') # don't allow anything else for security purposes
def processResponse(self, responseInfo, currentTime): mapper = ComponentRegistry.getComponent(responseInfo.get('Mapper', Strings.DEFAULT_MAPPER)) weights = mapper.mapEvent(responseInfo['Location'], self) main_log.debug('Screen processing response. Event generated.') addPixelEventIfMissing(responseInfo) heappush(self.eventHeap, (currentTime, currentTime, responseInfo['PixelEvent'], weights))
def configureInstallation(self, installationConfig): defaults = configGetter.generateArgDict(installationConfig.find("Defaults")) for defaultSelection in defaults: componentToMap = compReg.getComponent(defaults[defaultSelection]) compReg.registerComponent(compReg.getComponent(defaults[defaultSelection]), "Default" + defaultSelection) main_log.debug("Default Set: " + defaultSelection + "set to " + defaults[defaultSelection])