コード例 #1
0
ファイル: MimesisEngine.py プロジェクト: lahonu/Mimesis_Tool
    def pi_push_all_records(self, n_record_limit: int) -> bool:
        """
        Called when a tool has no incoming data connection.
        :param n_record_limit: Set it to <0 for no limit, 0 for no records, and >0 to specify the number of records.
        :return: True for success, False for failure.
        """

        if not self.is_initialized:
            return False

        # Save a reference to the RecordInfo passed into this function in the global namespace, so we can access it later.
        record_info_out = Sdk.RecordInfo(self.alteryx_engine)

        # Adds the new field to the record.
        for field in self.column_name:
            self.output_field = record_info_out.add_field(field,
                                                          self.output_type,
                                                          size=self.field_size)

        # Lets the downstream tools know what the outgoing record metadata will look like, based on record_info_out.
        self.output_anchor.init(record_info_out)
        # Creating a new, empty record creator based on record_info_out's record layout.
        record_creator = record_info_out.construct_record_creator()

        #import pdb; pdb.set_trace()

        #sophs code:
        for record in range(self.record_limit):
            for field in enumerate(record_info_out):
                if field[1].name == 'number_float':
                    mimesis_object = Numbers()
                    record_value = str(
                        mimesis_object.float_number(end=10000, precision=6))
                if field[1].name == 'number_float_positive':
                    mimesis_object = Numbers()
                    record_value = str(
                        mimesis_object.float_number(start=0,
                                                    end=10000,
                                                    precision=6))
                if field[1].name == 'number_int':
                    mimesis_object = Numbers()
                    record_value = str(
                        mimesis_object.integer_number(start=-32767, end=32767))
                if field[1].name == 'number_int_positive':
                    mimesis_object = Numbers()
                    record_value = str(
                        mimesis_object.integer_number(start=0, end=32767))
                if field[1].name == 'address_street_address':
                    mimesis_object = Address(self.Locale)
                    record_value = mimesis_object.address()
                if field[1].name == 'address_coordinates':
                    mimesis_object = Address(self.Locale)
                    record_value = str(mimesis_object.coordinates())
                if field[1].name == 'address_country':
                    mimesis_object = Address(self.Locale)
                    record_value = mimesis_object.country(allow_random=True)
                if field[1].name == 'address_postal_code':
                    mimesis_object = Address(self.Locale)
                    record_value = mimesis_object.postal_code()
                if field[1].name == 'code_imei':
                    mimesis_object = Code()
                    record_value = mimesis_object.imei()
                if field[1].name == 'code_isbn':
                    mimesis_object = Code()
                    record_value = mimesis_object.isbn()
                if field[1].name == 'code_pin':
                    mimesis_object = Code()
                    record_value = mimesis_object.pin()
                if field[1].name == 'food_dish':
                    mimesis_object = Food(self.Locale)
                    record_value = mimesis_object.dish()
                if field[1].name == 'food_fruit':
                    mimesis_object = Food(self.Locale)
                    record_value = mimesis_object.fruit()
                if field[1].name == 'food_vegetables':
                    mimesis_object = Food(self.Locale)
                    record_value = mimesis_object.vegetable()
                if field[1].name == 'internet_url':
                    mimesis_object = Internet()
                    record_value = mimesis_object.home_page()
                if field[1].name == 'internet_ipv4':
                    mimesis_object = Internet()
                    record_value = mimesis_object.ip_v4()
                if field[1].name == 'internet_mac':
                    mimesis_object = Internet()
                    record_value = mimesis_object.mac_address()
                if field[1].name == 'person_blood_type':
                    mimesis_object = Person(self.Locale)
                    record_value = mimesis_object.blood_type()
                if field[1].name == 'person_email':
                    mimesis_object = Person(self.Locale)
                    record_value = mimesis_object.email()
                if field[1].name == 'person_full_name':
                    mimesis_object = Person(self.Locale)
                    record_value = mimesis_object.full_name()
                if field[1].name == 'person_nationality':
                    mimesis_object = Person(self.Locale)
                    record_value = mimesis_object.nationality()
                if field[1].name == 'person_occupation':
                    mimesis_object = Person(self.Locale)
                    record_value = mimesis_object.occupation()
                if field[1].name == 'person_telephone':
                    mimesis_object = Person(self.Locale)
                    record_value = mimesis_object.telephone()
                if field[1].name == 'science_atomic_number':
                    mimesis_object = Science(self.Locale)
                    record_value = str(mimesis_object.atomic_number())
                if field[1].name == 'science_chemical_element':
                    mimesis_object = Science(self.Locale)
                    record_value = mimesis_object.chemical_element()
                if field[1].name == 'transport_airplane':
                    mimesis_object = Transport()
                    record_value = mimesis_object.airplane()
                if field[1].name == 'transport_car':
                    mimesis_object = Transport()
                    record_value = mimesis_object.car()
                if field[1].name == 'transport_truck':
                    mimesis_object = Transport()
                    record_value = mimesis_object.truck()
                if field[1].name == 'transport_vehicle_reg_code':
                    mimesis_object = Transport()
                    record_value = mimesis_object.vehicle_registration_code()
                if field[1].name == 'business_company_name':
                    mimesis_object = Business()
                    record_value = mimesis_object.company()
                if field[1].name == 'business_company_type':
                    mimesis_object = Business()
                    record_value = mimesis_object.company_type()
                if field[1].name == 'file_filename':
                    mimesis_object = File()
                    record_value = mimesis_object.file_name()
                if field[1].name == 'file_file_extension':
                    mimesis_object = File()
                    record_value = mimesis_object.extension()
                if field[1].name == 'file_mime_type':
                    mimesis_object = File()
                    record_value = mimesis_object.mime_type()
                if field[1].name == 'file_size':
                    mimesis_object = File()
                    record_value = mimesis_object.size()
                record_info_out[field[0]].set_from_string(
                    record_creator, record_value)
            out_record = record_creator.finalize_record()
            self.output_anchor.push_record(out_record, False)
            record_creator.reset()

        # Make sure that the output anchor is closed.
        self.output_anchor.close()
        return True
