def parse_allocation(self, object_key: IpapObjectKey, templates: list, data_records: list,
                         ipap_template_container: IpapTemplateContainer) -> Allocation:
        """
        Parse an allocation object from the ipap_message

        :param object_key: object key for the allocation that is going to be parsed.
        :param templates: templates for the allocation
        :param data_records: records for the allocation
        :param ipap_template_container: template container where we have to include the templates.
        :return: allocation object parsed.
        """
        nbr_data_read = 0
        nbr_option_read = 0
        bidding_object_key = None
        allocation_key = None
        auction_key = None
        status = None
        data_misc = {}

        data_template, opts_template = self.insert_auction_templates(object_key.get_object_type(),
                                                                     templates, ipap_template_container)

        opts = []
        # Read data records
        for data_record in data_records:
            template_id = data_record.get_template_id()
            # Read a data record for a data template
            if template_id == data_template.get_template_id():
                data_misc = self.read_record(data_template, data_record)
                bidding_object_key = self.extract_param(data_misc, 'biddingobjectid').value
                auction_key = self.extract_param(data_misc, 'auctionid').value
                allocation_key = self.extract_param(data_misc, 'allocationid').value
                status = self.extract_param(data_misc, 'status').value
                nbr_data_read = nbr_data_read + 1

            if template_id == opts_template.get_template_id():
                opts_misc = self.read_record(opts_template, data_record)
                opts.append(opts_misc)
                nbr_option_read = nbr_option_read + 1

        if nbr_data_read == 0:
            raise ValueError("A data template was not given")

        if nbr_option_read == 0:
            raise ValueError("An option template was not given")

        intervals = self.convert_options_interval(opts)

        allocation = Allocation(auction_key, bidding_object_key, allocation_key, data_misc, intervals)
        allocation.set_state(AuctioningObjectState(ParseFormats.parse_int(status.value)))

        return allocation
Exemplo n.º 2
0
    def __init__(self, config_file_name: str):
        self._pending_tasks_by_auction = {}

        self.config = Config(config_file_name).get_config()

        # Start Listening the web server application
        loop = asyncio.get_event_loop()
        self.app = Application(loop=loop)

        # Gets the log file
        log_file_name = self.config['DefaultLogFile']
        self.logger = log(log_file_name).get_logger()

        self.domain = ParseFormats.parse_int(Config().get_config_param(
            'Main', 'Domain'))
        self.immediate_start = ParseFormats.parse_bool(
            Config().get_config_param('Main', 'ImmediateStart'))

        self._load_main_data()
        self._load_control_data()
Exemplo n.º 3
0
    def parse_auction(self, object_key: IpapObjectKey, templates: list, data_records: list,
                      ipap_template_container: IpapTemplateContainer) -> Auction:
        """
        Parse an auction from the ipap_message

        :param templates: templates for the auction
        :param data_records: records for the auction
        :param ipap_template_container: template container where we have to include the templates.
        :return: auction parsed.
        """
        nbr_data_read = 0
        nbr_option_read = 0
        auction_key = None
        auction_status = None
        resource_key = None
        template_list = None
        action_name = None
        data_misc = {}
        opts_misc = {}

        data_template, opts_template = self.insert_auction_templates(object_key.get_object_type(),
                                                                     templates, ipap_template_container)
        # Read data records
        for data_record in data_records:
            template_id = data_record.get_template_id()
            # Read a data record for a data template
            if template_id == data_template.get_template_id():
                data_misc = self.read_record(data_template, data_record)
                auction_key = self.extract_param(data_misc, 'auctionid')
                auction_status = self.extract_param(data_misc, 'status')
                resource_key = self.extract_param(data_misc, 'resourceid')
                template_list = self.extract_param(data_misc, 'templatelist')
                nbr_data_read = nbr_data_read + 1

            if template_id == opts_template.get_template_id():
                opts_misc = self.read_record(opts_template, data_record)
                action_name = self.extract_param(opts_misc, 'algoritmname')
                nbr_option_read = nbr_option_read + 1

        if nbr_data_read > 1:
            raise ValueError("The message included more than one data template")

        if nbr_data_read == 0:
            raise ValueError("The message not included  a data template")

        if nbr_option_read > 1:
            raise ValueError("The message included more than one options template")

        if nbr_option_read == 0:
            raise ValueError("The message not included  a options template")

        action = Action(action_name.value, True, opts_misc)
        auction = Auction(auction_key.value, resource_key.value, action, data_misc)
        auction.set_state(AuctioningObjectState(ParseFormats.parse_int(auction_status.value)))

        template_ids = template_list.value.split(',')
        for template_sid in template_ids:
            template = ipap_template_container.get_template(ParseFormats.parse_int(template_sid))
            auction.set_bidding_object_template(template.get_object_type(template.get_type()),
                                                template.get_type(), template.get_template_id())

        return auction
    def parse_bidding_object(
            self, object_key: IpapObjectKey, templates: list,
            data_records: list,
            ipap_template_container: IpapTemplateContainer) -> BiddingObject:
        """
        Parse a bidding object from the ipap_message

        :param templates: templates for the auction
        :param data_records: records for the auction
        :param ipap_template_container: template container where we have to include the templates.
        :return: bidding object parsed.
        """
        nbr_data_read = 0
        nbr_option_read = 0
        bidding_object_key = None
        auction_key = None
        s_bidding_object_type = None
        status = None

        data_template, opts_template = self.insert_auction_templates(
            object_key.get_object_type(), templates, ipap_template_container)

        # Read data records
        elements = {}
        for data_record in data_records:
            template_id = data_record.get_template_id()
            # Read a data record for a data template
            if template_id == data_template.get_template_id():
                data_misc = self.read_record(data_template, data_record)
                record_id = self.extract_param(data_misc, 'recordid').value
                elements[record_id] = data_misc
                # all records have the following same information.
                bidding_object_key_tmp = self.extract_param(
                    data_misc, 'biddingobjectid').value
                auction_key_tmp = self.extract_param(data_misc,
                                                     'auctionid').value
                auction_key, bidding_object_key = self.check_same_bidding_object(
                    auction_key, bidding_object_key, auction_key_tmp,
                    bidding_object_key_tmp)
                s_bidding_object_type = self.extract_param(
                    data_misc, 'biddingobjecttype').value
                status = self.extract_param(data_misc, 'status').value
                # a new record was read
                nbr_data_read = nbr_data_read + 1

            options = {}
            if template_id == opts_template.get_template_id():
                opts_misc = self.read_record(opts_template, data_record)
                record_id = self.extract_param(opts_misc, 'recordid').value
                auction_key_tmp = self.extract_param(opts_misc,
                                                     'auctionid').value
                bidding_object_key_tmp = self.extract_param(
                    opts_misc, 'biddingobjectid').value
                auction_key, bidding_object_key = self.check_same_bidding_object(
                    auction_key, bidding_object_key, auction_key_tmp,
                    bidding_object_key_tmp)

                options[record_id] = opts_misc
                # a new record was read
                nbr_option_read = nbr_option_read + 1

        if nbr_data_read == 0:
            raise ValueError("A data template was not given")

        if nbr_option_read == 0:
            raise ValueError("An option template was not given")

        bidding_object_type = self.get_auctioning_object_type(
            self.parse_type(s_bidding_object_type))
        bidding_object = BiddingObject(auction_key, bidding_object_key,
                                       bidding_object_type, elements, options)
        status_val = ParseFormats.parse_int(status)
        bidding_object.set_state(AuctioningObjectState(status_val))

        return bidding_object