def createBid(self, bidId, strProv, serviceId, period, unitary_cost, unitary_profit, capacity, parent_bid_Id ):
     bid = Bid()
     bid.setValues(bidId, strProv, serviceId)
     bid.setStatus(Bid.ACTIVE)
     bid.setUnitaryProfit(unitary_profit)
     bid.setUnitaryCost(unitary_cost)
     bid.setCreationPeriod(period)
     bid.setCapacity(capacity)
     bid.insertParentBid(parent_bid_Id)
     return bid        
示例#2
0
    def handleCompetitorBids(self, period, competitorsXmlNode):
        bids = competitorsXmlNode.getElementsByTagName("Bid")
        try:
            agent_type = self._list_args['Type']
            if ( agent_type.getType() == AgentType.PRESENTER_TYPE):
                logger.debug('Handle competitor bids')
                self._list_args['Current_Bids'] = {}  
                logger.debug('clear Handle competitor bids')
                
            for bid in bids:
                logger.debug('We are inside the bid loop')
                competitor_bid = Bid()
                competitor_bid.setFromXmlNode(bid)                
                if (competitor_bid.getProvider() != self._list_args['strId']):
                    if (competitor_bid.getService() == (self._list_args['serviceId'])):                        
                        if (competitor_bid.getId() in self._list_args['Related_Bids']):
                            # The bid must be replaced as the provider update it.
                            oldCompetitorBid = (self._list_args['Related_Bids'])[competitor_bid.getId()]
                            competitor_bid.setCreationPeriod(oldCompetitorBid.getCreationPeriod())  
                            (self._list_args['Related_Bids'])[competitor_bid.getId()] = competitor_bid
                        else:
                            if (competitor_bid.isActive() == True):
                                competitor_bid.setCreationPeriod(period)

                            # Replace the parent bid, looking for the actual one already in the dictionary 
                            if (competitor_bid.getParentBid() != None):
                                parentBidId = competitor_bid.getParentBid().getId() 
                                if parentBidId not in self._list_args['Related_Bids']:
                                    logger.error('Parent BidId %s not found in related bids', parentBidId)
                                else:
                                    parentBid = (self._list_args['Related_Bids'])[parentBidId]
                                    competitor_bid.insertParentBid(parentBid)
                                
                            #logger.debug('Inserting competitor bid:' + competitor_bid.__str__())
                            (self._list_args['Related_Bids'])[competitor_bid.getId()] = competitor_bid
                        
                        # Inserts on exchanged bids
                        if (agent_type.getType() == AgentType.PRESENTER_TYPE):
                            (self._list_args['Current_Bids'])[competitor_bid.getId()] = competitor_bid
                                    
            if (agent_type.getType() == AgentType.PRESENTER_TYPE):
                logger.debug('End Handle competitor bids - num exchanged:' + str(len(self._list_args['Current_Bids'])))
            logger.debug('clear 3 Handle competitor bids')
            logger.debug('Ending handled bid competitors for agent is:' + str(self._list_args['Id']))
            
        except Exception as e:
            raise FoundationException(str(e))