def populate(authors: Sequence['People'], count=100) -> Generator['Comment', None, None]: import mimesis cid = mimesis.Numbers() comment = mimesis.Text() return (Comment(id=cid.between(1, count), body=comment.sentence(), author=random.choice(authors)) for _ in range(count))
def good_import_generator(n_citizens=20, n_relations=30): data = [] address_generator = mimesis.Address('ru') number_generator = mimesis.Numbers() person_generator = mimesis.Person('ru') gender_generator = mimesis.Person('en') datetime_generator = mimesis.Datetime() for i in range(1, n_citizens + 1): street, building = address_generator.address().rsplit(' ', maxsplit=1) gender = gender_generator.gender().lower() while gender != 'male' and gender != 'female': gender = gender_generator.gender().lower() data.append({ "citizen_id": i, "town": address_generator.city(), "street": street, "building": building, "apartment": number_generator.between(1, 100000), "name": person_generator.full_name(), "birth_date": datetime_generator.date(1900, 2018).strftime("%d.%m.%Y"), "gender": gender, "relatives": [] }) relations = set() for i in range(n_relations): relation = (number_generator.between(1, n_citizens), number_generator.between(1, n_citizens)) while relation in relations or (relation[1], relation[0]) in relations: relation = (number_generator.between(1, n_citizens), number_generator.between(1, n_citizens)) relations.add(relation) data[relation[0] - 1]["relatives"].append(relation[1]) if relation[0] != relation[1]: data[relation[1] - 1]["relatives"].append(relation[0]) return data
def next_vehicle(owners: typing.List[Owner], data_locale: str) -> typing.Iterator[Vehicle]: vehicle_id = 0 transport = mimesis.Transport(data_locale) vehicle_date = mimesis.Datetime(data_locale) numbers = mimesis.Numbers(data_locale) while True: vehicle_id += 1 vehicle = Vehicle(vehicle_id) vehicle.name = transport.car().title() vehicle.code = transport.vehicle_registration_code(data_locale) vehicle.owner = random.choice(owners) vehicle.vehicle_date = vehicle_date.date(start=1800, end=2018).isoformat() vehicle.temparature = numbers.integer_number(start=-30, end=50) yield vehicle
def populate(comments: Sequence['Comment'], authors: Sequence['People'], count=100) -> Generator['Article', None, None]: import mimesis aid = mimesis.Numbers() article = mimesis.Text() answers = list(comments) def get_random_answers(max): counter = 0 while answers and counter < max: yield answers.pop(random.randint(0, len(answers) - 1)) counter += 1 return (Article( id=aid.between(1, count), title=article.title(), author=random.choice(authors), comments=[c for c in get_random_answers(random.randint(1, 10))]) for _ in range(count))
def numbers(): return mimesis.Numbers()
import Mongo first_name = '' last_name = '' patronomik = '' clas = {'gb': [], 'bb': [], 'norm': []} classes = {} for i in range(11): classes.update({i + 1: clas}) gb = [] bb = [] norm = [] a = mimesis.Person(locales.RU) ru = RussiaSpecProvider() cl = mimesis.Numbers() d = mimesis.Datetime() t = mimesis.Text() # пофиксить номера школ, районы, datetime в date, вынести subject в Учениках в оценках mark_typ = ['Контрольная', 'Обычная'] visition = ['Был', 'Уважительная причина', 'Не уважительная причина'] subject_names = [ 'Математика', 'Химия', 'Физика', 'Астрономия', 'Информатика', 'Биология' ] # def classify_students(): # for i in range(20000): # if i % 5 == 0: # gb.append(i)
def generate_sample_data(total_employees_amount: int, total_patients_amount: int, conn): # first - check arguments if total_employees_amount < 0 or total_employees_amount % 100.0 != 0.0: return 1 if total_patients_amount < 0 or total_patients_amount % 1000.0 != 0.0: return 1 # mimesis generators will be used because they're really easy. very easy # pls read docs on them, it'll take 5 min or even less gen_person = mimesis.Person('en') date = mimesis.Datetime() ssn_id = mimesis.Numbers() home_addr = mimesis.Address() stuff_jobs = ['janitor', 'cook', 'guard'] # add multipliers such as no more than 1 Hospital - partially done # add loops - partially done # Doctors generator. Doctor types have been taken from Wikipedia - all questions for them doctor_types = ['Cardiac surgery', 'Cardiothoracic surgery', 'Colorectal surgery', 'Dental surgery', 'Organ transplant|Transplant surgery', 'Upper gastrointestinal surgery', 'Vascular surgery', 'Craniofacial surgery', 'Neurological surgery', 'Oral and maxillofacial surgery', 'Obstetrics and gynaecology', 'Orthopedic surgery', 'Ophthalmology', 'Otorhinolaryngology', 'Pediatric surgery', 'Podiatric_surgery', 'Plastic surgery', 'Surgical oncology', 'Trauma surgery', 'Thoracic surgery', 'Urology', 'General Surgery'] for i in range(0, int(0.25 * total_employees_amount), 1): r.table('Doctors').insert({ 'doctor_id': i, 'name': gen_person.full_name(gender=Gender.MALE), 'date_of_birth': str(date.date(start=1950, end=1995)), 'sex': 'male', 'qualification ': doctor_types[randint(0, len(doctor_types) - 1)], 'SSN_ID': ssn_id.between(minimum=1000000000000000, maximum=10000000000000000 - 1), 'telephone': 'blue', 'home_address': home_addr.address(), 'salary': 12000.00 }).run(conn) # Nurses generator for i in range(0, int(0.35 * total_employees_amount), 1): r.table('Nurses').insert({ 'nurse_id': i, 'name': gen_person.full_name(gender=Gender.FEMALE), 'date_of_birth': str(date.date(start=1950, end=1997)), 'sex': 'female', 'qualification': 'nurse', 'SSN_ID': ssn_id.between(minimum=1000000000000000, maximum=10000000000000000 - 1), 'telephone': ssn_id.between(minimum=89000000000, maximum=89999999999), 'home_address': home_addr.address(), 'salary': 27000.00 }).run(conn) # Paramedics generator for i in range(0, int(0.15 * total_employees_amount), 1): r.table('Paramedics').insert({ 'paramedic_id': i, 'name': gen_person.full_name(gender=Gender.MALE), 'date_of_birth': str(date.date(start=1980, end=2000)), 'sex': 'male', 'qualification': 'ambulance paramedic', 'SSN_ID': ssn_id.between(minimum=1000000000000000, maximum=10000000000000000 - 1), 'telephone': ssn_id.between(minimum=89000000000, maximum=89999999999), 'home_address': home_addr.address(), 'salary': 16600.00 }).run(conn) # Administrators generator admins_types=['Dean of the Hospital', 'Hospital Administrator', 'Head of Surgeons and Doctors Department', 'Head of Nursing Department', 'Head of Emergency Department', 'Head of Recruitment Department', 'Head of Medicine Department', 'Head of Equipment Department', 'Head of Security Department', 'Medical Student Administration', 'Inventory Head'] for i in range(0, int(0.15 * total_employees_amount), 1): r.table('Administrators').insert({ 'administrator_id': i, 'name': gen_person.full_name(gender=Gender.FEMALE), 'date_of_birth': str(date.date(start=1970, end=1990)), 'sex': 'male', 'qualification': admins_types[randint(0, len(admins_types) - 1)], 'SSN_ID': ssn_id.between(minimum=1000000000000000, maximum=10000000000000000 - 1), 'telephone': ssn_id.between(minimum=89000000000, maximum=89999999999), 'home_address': home_addr.address(), 'salary': 0.00 }).run(conn) # Stuff generator for i in range(0, int(0.10 * total_employees_amount), 1): r.table('Stuff').insert({ 'stuff_id': i, 'name': gen_person.full_name(gender=Gender.FEMALE), 'date_of_birth': str(date.date(start=1950, end=2000)), 'sex': 'female', 'vacated_position': stuff_jobs[randint(0, len(stuff_jobs) - 1)], 'SSN_ID': ssn_id.between(minimum=1000000000000000, maximum=10000000000000000 - 1), 'telephone': ssn_id.between(minimum=89000000000, maximum=89999999999), 'home_address': home_addr.address(), 'salary': 8800.00 }).run(conn) # Patients generator. Gender division: 0.5 avg for i in range(0, int(0.5 * total_patients_amount)): r.table('Patients').insert({ 'patient_id': total_employees_amount, 'name': gen_person.full_name(gender=Gender.FEMALE), 'date_of_birth': str(date.date(start=1935, end=2015)), 'sex': 'male', 'SSN_ID': ssn_id.between(minimum=1000000000000000, maximum=10000000000000000 - 1), 'telephone': ssn_id.between(minimum=89000000000, maximum=89999999999), 'home_address': home_addr.address(), 'coordinates': {float(randint(10000, 300000) / 100), float(randint(10000, 300000) / 100)}, 'illness_history_head_id': i }).run(conn) for i in range(int(0.5 * total_patients_amount), int(1.0 * total_patients_amount)): r.table('Patients').insert({ 'patient_id': total_employees_amount, 'name': gen_person.full_name(gender=Gender.FEMALE), 'date_of_birth': str(date.date(start=1940, end=2015)), 'sex': 'female', 'SSN_ID': ssn_id.between(minimum=1000000000000000, maximum=10000000000000000 - 1), 'telephone': ssn_id.between(minimum=89000000000, maximum=89999999999), 'home_address': home_addr.address(), 'coordinates': {float(randint(10000, 300000) / 100), float(randint(10000, 300000) / 100)}, 'illness_history_head_id': i }).run(conn) # Let's link a little illness histories with their owners. # Also, by analogue of extended books, next_ids can be used for i in range(int(1.5 * total_employees_amount)): r.table('IllnessHistories').insert({ 'history_id': i, 'owner_id': i, 'data': {}, 'next_id': '' }).run(conn) # for this table - maybe generate different types of forms r.table('IllnessForms').insert({ 'form_id': total_employees_amount, 'form_type': '069-uf', 'doctor_id': total_employees_amount, 'patient_id': total_employees_amount, 'procedure_type': 'operation', 'additional_information': { 'operation_type': 'bone marrow transplant', 'result': 'success' } }).run(conn) # Hospital generator r.table('Hospital').insert({ 'hospital_id': 0, 'address': home_addr.address(), 'coordinates': {0.00, 0.00}, 'director': 'wanted', 'departments': doctor_types }).run(conn) # Departments generator for i in range(len(doctor_types)): r.table('Departments').insert({ 'department_id': i, 'name': doctor_types[i], 'leader_id': total_employees_amount, 'doctors_ids': [total_employees_amount], 'nurses_ids': [total_employees_amount], 'administrators_ids': [total_employees_amount], 'stuff_ids': [total_employees_amount], 'beds': randint(15, 50) }).run(conn) # Ambulance generator for i in range(int(0.01 * total_employees_amount)): r.table('Ambulances').insert({ 'ambulance_id': i, 'driver_id': 'wanted', 'doctor_id': 'wanted', 'paramedic_ids': ['wanted'], 'coords': {0.00, 0.00} }).run(conn) return 0