def _getAllVisibleDiscounts(cls, actions, entities, announced):
        composer = ActionComposer()
        visibleCards = {_VISIBLE_CARDS.ACTIONS: [],
         _VISIBLE_CARDS.ANNOUNCED: []}
        if actions:
            affectedActions = set()
            actionEntities = entities.get('actionEntities', None)
            actionNames = entities.get('actions', None)
            actionSteps = entities.get('steps', None)
            if actionEntities and actionNames and actionSteps:
                for name, step, _ in actionEntities.values():
                    affectedActions.add((actionNames[name], actionSteps[step]))

            for action in actions:
                for actionInfo in getActionInfoData(action):
                    if actionInfo.visualPriority not in _ACTIONS_PRIORITY_LEVEL.ALL_VISIBLE:
                        continue
                    aiName = actionInfo.event.getID()
                    aiStep = actionInfo.discount.getName()
                    if not actionInfo.isDiscountVisible():
                        continue
                    if aiStep in _INTERSECTED_ACTIONS_LIST:
                        if (aiName, aiStep) in affectedActions:
                            composer.add(actionInfo)
                    composer.add(actionInfo)

        visibleCards[_VISIBLE_CARDS.ACTIONS] = composer.getActions()
        for announce in announced:
            infoList = getAnnouncedActionInfo(announce)
            if infoList:
                visibleCards[_VISIBLE_CARDS.ANNOUNCED].append(infoList)

        return visibleCards
    def getAllVisibleDiscounts(cls,
                               actions,
                               entities,
                               announced,
                               sorting=False):
        composer = ActionComposer()
        visibleCards = {
            _VISIBLE_CARDS.ACTIONS: [],
            _VISIBLE_CARDS.ANNOUNCED: []
        }
        if actions:
            for actionsInfo in getAllActionsInfoIterator(actions, entities):
                composer.add(actionsInfo)

        visibleCards[_VISIBLE_CARDS.ACTIONS] = composer.getActions()
        for announce in announced:
            infoList = getAnnouncedActionInfo(announce)
            if infoList:
                visibleCards[_VISIBLE_CARDS.ANNOUNCED].append(infoList)

        if sorting:
            visibleCards[_VISIBLE_CARDS.ACTIONS] = sorted(
                visibleCards[_VISIBLE_CARDS.ACTIONS],
                key=methodcaller('getFinishTime'))
            visibleCards[_VISIBLE_CARDS.ANNOUNCED] = sorted(
                visibleCards[_VISIBLE_CARDS.ANNOUNCED],
                key=methodcaller('getStartTime'))
        return visibleCards
Exemplo n.º 3
0
    def getAllVisibleDiscounts(cls, actions, entities, announced):
        """
        :param actions: actions list from server
        :param entities: dict
            {'actionsEntities': (index from 'actions', index from 'step', intersected actions (bool)),
             'actions': (list of active actions),
             'steps': (list of active steps),
            }
        :param announced: future actions
        :return: dict of actions for view
        """
        visibleCards = {
            _VISIBLE_CARDS.ACTIONS: [],
            _VISIBLE_CARDS.ANNOUNCED: []
        }
        composer = ActionComposer()
        if actions:
            affectedActions = set()
            actionEntities = entities.get('actionEntities', None)
            actionNames = entities.get('actions', None)
            actionSteps = entities.get('steps', None)
            if actionEntities and actionNames and actionSteps:
                for name, step, _ in actionEntities.values():
                    affectedActions.add((actionNames[name], actionSteps[step]))

            for action in actions:
                for actionInfo in getActionInfoData(action):
                    if actionInfo.visualPriority not in _ACTIONS_PRIORITY_LEVEL.ALL_VISIBLE:
                        continue
                    aiName = actionInfo.event.getID()
                    aiStep = actionInfo.discount.getName()
                    if not actionInfo.isDiscountVisible():
                        continue
                    if aiStep in _INTERSECTED_ACTIONS_LIST:
                        if (aiName, aiStep) in affectedActions:
                            composer.add(actionInfo)
                    else:
                        composer.add(actionInfo)

        for announce in announced:
            infoList = getAnnouncedActionInfo(announce)
            if infoList:
                visibleCards[_VISIBLE_CARDS.ANNOUNCED].append(infoList)

        visibleCards[_VISIBLE_CARDS.ACTIONS] = sorted(
            composer.getActions(), key=methodcaller('getFinishTime'))
        visibleCards[_VISIBLE_CARDS.ANNOUNCED] = sorted(
            visibleCards[_VISIBLE_CARDS.ANNOUNCED],
            key=methodcaller('getStartTime'))
        return visibleCards