コード例 #1
0
    def CalculateDOM(self, value):
        """
        This method calculates the degree of membership for a particular value
        :param value:
        :return:
        """

        # Test for the case where the left or right offsets are zero
        # (to prevent divide by zero errors below)
        if (Utils.IsEqual(self._rightOffset, 0.0) and (Utils.IsEqual(self._peakPoint, value))) or \
                (Utils.IsEqual(self._leftOffset, 0.0) and (Utils.IsEqual(self._peakPoint, value))):
            return 1.0

        # Find DOM if left of center
        elif (value <= self._peakPoint) and (value > (self._peakPoint - self._leftOffset)):
            grad = 1.0 / self._leftOffset
            return grad * (value - (self._peakPoint - self._leftOffset))

        # Find DOM if right of center and less than center + right offset
        elif (value > self._peakPoint) and (value <= self._peakPoint + self._rightOffset):
            return 1.0

        # out of range of this FLV, return zero
        else:
            return 0.0
コード例 #2
0
 def ToJson(self):
     return json.dumps({
         'Name': self.Name,
         'StateClassName': self.StateClassName,
         'StartTime': Utils.TimeToString(self.StartTime),
         'EndTime': Utils.TimeToString(self.EndTime),
     })
コード例 #3
0
    def test_SpecifyThatUtilsCanSleepForGivenLengthOfTime(
            self, patched_time_sleep):

        # execute
        Utils.SleepFor(3, 'seconds')

        # verify
        self.assertEqual(1, patched_time_sleep.call_count)
        patched_time_sleep.assert_called_with(3)
コード例 #4
0
ファイル: EntityEngine.py プロジェクト: SergeKrstic/show-case
    def _processRequest(self, transaction):
        transactionData = transaction.to_dict()
        actionName = transactionData['body']['queryResult'].get('action')
        actionData = self._actionMap.get(actionName)

        if actionData is not None:
            # Todo: figure out if this approach is robust (draw some flow/timing diagrams)
            _thread.start_new_thread(self._executeRequest, (actionData, transaction))
        else:
            Utils.NotifyAdminOfSystemEvent(f"Sorry something went wrong. I don't recognise this action: '{actionName}'")

        return self._createEmptyResponse()
コード例 #5
0
    def test_SpecifyThatAListOfIndicesCanBeShuffled(self):
        import random

        # setup
        random.seed(101)
        numberOfIndices = 8

        # execute
        shuffledIndices = Utils.GetShuffledIndices(numberOfIndices)

        # verify
        self.assertEqual(len(shuffledIndices), numberOfIndices,
                         "numberOfIndices")
        self.assertEqual([1, 6, 5, 0, 7, 2, 4, 3], shuffledIndices,
                         'shuffledIndices')
コード例 #6
0
 def test_SpecifyThatDateCanBeCreatedFromString(self):
     dateString = "2018-07-11"
     self.assertEqual(type(Utils.DateFromString(dateString)), datetime.date)
     self.assertEqual(Utils.DateFromString(dateString),
                      datetime.date(2018, 7, 11))
コード例 #7
0
 def IsLocalTimeWithinScheduledEvent(self, eventName, localTime):
     startTime = self.GetEvent(eventName).StartTime
     endTime = self.GetEvent(eventName).EndTime
     return Utils.IsTimeWithinSchedule(localTime, startTime, endTime)
コード例 #8
0
    def test_SpecifyThatTimeCanBeRangedChecked(self):
        # arrange
        onTimeDay = datetime.time(8, 30)  # 8:30 am
        offTimeDay = datetime.time(22, 45)  # 10:45 pm

        onTimeNight = datetime.time(22, 45)  # 10:45 pm
        offTimeNight = datetime.time(8, 30)  # 8:30 am

        # assert
        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(8, 29), onTimeDay,
                                       offTimeDay), False)
        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(8, 30), onTimeDay,
                                       offTimeDay), True)
        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(10, 00), onTimeDay,
                                       offTimeDay), True)
        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(22, 44), onTimeDay,
                                       offTimeDay), True)
        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(22, 45), onTimeDay,
                                       offTimeDay), False)

        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(22, 44), onTimeNight,
                                       offTimeNight), False)
        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(22, 45), onTimeNight,
                                       offTimeNight), True)
        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(23, 30), onTimeNight,
                                       offTimeNight), True)
        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(8, 29), onTimeNight,
                                       offTimeNight), True)
        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(8, 30), onTimeNight,
                                       offTimeNight), False)

        self.assertEqual(
            Utils.IsTimeWithinSchedule(datetime.time(8, 31), onTimeNight,
                                       onTimeNight), False)
