Exemple #1
0
    def getPeriodsBetween(self, startTime, endTime):
        """
        Return the periods that includes two timestamps
        :param startTime: start time stamp in UTC
        :param endTime: end time stamp in UTC
        :return: list on periods as (start, end)
        """
        periods = []
        startDateTime = time_utils.getDateTimeInUTC(startTime)
        startTimeDayStart, _ = time_utils.getDayTimeBoundsForUTC(startTime)
        weekDay = startDateTime.isoweekday()
        while startTimeDayStart <= endTime:
            if weekDay in self.__periods:
                for (startH, startM), (endH, endM) in self.__periods[weekDay]:
                    periodStartTime = startTimeDayStart + startH * time_utils.ONE_HOUR + startM * time_utils.ONE_MINUTE
                    periodEndTime = startTimeDayStart + endH * time_utils.ONE_HOUR + endM * time_utils.ONE_MINUTE
                    if startTime < periodEndTime and periodStartTime <= endTime:
                        periods.append((max(startTime, periodStartTime), min(endTime, periodEndTime)))

            if weekDay == time_utils.WEEK_END:
                weekDay = time_utils.WEEK_START
            else:
                weekDay += 1
            startTimeDayStart += time_utils.ONE_DAY

        return collapseIntervals(periods)
    def getPrimeTimes(self):
        if not self.hasAnySeason():
            return {}
        epicBattlesConfig = self.lobbyContext.getServerSettings().epicBattles
        primeTimes = epicBattlesConfig.season.get('primeTimes', {})
        peripheryIDs = epicBattlesConfig.peripheryIDs
        primeTimesPeriods = defaultdict(lambda: defaultdict(list))
        for primeTime in primeTimes:
            period = (primeTime['start'], primeTime['end'])
            weekdays = primeTime['weekdays']
            for pID in primeTime['peripheryIDs']:
                if pID not in peripheryIDs:
                    continue
                periphery = primeTimesPeriods[pID]
                for wDay in weekdays:
                    periphery[wDay].append(period)

        return {
            pID: PrimeTime(
                pID, {
                    wDay: collapseIntervals(periods)
                    for wDay, periods in pPeriods.iteritems()
                })
            for pID, pPeriods in primeTimesPeriods.iteritems()
        }
    def getPeriodsBetween(self, startTime, endTime, includeBeginning=True, includeEnd=True, preferPeriodBounds=False):
        periods = []
        startDateTime = time_utils.getDateTimeInUTC(startTime)
        startTimeDayStart, _ = time_utils.getDayTimeBoundsForUTC(startTime)
        weekDay = startDateTime.isoweekday()
        while startTimeDayStart <= endTime:
            if weekDay in self.__periods:
                for (startH, startM), (endH, endM) in self.__periods[weekDay]:
                    periodStartTime = startTimeDayStart + startH * time_utils.ONE_HOUR + startM * time_utils.ONE_MINUTE
                    periodEndTime = startTimeDayStart + endH * time_utils.ONE_HOUR + endM * time_utils.ONE_MINUTE
                    if startTime < periodEndTime and periodStartTime <= endTime:
                        if not includeBeginning and startTime > periodStartTime:
                            continue
                        if not includeEnd and endTime < periodEndTime:
                            continue
                        if preferPeriodBounds:
                            periods.append((periodStartTime, periodEndTime))
                        else:
                            periods.append((max(startTime, periodStartTime), min(endTime, periodEndTime)))

            if weekDay == time_utils.WEEK_END:
                weekDay = time_utils.WEEK_START
            else:
                weekDay += 1
            startTimeDayStart += time_utils.ONE_DAY

        return collapseIntervals(periods)
Exemple #4
0
    def getPrimeTimes(self):
        """
        Gets dict with all available peripheries and prime times set for them.
        """
        lobbyContext = dependency.instance(ILobbyContext)
        rankedBattlesConfig = lobbyContext.getServerSettings().rankedBattles
        primeTimes = rankedBattlesConfig.primeTimes
        peripheryIDs = rankedBattlesConfig.peripheryIDs
        primeTimesPeriods = defaultdict(lambda: defaultdict(list))
        for primeTime in primeTimes.itervalues():
            period = (primeTime['start'], primeTime['end'])
            weekdays = primeTime['weekdays']
            for pID in primeTime['peripheryIDs']:
                if pID not in peripheryIDs:
                    continue
                periphery = primeTimesPeriods[pID]
                for wDay in weekdays:
                    periphery[wDay].append(period)

        return {
            pID: PrimeTime(
                pID, {
                    wDay: collapseIntervals(periods)
                    for wDay, periods in pPeriods.iteritems()
                })
            for pID, pPeriods in primeTimesPeriods.iteritems()
        }
    def getPrimeTimes(self):
        gameModeSettings = self.__settingsProvider()
        primeTimes = gameModeSettings.primeTimes
        peripheryIDs = gameModeSettings.peripheryIDs
        primeTimesPeriods = defaultdict(lambda: defaultdict(list))
        for primeTime in self.__getPrimeTimesIter(primeTimes):
            period = (primeTime['start'], primeTime['end'])
            weekdays = primeTime['weekdays']
            for pID in primeTime['peripheryIDs']:
                if pID not in peripheryIDs:
                    continue
                periphery = primeTimesPeriods[pID]
                for wDay in weekdays:
                    periphery[wDay].append(period)

        return {
            pID: PrimeTime(
                pID, {
                    wDay: collapseIntervals(periods)
                    for wDay, periods in pPeriods.iteritems()
                })
            for pID, pPeriods in primeTimesPeriods.iteritems()
        }