def prepare_auction_stages(self):
        # Initital Bids
        self.auction_document[
            'auction_type'] = 'meat' if self.features else 'default'

        for bid_info in self.bidders_data:
            self.auction_document["initial_bids"].append(
                prepare_initial_bid_stage(
                    time="",
                    bidder_id=bid_info["id"],
                    bidder_name=self.mapping[bid_info["id"]],
                    amount="0",
                    yearlyPaymentsPercentage="0",
                    contractDurationYears="0",
                    contractDurationDays="0",
                    annualCostsReduction=[]))
        self.auction_document['stages'] = []
        next_stage_timedelta = self.startDate
        for round_id in xrange(ROUNDS):
            # Schedule PAUSE Stage
            pause_stage = prepare_service_stage(
                start=next_stage_timedelta.isoformat(), stage="pause")
            self.auction_document['stages'].append(pause_stage)
            if round_id == 0:
                next_stage_timedelta += timedelta(seconds=FIRST_PAUSE_SECONDS)
            else:
                next_stage_timedelta += timedelta(seconds=PAUSE_SECONDS)

            # Schedule BIDS Stages
            for index in xrange(self.bidders_count):
                bid_stage = prepare_bids_stage({
                    'start':
                    next_stage_timedelta.isoformat(),
                    'bidder_id':
                    '',
                    'bidder_name':
                    '',
                    'amount':
                    '0',
                    'contractDurationDays':
                    '0',
                    'contractDurationYears':
                    '0',
                    'yearlyPaymentsPercentage':
                    '0',
                    'time':
                    '',
                })

                self.auction_document['stages'].append(bid_stage)
                next_stage_timedelta += timedelta(seconds=BIDS_SECONDS)

        self.auction_document['stages'].append(
            prepare_service_stage(start=next_stage_timedelta.isoformat(),
                                  type="pre_announcement"))
        self.auction_document['stages'].append(
            prepare_service_stage(start="", type="announcement"))

        self.auction_document['endDate'] = next_stage_timedelta.isoformat()
def prepare_auction_document(self):
    self.auction_document.update({
        '_id':
        self.auction_doc_id,
        'stages': [],
        'tenderID':
        self._auction_data['data'].get('tenderID', ''),
        'procurementMethodType':
        self._auction_data['data'].get('procurementMethodType', ''),
        'TENDERS_API_VERSION':
        self.worker_defaults['TENDERS_API_VERSION'],
        'initial_bids': [],
        'current_stage':
        -1,
        "NBUdiscountRate":
        self._auction_data["data"].get("NBUdiscountRate"),
        'results': [],
        'minimalStep':
        self._lot_data.get('minimalStep', {}),
        'procuringEntity':
        self._auction_data['data'].get('procuringEntity', {}),
        'items':
        self._lot_data.get('items', []),
        'minValue':
        self._lot_data.get('value', {}),
        'lot': {}
    })
    self.auction_document[
        'auction_type'] = 'meat' if self.features else 'default'

    for key in MULTILINGUAL_FIELDS:
        for lang in ADDITIONAL_LANGUAGES:
            lang_key = '{}_{}'.format(key, lang)
            if lang_key in self._auction_data['data']:
                self.auction_document[lang_key] = self._auction_data['data'][
                    lang_key]
            if lang_key in self._lot_data:
                self.auction_document['lot'][lang_key] = self._lot_data[
                    lang_key]
        self.auction_document[key] = self._auction_data['data'].get(key, '')
        self.auction_document['lot'][key] = self._lot_data.get(key, '')

    self.auction_document['stages'].append(
        prepare_service_stage(start=self.startDate.isoformat(), type="pause"))
    return self.auction_document
Ejemplo n.º 3
0
def prepare_auction_document(self):
    self.auction_document.update({
        "_id":
        self.auction_doc_id,
        "stages": [],
        "tenderID":
        self._auction_data["data"].get("tenderID", ""),
        "procurementMethodType":
        self._auction_data["data"].get("procurementMethodType", "default"),
        "TENDERS_API_VERSION":
        self.worker_defaults["TENDERS_API_VERSION"],
        "initial_bids": [],
        "current_stage":
        -1,
        "results": [],
        "minimalStep":
        self._auction_data["data"].get("minimalStep", {}),
        "procuringEntity":
        self._auction_data["data"].get("procuringEntity", {}),
        "items":
        self._auction_data["data"].get("items", []),
        "minValue":
        self._auction_data["data"].get("minValue", {})
    })
    # XXX TODO Remove meat
    if self.features:
        self.auction_document["auction_type"] = "meat"
    else:
        self.auction_document["auction_type"] = "default"

    for key in MULTILINGUAL_FIELDS:
        for lang in ADDITIONAL_LANGUAGES:
            lang_key = "{}_{}".format(key, lang)
            if lang_key in self._auction_data["data"]:
                self.auction_document[lang_key] = self._auction_data["data"][
                    lang_key]
        self.auction_document[key] = self._auction_data["data"].get(key, "")

    self.auction_document['stages'].append(
        prepare_service_stage(start=self.startDate.isoformat(), type="pause"))

    return self.auction_document