コード例 #9
0
 def test_SpecifyThatDebugPrintCanWriteAMessageToConsole(self, print_):
     Utils.DEBUG_PRINT_ENABLED = True
     Utils.DebugPrint("Sample debug message")
     print_.assert_called_with("Sample debug message")
コード例 #10
0
 def test_SpecifyThatDebugPrintCanWriteADictionaryToConsole(self, print_):
     Utils.DEBUG_PRINT_ENABLED = True
     Utils.DebugPrint({"Message": "Sample debug message"})
     print_.assert_called_with({'Message': 'Sample debug message'})
コード例 #11
0
 def test_SpecifyThatDateCanBeConvertedToString(self):
     dateObject = datetime.datetime(2018, 7, 11).date()
     self.assertEqual(type(Utils.DateToString(dateObject)), type('string'))
     self.assertEqual(Utils.DateToString(dateObject), "2018-07-11")
コード例 #12
0
 def FromDict(data):
     return Event(name=data['Name'],
                  stateClassName=data['StateClassName'],
                  startTime=Utils.TimeFromString(data['StartTime']),
                  endTime=Utils.TimeFromString(data['EndTime']))
コード例 #13
0
    def test_SpecifyThatLengthOfTimeCanBeConvertedIntoSeconds(self):
        self.assertEqual(Utils.ConvertTimeLengthToSeconds(1, 'second'), 1)
        self.assertEqual(Utils.ConvertTimeLengthToSeconds(3, 'seconds'), 3)

        self.assertEqual(Utils.ConvertTimeLengthToSeconds(1, 'minute'), 60)
        self.assertEqual(Utils.ConvertTimeLengthToSeconds(3, 'minutes'), 180)
        self.assertEqual(Utils.ConvertTimeLengthToSeconds(3.5, 'minutes'), 210)

        self.assertEqual(Utils.ConvertTimeLengthToSeconds(1, 'hour'), 3600)
        self.assertEqual(Utils.ConvertTimeLengthToSeconds(3, 'hours'), 10800)
        self.assertEqual(Utils.ConvertTimeLengthToSeconds(3.5, 'hours'), 12600)

        self.assertEqual(Utils.ConvertTimeLengthToSeconds(1, 'day'), 86400)
        self.assertEqual(Utils.ConvertTimeLengthToSeconds(3, 'days'), 259200)
        self.assertEqual(Utils.ConvertTimeLengthToSeconds(3.5, 'days'), 302400)
コード例 #14
0
 def test_SpecifyThatDecimalValuesCanBeCompared(self):
     value = 1.23456789
     self.assertEqual(Utils.IsEqual(value, value + Utils.EPSILON / 2), True)
     self.assertEqual(Utils.IsEqual(value, value + Utils.EPSILON * 2),
                      False)
コード例 #15
0
 def test_SpecifyThatTimeCanBeAdjusted(self):
     timeObject = datetime.time(6, 15)
     self.assertEqual(str(Utils.AdjustTime(timeObject, 3, 4, 5)),
                      "09:19:05")
コード例 #16
0
 def test_SpecifyThatTimeCanBeConvertedToString(self):
     timeObject = datetime.time(6, 15)
     self.assertEqual(type(Utils.TimeToString(timeObject)), type('string'))
     self.assertEqual(Utils.TimeToString(timeObject), "06:15")
コード例 #17
0
 def test_SpecifyThatTimeCanBeCreatedFromString(self):
     timeString = "06:15"
     self.assertEqual(type(Utils.TimeFromString(timeString)), datetime.time)
     self.assertEqual(Utils.TimeFromString(timeString),
                      datetime.time(6, 15))
コード例 #18
0
 def test_SpecifyThatLocalTimeCanBeRetrieved(self):
     self.assertEqual('Tue Jun 21 10:15:30 2011', Utils.GetLocalTime())