Beispiel #1
0
    def end_sealedbid(self, stage):
        def get_amount(bid):
            return bid['amount']
        with utils.update_auction_document(self):

            self._end_sealedbid.set()
            while not self.bids_queue.empty():
                LOGGER.info(
                    "Waiting for bids to process"
                )
                sleep(0.1)
            LOGGER.info("Done processing bids queue")
            self.auction_document['results'] = utils.prepare_auction_results(self, self._bids_data)
            if len([bid for bid in self.auction_document['results'] if str(bid['amount']) != '-1']) < 2:
                LOGGER.info("No bids on sealedbid phase. End auction now!")
                self.end_auction()
                return
            # find sealedbid winner in auction_document
            max_bid = max(self.auction_document['results'], key=get_amount)
            LOGGER.info("Approved sealedbid winner {bidder_id} with amount {amount}".format(
                **max_bid
                ))
            if not max_bid.get('dutch_winner', False):
                max_bid['sealedbid_winner'] = True
            self.auction_document['stages'][self.auction_document['current_stage']].update(
                max_bid
            )
            self.approve_audit_info_on_sealedbid(utils.update_stage(self))
            self.auction_document['current_phase'] = PREBESTBID
Beispiel #2
0
    def end_sealedbid(self, stage):
        with utils.update_auction_document(self):

            self._end_sealedbid.set()
            while not self.bids_queue.empty():
                LOGGER.info("Waiting for bids to process")
                sleep(0.1)
            LOGGER.info("Done processing bids queue")
            if len(self._bids_data.keys()) < 2:
                LOGGER.info("No bids on sealedbid phase. end auction")
                self.end_auction()
                return

            all_bids = deepcopy(self._bids_data)
            minimal_bids = []
            max_bid = {'amount': 0}  # init sealedbid winner bid
            for bid_id in all_bids.keys():
                bid = get_latest_bid_for_bidder(all_bids[bid_id], bid_id)
                bid['bidder_name'] = self.mapping[bid['bidder_id']]
                minimal_bids.append(utils.prepare_results_stage(**bid))
                # find a winner
                max_bid = max([max_bid, bid], key=lambda bid: bid['amount'])
            minimal_bids = sorting_by_amount(minimal_bids)
            self.auction_document['results'] = minimal_bids
            # save winner to stages in auction_document
            max_bid['sealedbid_winner'] = True
            self.auction_document['stages'][
                self.auction_document['current_stage']].update(
                    utils.prepare_results_stage(**max_bid))
            run_time = utils.update_stage(self)
            self.approve_audit_info_on_sealedbid(run_time)
            self.auction_document['current_phase'] = PREBESTBID
Beispiel #3
0
    def next_stage(self, stage):

        with utils.lock_bids(self), utils.update_auction_document(self):
            run_time = utils.update_stage(self)
            stage_index = self.auction_document['current_stage']
            self.auction_document['stages'][stage_index - 1].update({
                'passed': True
            })

            if stage['type'].startswith(DUTCH):
                LOGGER.info(
                    '---------------- SWITCH DUTCH VALUE ----------------'
                )
                self.auction_document['stages'][stage_index]['time']\
                    = run_time
                if stage_index == 1:
                    self.auction_document['current_phase'] = DUTCH
                    self.audit['timeline'][DUTCH]['timeline']['start']\
                        = run_time

                old = self.auction_document['stages'][stage_index - 1].get(
                    'amount', ''
                ) or self.auction_document['initial_value']

                LOGGER.info('Switched dutch phase value from {} to {}'.format(
                    old, stage['amount'])
                )
                turn = 'turn_{}'.format(stage_index)
                self.audit['timeline'][DUTCH][turn] = {
                    'amount': stage['amount'],
                    'time': run_time,
                }

            else:
                self.end_dutch()
Beispiel #4
0
 def switch_to_sealedbid(self, stage):
     with utils.lock_bids(self), utils.update_auction_document(self):
         self._end_sealedbid = Event()
         run_time = utils.update_stage(self)
         self.auction_document['current_phase'] = SEALEDBID
         self.audit['timeline'][SEALEDBID]['timeline']['start'] =\
             run_time
         spawn(self.add_bid)
         LOGGER.info("Swithed auction to {} phase".format(SEALEDBID))
 def end_bestbid(self, stage):
     with simple.update_auction_document(self):
         run_time = simple.update_stage(self)
         self.auction_document['current_phase'] = END
         all_bids = deepcopy(self._bids_data)
         self.auction_document['results'] = sorting_by_amount(
             all_bids.values())
         if not self.debug:
             # TODO: post results data
             pass
         self.approve_audit_info_on_bestbid(run_time)
     self.end_auction()
 def end_sealedbid(self, stage):
     with simple.update_auction_document(self):
         run_time = simple.update_stage(self)
         self._end_sealedbid.set()
         while not self.bids_queue.empty():
             LOGGER.info("Waiting for bids to process")
             sleep(0.1)
         LOGGER.info("Done processing bids queue")
         self.auction_document['current_phase'] = PREBESTBID
         all_bids = deepcopy(self._bids_data)
         self.auction_document['results'] = sorting_by_amount(
             all_bids.values())
         self.approve_audit_info_on_sealedbid(run_time)
Beispiel #7
0
    def end_bestbid(self, stage):
        with utils.update_auction_document(self):

            all_bids = deepcopy(self._bids_data)
            minimal_bids = []

            for bid_id in all_bids.keys():
                bid = get_latest_bid_for_bidder(all_bids[bid_id], bid_id)
                bid['bidder_name'] = self.mapping[bid['bidder_id']]
                minimal_bids.append(utils.prepare_results_stage(**bid))
            minimal_bids = sorting_by_amount(minimal_bids)

            self.auction_document['results'] = minimal_bids
            run_time = utils.update_stage(self)
            self.approve_audit_info_on_bestbid(run_time)
        self.end_auction()
Beispiel #8
0
 def end_bestbid(self, stage):
     with utils.update_auction_document(self):
         self.auction_document['results'] = utils.prepare_auction_results(self, self._bids_data)
         self.approve_audit_info_on_bestbid(utils.update_stage(self))
     self.end_auction()
Beispiel #9
0
 def switch_to_bestbid(self, stage):
     with utils.lock_bids(self), utils.update_auction_document(self):
         self.auction_document['current_phase'] = BESTBID
         self.audit['timeline'][BESTBID]['timeline']['start'] = utils.update_stage(self)
 def switch_to_bestbid(self, stage):
     with simple.lock_bids(self), simple.update_auction_document(self):
         run_time = simple.update_stage(self)
         self.auction_document['current_phase'] = BESTBID
         self.audit['timeline'][BESTBID]['timeline']['start'] = run_time