Ejemplo n.º 4
0
def prepare_auction_document(self):
    self.auction_document.update(
        {"_id": self.auction_doc_id,
         "stages": [],
         "tenderID": self._auction_data["data"].get("tenderID", ""),
         "procurementMethodType": self._auction_data["data"].get("procurementMethodType", "default"),
         "TENDERS_API_VERSION": self.worker_defaults["resource_api_version"],
         "initial_bids": [],
         "current_stage": -1,
         "NBUdiscountRate": self._auction_data["data"].get("NBUdiscountRate"),
         "noticePublicationDate": self._auction_data["data"].get("noticePublicationDate"),
         "results": [],
         "minimalStepPercentage": self._auction_data["data"].get("minimalStepPercentage", {}),
         "procuringEntity": self._auction_data["data"].get("procuringEntity", {}),
         "items": self._auction_data["data"].get("items", []),
         "minValue": self._auction_data["data"].get("minValue", {}),
         "fundingKind": self._auction_data["data"].get("fundingKind", {}),
         "yearlyPaymentsPercentageRange": self._auction_data["data"].get("yearlyPaymentsPercentageRange")}
    )
    if self.features:
        self.auction_document["auction_type"] = "meat"
    else:
        self.auction_document["auction_type"] = "default"

    for key in MULTILINGUAL_FIELDS:
        for lang in ADDITIONAL_LANGUAGES:
            lang_key = "{}_{}".format(key, lang)
            if lang_key in self._auction_data["data"]:
                self.auction_document[lang_key] = self._auction_data["data"][lang_key]
        self.auction_document[key] = self._auction_data["data"].get(key, "")

    self.auction_document['stages'].append(
        prepare_service_stage(
            start=self.startDate.isoformat(),
            type="pause"
        )
    )

    return self.auction_document
def prepare_auction_document(auction, fast_forward=False):
    auction.auction_document.update({
        "_id": auction.auction_doc_id,
        "stages": [],
        "auctionID": auction._auction_data["data"].get("auctionID", ""),
        "procurementMethodType": auction._auction_data["data"].get(
            "procurementMethodType", "default"),
        "TENDERS_API_VERSION": auction.worker_defaults["resource_api_version"],
        "current_stage": -1,
        "current_phase": "",
        "results": [],
        "procuringEntity": auction._auction_data["data"].get(
            "procuringEntity", {}
        ),
        "items": auction._auction_data["data"].get("items", []),
        "value": auction._auction_data["data"].get("value", {}),
        "initial_value": auction._auction_data["data"].get(
            "value", {}
        ).get('amount'),
        "auction_type": "dutch",
    })

    for key in MULTILINGUAL_FIELDS:
        for lang in ADDITIONAL_LANGUAGES:
            lang_key = "{}_{}".format(key, lang)
            if lang_key in auction._auction_data["data"]:
                auction.auction_document[lang_key]\
                    = auction._auction_data["data"][lang_key]
        auction.auction_document[key] = auction._auction_data["data"].get(
            key, ""
        )
    if fast_forward:
        DUTCH_TIMEDELTA = timedelta(minutes=10)
        DUTCH_ROUNDS = 10
        FIRST_PAUSE = timedelta(seconds=10)
    else:
        from openprocurement.auction.insider.constants import DUTCH_TIMEDELTA,\
            DUTCH_ROUNDS, FIRST_PAUSE
    dutch_step_duration = DUTCH_TIMEDELTA / DUTCH_ROUNDS
    next_stage_timedelta = auction.startDate
    amount = auction.auction_document['value']['amount']
    auction.auction_document['stages'] = [prepare_service_stage(
        start=auction.startDate.isoformat(),
        type="pause"
    )]
    next_stage_timedelta += FIRST_PAUSE
    for index in range(DUTCH_ROUNDS + 1):
        if index == DUTCH_ROUNDS:
            stage = {
                'start': next_stage_timedelta.isoformat(),
                'type': PRESEALEDBID,
                'time': ''
            }
        else:
            stage = {
                'start': next_stage_timedelta.isoformat(),
                'amount': amount,
                'type': 'dutch_{}'.format(index),
                'time': ''
            }
        auction.auction_document['stages'].append(stage)
        amount = calculate_next_amount(
            auction.auction_document['initial_value'],
            amount
        )
        if index != DUTCH_ROUNDS:
            next_stage_timedelta += dutch_step_duration

    for delta, name in zip(
            [
                END_PHASE_PAUSE,
                SEALEDBID_TIMEDELTA,
                END_PHASE_PAUSE,
                BESTBID_TIMEDELTA,

            ],
            [
                SEALEDBID,
                PREBESTBID,
                BESTBID,
                END,
            ]):
        next_stage_timedelta += delta
        auction.auction_document['stages'].append({
            'start': next_stage_timedelta.isoformat(),
            'type': name,
            'time': ''
        })
    return auction.auction_document
