Ejemplo n.º 1
0
    def Collect(self):
        list = self.GetCollectors()
        if len(list) < 1:
            return None
        try:
            for objCollector in list:
                if not hasattr(objCollector, "MaxCollectedValue"):
                    objCollector.MaxCollectedValue = objCollector.GetLastValue()

            if not Utility.IsNumeric(list[0].MaxCollectedValue):
                if not self._InvalidInpWarningSent:
                    Log.getLogger().warn("An Input to Operator MaxValue is non numeric.--> " + objCollector.MaxCollectedValue)
                    self._InvalidInpWarningSent = True
                return "HelenKeller"

            max = float(list[0].MaxCollectedValue)
            for objCollector in list:
                if not Utility.IsNumeric(objCollector.MaxCollectedValue):
                    return None

                val = float(objCollector.MaxCollectedValue)
                if not objCollector.ReadyForConsumption() and not objCollector.IsDefaultValue():
                    
                    return None # hasn't yet collecte

                if val > max:
                    max = val

        except Exception as Ex:
            if not self._InvalidInpWarningSent:
                Log.getLogger().warn("An Input to Operator MaxValue is non numeric.--> " + objCollector.MaxCollectedValue)
                self._InvalidInpWarningSent = True
            max = ""

        return str(max)
    def SetCurrentNumber(self,newNumber):
        if Utility.IsNumeric(newNumber) and newNumber> -1 and newNumber < self.GetDataCount():
            self.CurrentIndex = newNumber
            self.IndexExternallySet = True

        else:
            Log.getLogger().warn("Tried to set playback index to invalid value: " + str(newNumber))
    def SetPlaybackSpeed(self,newVal):
        if False == Utility.IsNumeric(newVal):
            Log.getLogger().warn("Tried to set playback speed to invalid value: " + str(newVal))
            return

        if newVal > 0 and newVal < 101:
            self.PlaybackSpeed = newVal
        else:
            Log.getLogger().warn("Tried to set playback speed to invalid value: " + str(newVal))
    def OnSetPlaybackSpeed(self,speed):
        if not Utility.IsNumeric(speed):
            Log.getLogger().error("Tried to set playback speed to invalid value: " + str(speed))
            return

        if speed<=0 :
            Log.getLogger().error("Tried to set playback speed to invalid value: " + str(speed))
            return

        Playback.get().SetPlaybackSpeed(speed)
    def HandleAnyExtraStuff(self):
        try:
            if hasattr(self, "MaxCollectedValue"):
                if Utility.IsNumeric(self._LastValue):
                    if Utility.IsNumeric(self.MaxCollectedValue):
                        if float(self._LastValue) > float(self.MaxCollectedValue):
                            self.MaxCollectedValue = self._LastValue
                    else:
                        self.MaxCollectedValue = self._LastValue # last val wasn't numeric

            if hasattr(self, "MinCollectedValue"):
                if Utility.IsNumeric(self._LastValue):
                    if Utility.IsNumeric(self.MinCollectedValue):
                        if float(self._LastValue) < float(self.MaxCollectedValue):
                            self.MinCollectedValue = self._LastValue
                    else:
                        self.MinCollectedValue = self._LastValue # last val wasn't numeric

        except Exception as Ex:
            pass
Ejemplo n.º 6
0
    def PerformPlayFileTask(self, Params):
        #<?xml version="1.0" encoding="utf-8"?>
        #<Marvin Type="OscarTask">
        #    <Version>1.0</Version>
        #     <OscarID>DemoOscar</OscarID>
        #     <Task>Playback</Task>
        #     <Param>speed=2</Param>
        #</Marvin>
        #<?xml version="1.0" encoding="utf-8"?>
        #<Marvin Type="OscarTask">
        #    <Version>1.0</Version>
        #     <OscarID>DemoOscar</OscarID>
        #     <Task>Playback</Task>
        #     <Param>speed=2</Param>
        #     <Param>repeat</Param>
        #</Marvin>
        #<?xml version="1.0" encoding="utf-8"?>
        #<Marvin Type="OscarTask">
        #    <Version>1.0</Version>
        #     <OscarID>DemoOscar</OscarID>
        #     <Task>Playback</Task>
        #     <Param>loop</Param>
        #     <Param>speed=2</Param>
        #     <Param>start=10</Param>
        #     <Param>end=2400</Param>
        #</Marvin>

        speed = 1
        start = 0
        end = Playback.get().GetDataCount()
        type = Playback.RepeatMode.NONE
        file = None

        for param in Params:
            tParam = Alias.Alias(param.lower())
            if tParam == "repeat":
                type = Playback.RepeatMode.REPEAT
            elif tParam == "loop":
                type = Playback.RepeatMode.LOOP
            else:
                parts = tParam.split("=")
                if len(parts) == 2:
                    if parts[0].lower() == 'start' and Utility.IsNumeric(
                            Alias.Alias(parts[1])):
                        start = int(parts[1])
                    elif parts[0].lower() == 'end' and Utility.IsNumeric(
                            Alias.Alias(parts[1])):
                        end = int(parts[1])
                    elif parts[0].lower() == 'speed' and Utility.IsNumeric(
                            Alias.Alias(parts[1])):
                        speed = int(parts[1])
                    elif parts[0].lower() == 'file':
                        file = parts[1]
                        if False == self.PerformLoadFileTask([file]):
                            return

                        end = Playback.get().GetDataCount()

                    else:
                        Log.getLogger().info(
                            "Received unknown Oscar Play parameter: " + param)
                        return
                else:
                    Log.getLogger().info(
                        "Received unknown Oscar Play parameter: " + param)
                    return

        if Playback.get().GetDataCount() == 0:
            Log.getLogger().info("Oscar Play received - but no file loaded.")
            return

        if start >= end:
            Log.getLogger().info("Oscar Play Loop  - but start > end.")
            return

        Log.getLogger().info("Performing Oscar task: Start Playback.")
        GuiMgr.OnStopRecording(True)  #drop all recorded packets
        GuiMgr.OnStopLiveData()

        GuiMgr.OnSetPlaybackSpeed(speed)
        GuiMgr.OnSetRepeatMode(type, start, end)
        GuiMgr.OnStartPlayback()