def createPlayers(team): person = Person("en") adress = Address("en") players = [] MAX_N = len(team) arrOfIds = [i + 1 for i in range(MAX_N)] for i in range(MAX_N): positions = [1, 2, 3, 4, 5] numbers = [k for k in range(1, 99, 1)] curTeamID = choice(arrOfIds) arrOfIds.remove(curTeamID) for _ in range(len(positions)): curID = str(len(players) + 1) teamID = str(curTeamID) name = person.full_name() position = choice(positions) height = str(randint(150, 220)) weight = str(person.weight()) number = str(choice(numbers)) age = str(person.age()) country = adress.country(allow_random=True) positions.remove(position) numbers.remove(int(number)) players.append([curID, teamID, name, position, height, weight, number, age, country]) f = open("Players.csv", "w", encoding='utf-8') for player in players: line = str(player[0]) + ',' + str(player[1]) + ',' + str(player[2]) + ',' +\ str(player[3]) + ',' + str(player[4]) + ',' + str(player[5]) + ',' +\ str(player[6]) + ',' + str(player[7]) + ',' + str(player[8]) + '\n' f.write(line) f.close()
def address(cls, *, locale=Locales.EN, calling_code=None, city=None, country=None, country_code=None, latitude=None, longitude=None, postal_code=None, state=None, street_name=None, street_number=None, street_suffix=None): ''' Create an Address Data Entity object. All individual fields are automatically randomly generated based on locale. If provided, the corresponding values are overriden. Note: All individual fields are randomly generated. Don't expect correct correlation e.g. correct postal code for the generated city. Keyword Arguments: locale: Approprite Random.locale.<local_name> object. Default is Random.locale.EN calling_code: Calling Code city: City country: Country Name country_code: Country Code latitude: Latitude longitude: Longitde postal_code: Postal Code state: State street_name: Street Name street_number Street Number street_suffix: Street Suffix ''' address = Address(locale=locale) from arjuna.engine.data.entity.address import Address as ArjAddress return ArjAddress( calling_code=calling_code is not None and calling_code or address.calling_code(), city=city and city is not None or address.city(), country=country is not None and country or address.country(), country_code=country_code is not None and country_code or address.country_code(), latitude=latitude is not None and latitude or address.latitude(), longitude=longitude is not None and longitude or address.longitude(), postal_code=postal_code is not None and postal_code or address.postal_code(), state=state is not None and state or address.state(), street_name=street_name is not None and street_name or address.street_name(), street_number=street_number is not None and street_number or address.street_number(), street_suffix=street_suffix is not None and street_suffix or address.street_suffix(), )
def get_fake_address(self, loc): address = Address(loc) city = address.city() kind_street = address.street_suffix() street = address.street_name() house = address.street_number() area = address.state() zip = address.zip_code() country = address.country() return zip, city, kind_street, street, house, area, country
def generate_addresses(): address = Address('en-gb') city = address.city() country = address.country() postal_code = address.postal_code() street_name = address.street_name() street_number = address.street_number() return { 'id': id, "street_number": street_number, "street_name": street_name, "city": city, "postal_code": postal_code, "country": country }
def get_data(address: Address, lang: str): return { 'address': address.address(), 'calling_code': address.calling_code(), 'city': address.city(), 'continent': address.continent(), 'coordinates': address.coordinates(), 'country': address.country(), 'country_code': get_country_code(lang), 'latitude': address.latitude(), 'longitude': address.longitude(), 'postal_code': address.postal_code(), 'state': address.state(), 'street_name': address.street_name(), 'street_number': address.street_number(), 'street_suffix': address.street_suffix(), 'zip_code': address.zip_code() }
def generatingData(num, locale, country): person = Person(locale) address = Address(locale) buffer = io.StringIO() writer = csv.writer(buffer, delimiter=';', lineterminator="\n", quoting=csv.QUOTE_NONE, escapechar='\\') for i in range(int(num)): writer.writerow([ person.full_name(), country if randint(0, 1) == 1 else address.country(), ', '.join([address.province(), address.city(), address.address()]), person.telephone() ]) return buffer.getvalue()
def generatePeople(row_num: int, region: str): if region == 'en_US': locale = 'en' elif region == 'ru_RU': locale = 'ru' else: locale = 'uk' writer = csv.writer(stdout, quoting=csv.QUOTE_NONE, delimiter=';', escapechar='"') person = Person(locale) address = Address(locale) for i in range(row_num): writer.writerow([ person.full_name(), address.country(), address.region(), address.city(), address.address(), address.zip_code(), person.telephone() ])
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 == 'address_full_address': mimesis_object = Address(self.parent.Locale) record_value = mimesis_object.address() if field[1].name == 'address_coordinates': mimesis_object = Address(self.parent.Locale) record_value = str(mimesis_object.coordinates()) if field[1].name == 'address_country': mimesis_object = Address(self.parent.Locale) record_value = mimesis_object.country() if field[1].name == 'address_postal_code': mimesis_object = Address(self.parent.Locale) record_value = mimesis_object.postal_code() if field[1].name == 'code_imei': mimesis_object = Code(self.parent.Locale) record_value = mimesis_object.imei() if field[1].name == 'code_isbn': mimesis_object = Code(self.parent.Locale) record_value = mimesis_object.isbn() if field[1].name == 'code_pin': mimesis_object = Code(self.parent.Locale) record_value = mimesis_object.pin() if field[1].name == 'food_dish': mimesis_object = Food(self.parent.Locale) record_value = mimesis_object.dish() if field[1].name == 'food_fruit': mimesis_object = Food(self.parent.Locale) record_value = mimesis_object.fruit() if field[1].name == 'food_vegetables': mimesis_object = Food(self.parent.Locale) record_value = mimesis_object.vegetable() '''if field[1].name == 'game_gaming_platform': mimesis_object = Games(self.parent.Locale) record_value = mimesis_object.gaming_platform() if field[1].name == 'game_titles': mimesis_object = Games(self.parent.Locale) record_value = mimesis_object.game()''' if field[1].name == 'person_blood_type': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.blood_type() if field[1].name == 'person_email': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.email() if field[1].name == 'person_full_name': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.full_name() if field[1].name == 'person_nationality': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.nationality() if field[1].name == 'person_occupation': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.occupation() if field[1].name == 'person_telephone': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.telephone() if field[1].name == 'science_atomic_number': mimesis_object = Science(self.parent.Locale) record_value = str(mimesis_object.atomic_number()) if field[1].name == 'science_chemical_element': mimesis_object = Science(self.parent.Locale) record_value = mimesis_object.chemical_element() if field[1].name == 'transport_airplane': mimesis_object = Transport(self.parent.Locale) record_value = mimesis_object.airplane() if field[1].name == 'transport_car': mimesis_object = Transport(self.parent.Locale) record_value = mimesis_object.car() if field[1].name == 'transport_truck': mimesis_object = Transport(self.parent.Locale) record_value = mimesis_object.truck() if field[1].name == 'transport_vehicle_reg_code': mimesis_object = Transport(self.parent.Locale) record_value = mimesis_object.vehicle_registration_code() #pdb.set_trace() 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
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 == 'address_full_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() 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(self.Locale) record_value = mimesis_object.imei() if field[1].name == 'code_isbn': mimesis_object = Code(self.Locale) record_value = mimesis_object.isbn() if field[1].name == 'code_pin': mimesis_object = Code(self.Locale) 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 == 'game_gaming_platform': mimesis_object = Games(self.Locale) record_value = mimesis_object.gaming_platform() if field[1].name == 'game_titles': mimesis_object = Games(self.Locale) record_value = mimesis_object.game()''' 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(self.Locale) record_value = mimesis_object.airplane() if field[1].name == 'transport_car': mimesis_object = Transport(self.Locale) record_value = mimesis_object.car() if field[1].name == 'transport_truck': mimesis_object = Transport(self.Locale) record_value = mimesis_object.truck() if field[1].name == 'transport_vehicle_reg_code': mimesis_object = Transport(self.Locale) record_value = mimesis_object.vehicle_registration_code() 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
my_cod.code.imei() print(my_cod.code.imei()) #Генерація назв фруктів по назві f = Generic('uk') f.food.fruit() print(f.food.fruit()) #Генерація області по мові adr = Address('uk') adr.region() print(adr.region()) # Генерація країни по мові adr = Address('uk') adr.country() print(adr.country()) # Генерація адреси adr = Address('uk') adr.address() print(adr.address()) # Генерація поного імені людини з іншого регіону person = Person(locales.EN) person.full_name() print(person.full_name()) with person.override_locale(locales.RU): person.full_name() print(person.full_name())
def gen_data_add_nested_struct(self, data_path, partition_date, num_rows, file_format): """ Input - data_path: path where the partition will be created (string) - partition_date: partition date to be created (date) - num_rows: number of rows to be generated (integer) - file_format: format of file to be generated (parquet or avro) This function creates a data sample adding a nested struct to the schema """ person = Person('en') address = Address('en') # Create schema schema_address = StructType([ StructField('address', StringType(), True), StructField('city', StringType(), True), StructField('country', StringType(), True), StructField('state', StringType(), True), StructField('postal_code', StringType(), True) ]) schema_df = StructType([ StructField('identifier', StringType(), True), StructField('first_name', StringType(), True), StructField('last_name', StringType(), True), StructField('occupation', StringType(), True), StructField('age', IntegerType(), True), StructField('address', schema_address, True), StructField('date', DateType(), True) ]) # Generate data for _ in range(num_rows): df_temp = self.spark.createDataFrame([[ person.identifier(), person.first_name(), person.last_name(), person.occupation(), person.age(), [ address.address(), address.city(), address.country(), address.state(), address.postal_code() ], partition_date ]], schema_df) try: df = df.union(df_temp) except: df = df_temp df.coalesce(1).write.partitionBy('date').mode('overwrite').format( file_format).save(data_path) print('Partition created: {data_path}/date={date}'.format( data_path=data_path, date=partition_date)) print('# Rows:', df.count()) print('Schema:') df.printSchema() print('\n') return
def gen_data_remove_column(self, data_path, partition_date, num_rows, file_format): """ Input - data_path: path where the partition will be created (string) - partition_date: partition date to be created (date) - num_rows: number of rows to be generated (integer) - file_format: format of file to be generated (parquet or avro) This function creates a data sample removing some columns """ person = Person('en') address = Address('en') schema_street = StructType([ StructField('street_name', StringType(), True) # StructField('lat', FloatType(), True), #column removed # StructField('long', FloatType(), True) #column removed ]) schema_address_details = StructType([ StructField('street', schema_street, True), StructField('number', IntegerType(), True) ]) schema_address = StructType([ StructField('address_details', schema_address_details, True), StructField('city', StringType(), True), StructField('country', StringType(), True), # StructField('country_code', StringType(), True), #column removed StructField('state', StringType(), True), StructField('postal_code', IntegerType(), True) ]) schema_df = StructType([ StructField('identifier', StringType(), True), StructField('first_name', StringType(), True), StructField('last_name', StringType(), True), StructField('occupation', StringType(), True), StructField('age', IntegerType(), True), StructField('address', schema_address, True), # StructField('title_name', StringType(), True), #column removed StructField('date', DateType(), True) ]) for _ in range(num_rows): df_temp = self.spark.createDataFrame( [[ person.identifier(), person.first_name(), person.last_name(), person.occupation(), person.age(), [ [ [ address.street_name() #float(address.latitude()), #float(address.longitude()) ], int(address.street_number()) ], address.city(), address.country(), #address.country_code(), address.state(), int(address.postal_code()) ], #person.title(), partition_date ]], schema_df) try: df = df.union(df_temp) except: df = df_temp df.coalesce(1).write.partitionBy('date').mode('overwrite').format( file_format).save(data_path) print('Partition created: {data_path}/date={date}'.format( data_path=data_path, date=partition_date)) print('# Rows:', df.count()) print('Schema:') df.printSchema() print('\n') return