Ejemplo n.º 6
0
    def prepare_auction_stages_fast_forward(self):
        self.auction_document['auction_type'] = 'meat' if self.features else 'default'
        bids = deepcopy(self.bidders_data)
        self.auction_document["initial_bids"] = []
        bids_info = sorting_start_bids_by_amount(bids, features=self.features, reverse=False)
        for index, bid in enumerate(bids_info):
            amount = bid["value"]["amountPerformance"]
            annualCostsReduction = bid["value"]["annualCostsReduction"]
            if self.features:
                amount_features = cooking(
                    amount,
                    self.features, self.bidders_features[bid["id"]],
                    reverse=True
                )
                coeficient = self.bidders_coeficient[bid["id"]]

            else:
                coeficient = None
                amount_features = None
            initial_bid_stage = prepare_initial_bid_stage(
                time=bid["date"] if "date" in bid else self.startDate,
                bidder_id=bid["id"],
                bidder_name=self.mapping[bid["id"]],
                amount=amount,
                coeficient=coeficient,
                amount_features=amount_features,
                annualCostsReduction=annualCostsReduction,
                yearlyPaymentsPercentage=bid["value"]["yearlyPaymentsPercentage"],
                contractDurationDays=bid["value"]["contractDuration"].get("days", None),
                contractDurationYears=bid["value"]["contractDuration"].get("years", None)
            )
            self.auction_document["initial_bids"].append(
                initial_bid_stage
            )
        self.auction_document['stages'] = []
        next_stage_timedelta = datetime.now(tzlocal())
        for round_id in xrange(ROUNDS):
            # Schedule PAUSE Stage
            pause_stage = prepare_service_stage(
                start=next_stage_timedelta.isoformat(),
                stage="pause"
            )
            self.auction_document['stages'].append(pause_stage)
            # Schedule BIDS Stages
            for index in xrange(self.bidders_count):
                bid_stage = prepare_bids_stage({
                    'start': next_stage_timedelta.isoformat(),
                    'bidder_id': '',
                    'bidder_name': '',
                    'amount': '0',
                    "contractDurationDays": "0",
                    "contractDurationYears": "0",
                    "yearlyPaymentsPercentage": "0",
                    'time': '',
                })
                self.auction_document['stages'].append(bid_stage)
                next_stage_timedelta += timedelta(seconds=BIDS_SECONDS)

        self.auction_document['stages'].append(
            prepare_service_stage(
                start=next_stage_timedelta.isoformat(),
                type="pre_announcement"
            )
        )
        self.auction_document['stages'].append(
            prepare_service_stage(
                start="",
                type="announcement"
            )
        )
        all_bids = deepcopy(self.auction_document["initial_bids"])
        minimal_bids = []
        for bid_info in self.bidders_data:
            minimal_bids.append(get_latest_bid_for_bidder(
                all_bids, str(bid_info['id'])
            ))

        minimal_bids = self.filter_bids_keys(sorting_by_amount(minimal_bids, reverse=False))
        self.update_future_bidding_orders(minimal_bids)

        self.auction_document['endDate'] = next_stage_timedelta.isoformat()
        self.auction_document["current_stage"] = len(self.auction_document["stages"]) - 2