<commit_before>
import logging

import sys
from ..templates import prepare_service_stage
from ..utils import calculate_hash
from ..utils import (
    get_tender_data,
    get_latest_bid_for_bidder,
    patch_tender_data
)
from ..systemd_msgs_ids import(
    AUCTION_WORKER_API_AUCTION_CANCEL,
    AUCTION_WORKER_API_AUCTION_NOT_EXIST,
    AUCTION_WORKER_SERVICE_NUMBER_OF_BIDS,
    AUCTION_WORKER_API_APPROVED_DATA,
    AUCTION_WORKER_SET_AUCTION_URLS
)
from barbecue import calculate_coeficient

MULTILINGUAL_FIELDS = ["title", "description"]
ADDITIONAL_LANGUAGES = ["ru", "en"]
ROUNDS = 3
logger = logging.getLogger('Auction Worker')


def get_auction_info(self, prepare=False):
    if not self.debug:
        if prepare:
            self._auction_data = get_tender_data(
                self.tender_url,
                request_id=self.request_id,
                session=self.session
            )
        else:
            self._auction_data = {'data': {}}
        auction_data = get_tender_data(
            self.tender_url + '/auction',
            user=self.worker_defaults["TENDERS_API_TOKEN"],
            request_id=self.request_id,
            session=self.session
        )
        if auction_data:
            self._auction_data['data'].update(auction_data['data'])
            self.startDate = self.convert_datetime(self._auction_data['data']['auctionPeriod']['startDate'])
            del auction_data
        else:
            self.get_auction_document()
            if self.auction_document:
                self.auction_document["current_stage"] = -100
                self.save_auction_document()
                logger.warning("Cancel auction: {}".format(
                    self.auction_doc_id
                ), extra={"JOURNAL_REQUEST_ID": self.request_id,
                          "MESSAGE_ID": AUCTION_WORKER_API_AUCTION_CANCEL})
            else:
                logger.error("Auction {} not exists".format(
                    self.auction_doc_id
                ), extra={"JOURNAL_REQUEST_ID": self.request_id,
                          "MESSAGE_ID": AUCTION_WORKER_API_AUCTION_NOT_EXIST})
            self._end_auction_event.set()
            sys.exit(1)
    self.bidders_count = len(self._auction_data["data"]["bids"])
    logger.info("Bidders count: {}".format(self.bidders_count),
                extra={"JOURNAL_REQUEST_ID": self.request_id,
                       "MESSAGE_ID": AUCTION_WORKER_SERVICE_NUMBER_OF_BIDS})
    self.rounds_stages = []
    for stage in range((self.bidders_count + 1) * ROUNDS + 1):
        if (stage + self.bidders_count) % (self.bidders_count + 1) == 0:
            self.rounds_stages.append(stage)
    self.bidders = [bid["id"]
                    for bid in self._auction_data["data"]["bids"]
                    if bid.get('status', 'active') == 'active']
    self.mapping = {}
    self.startDate = self.convert_datetime(
        self._auction_data['data']['auctionPeriod']['startDate']
    )
    if "features" in self._auction_data["data"]:
        self.features = self._auction_data["data"]["features"]

    if not prepare:
        self.bidders_data = []
        if self.features:
            self.bidders_features = {}<commit_msg>Fixed bid count calculation<commit_after>
import logging

import sys
from ..templates import prepare_service_stage
from ..utils import calculate_hash
from ..utils import (
    get_tender_data,
    get_latest_bid_for_bidder,
    patch_tender_data
)
from ..systemd_msgs_ids import(
    AUCTION_WORKER_API_AUCTION_CANCEL,
    AUCTION_WORKER_API_AUCTION_NOT_EXIST,
    AUCTION_WORKER_SERVICE_NUMBER_OF_BIDS,
    AUCTION_WORKER_API_APPROVED_DATA,
    AUCTION_WORKER_SET_AUCTION_URLS
)
from barbecue import calculate_coeficient

MULTILINGUAL_FIELDS = ["title", "description"]
ADDITIONAL_LANGUAGES = ["ru", "en"]
ROUNDS = 3
logger = logging.getLogger('Auction Worker')


def get_auction_info(self, prepare=False):
    if not self.debug:
        if prepare:
            self._auction_data = get_tender_data(
                self.tender_url,
                request_id=self.request_id,
                session=self.session
            )
        else:
            self._auction_data = {'data': {}}
        auction_data = get_tender_data(
            self.tender_url + '/auction',
            user=self.worker_defaults["TENDERS_API_TOKEN"],
            request_id=self.request_id,
            session=self.session
        )
        if auction_data:
            self._auction_data['data'].update(auction_data['data'])
            self.startDate = self.convert_datetime(self._auction_data['data']['auctionPeriod']['startDate'])
            del auction_data
        else:
            self.get_auction_document()
            if self.auction_document:
                self.auction_document["current_stage"] = -100
                self.save_auction_document()
                logger.warning("Cancel auction: {}".format(
                    self.auction_doc_id
                ), extra={"JOURNAL_REQUEST_ID": self.request_id,
                          "MESSAGE_ID": AUCTION_WORKER_API_AUCTION_CANCEL})
            else:
                logger.error("Auction {} not exists".format(
                    self.auction_doc_id
                ), extra={"JOURNAL_REQUEST_ID": self.request_id,
                          "MESSAGE_ID": AUCTION_WORKER_API_AUCTION_NOT_EXIST})
            self._end_auction_event.set()
            sys.exit(1)
    self.bidders = [bid["id"]
                    for bid in self._auction_data["data"]["bids"]
                    if bid.get('status', 'active') == 'active']
    self.bidders_count = len(self.bidders)
    logger.info("Bidders count: {}".format(self.bidders_count),
                extra={"JOURNAL_REQUEST_ID": self.request_id,
                       "MESSAGE_ID": AUCTION_WORKER_SERVICE_NUMBER_OF_BIDS})
    self.rounds_stages = []
    for stage in range((self.bidders_count + 1) * ROUNDS + 1):
        if (stage + self.bidders_count) % (self.bidders_count + 1) == 0:
            self.rounds_stages.append(stage)
    self.mapping = {}
    self.startDate = self.convert_datetime(
        self._auction_data['data']['auctionPeriod']['startDate']
    )
    if "features" in self._auction_data["data"]:
        self.features = self._auction_data["data"]["features"]

    if not prepare:
        self.bidders_data = []
        if self.features:
            self.bidders_features = {}
{'fraction_non_alphanumeric': 0.10603690960275258, 'fraction_numerical': 0.0028151391929934315, 'mean_word_length': 2.3871822033898304, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2887372', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1985, 'n_words': 301}