コード例 #2
0
ファイル: MimesisEngine.py プロジェクト: lahonu/Mimesis_Tool
    def ii_push_record(self, in_record: object) -> bool:
        """
        Responsible for pushing records out.
        Called when an input record is being sent to the plugin.
        :param in_record: The data for the incoming record.
        :return: False if there's a downstream error, or if there's an error with the field name, otherwise True.
        """

        if not self.parent.is_initialized:
            return False

        #create the new fields
        record_value = None
        for field in enumerate(self.record_info_out):
            if field[1].name == 'number_float':
                mimesis_object = Numbers()
                record_value = str(
                    mimesis_object.float_number(end=10000, precision=6))
            if field[1].name == 'number_float_positive':
                mimesis_object = Numbers()
                record_value = str(
                    mimesis_object.float_number(start=0,
                                                end=10000,
                                                precision=6))
            if field[1].name == 'number_int':
                mimesis_object = Numbers()
                record_value = str(
                    mimesis_object.integer_number(start=-32767, end=32767))
            if field[1].name == 'number_int_positive':
                mimesis_object = Numbers()
                record_value = str(
                    mimesis_object.integer_number(start=0, end=32767))
            if field[1].name == 'address_street_address':
                mimesis_object = Address(self.Locale)
                record_value = mimesis_object.address()
            if field[1].name == 'address_coordinates':
                mimesis_object = Address(self.Locale)
                record_value = str(mimesis_object.coordinates())
            if field[1].name == 'address_country':
                mimesis_object = Address(self.Locale)
                record_value = mimesis_object.country(allow_random=True)
            if field[1].name == 'address_postal_code':
                mimesis_object = Address(self.Locale)
                record_value = mimesis_object.postal_code()
            if field[1].name == 'code_imei':
                mimesis_object = Code()
                record_value = mimesis_object.imei()
            if field[1].name == 'code_isbn':
                mimesis_object = Code()
                record_value = mimesis_object.isbn()
            if field[1].name == 'code_pin':
                mimesis_object = Code()
                record_value = mimesis_object.pin()
            if field[1].name == 'food_dish':
                mimesis_object = Food(self.Locale)
                record_value = mimesis_object.dish()
            if field[1].name == 'food_fruit':
                mimesis_object = Food(self.Locale)
                record_value = mimesis_object.fruit()
            if field[1].name == 'food_vegetables':
                mimesis_object = Food(self.Locale)
                record_value = mimesis_object.vegetable()
            if field[1].name == 'internet_url':
                mimesis_object = Internet()
                record_value = mimesis_object.home_page()
            if field[1].name == 'internet_ipv4':
                mimesis_object = Internet()
                record_value = mimesis_object.ip_v4()
            if field[1].name == 'internet_mac':
                mimesis_object = Internet()
                record_value = mimesis_object.mac_address()
            if field[1].name == 'person_blood_type':
                mimesis_object = Person(self.Locale)
                record_value = mimesis_object.blood_type()
            if field[1].name == 'person_email':
                mimesis_object = Person(self.Locale)
                record_value = mimesis_object.email()
            if field[1].name == 'person_full_name':
                mimesis_object = Person(self.Locale)
                record_value = mimesis_object.full_name()
            if field[1].name == 'person_nationality':
                mimesis_object = Person(self.Locale)
                record_value = mimesis_object.nationality()
            if field[1].name == 'person_occupation':
                mimesis_object = Person(self.Locale)
                record_value = mimesis_object.occupation()
            if field[1].name == 'person_telephone':
                mimesis_object = Person(self.Locale)
                record_value = mimesis_object.telephone()
            if field[1].name == 'science_atomic_number':
                mimesis_object = Science(self.Locale)
                record_value = str(mimesis_object.atomic_number())
            if field[1].name == 'science_chemical_element':
                mimesis_object = Science(self.Locale)
                record_value = mimesis_object.chemical_element()
            if field[1].name == 'transport_airplane':
                mimesis_object = Transport()
                record_value = mimesis_object.airplane()
            if field[1].name == 'transport_car':
                mimesis_object = Transport()
                record_value = mimesis_object.car()
            if field[1].name == 'transport_truck':
                mimesis_object = Transport()
                record_value = mimesis_object.truck()
            if field[1].name == 'transport_vehicle_reg_code':
                mimesis_object = Transport()
                record_value = mimesis_object.vehicle_registration_code()
            if field[1].name == 'business_company_name':
                mimesis_object = Business()
                record_value = mimesis_object.company()
            if field[1].name == 'business_company_type':
                mimesis_object = Business()
                record_value = mimesis_object.company_type()
            if field[1].name == 'file_filename':
                mimesis_object = File()
                record_value = mimesis_object.file_name()
            if field[1].name == 'file_file_extension':
                mimesis_object = File()
                record_value = mimesis_object.extension()
            if field[1].name == 'file_mime_type':
                mimesis_object = File()
                record_value = mimesis_object.mime_type()
            if field[1].name == 'file_size':
                mimesis_object = File()
                record_value = mimesis_object.size()
            self.record_info_out[field[0]].set_from_string(
                self.record_creator, record_value)
        out_record = self.record_creator.finalize_record()
        #self.parent.output_anchor.push_record(out_record, False)
        self.record_creator.reset()

        # Copy the data from the incoming record into the outgoing record.
        self.record_creator.reset()
        self.record_copier.done_adding()
        self.record_copier.copy(self.record_creator, in_record)

        # Push the record downstream and quit if there's a downstream error.
        if not self.parent.output_anchor.push_record(out_record):
            return False

        return True