Пример #1
0
def importToPin():
    try:
        dsnStr = cx_Oracle.makedsn("217.173.198.135", "1522", "orcltp")
        con = cx_Oracle.connect(user="******", password="******", dsn=dsnStr)
        num = int(input("How many rows should be entered? "))
        last_id = getLastID("pin")
        print("Fetching rows...")
        for x in range(num):
            d = mimesis.Datetime()
            state_id = random.randint(1, getLastID("state"))
            asset_id = random.randint(1, getLastID("asset"))
            date_pinned = d.date(start=2015, end=2021)
            employee_id = random.randint(1, getLastID("employee"))
            query = "INSERT INTO PIN (id_pin, state_id, asset_id, date_pinned, employee_id) VALUES (:1, :2, :3, :4, :5)"
            cursor = con.cursor()
            last_id = last_id + 1
            cursor.execute(
                query, (last_id, state_id, asset_id, date_pinned, employee_id))
            print(query)
            cursor.close()
        con.commit()
        print("Rows added successfully")
    except cx_Oracle.Error as error:
        print("Error occurred:")
        print(error)
    consoleInput()
Пример #2
0
def new_schooluser() -> dict:
    """Generate data for fake school user

    :return: dictionary with personal data
    :rtype: dict
    """
    random.seed()
    _person = mimesis.Person(locales.RU)
    _person_ru = mimesis.builtins.RussiaSpecProvider()
    _date = mimesis.Datetime()
    _gender = random.choice((enums.Gender.MALE, enums.Gender.FEMALE))
    _username = _person.username('ld')
    return {
        'username': _username,
        'password': _username,
        'first_name': _person.name(_gender),
        'last_name': _person.surname(_gender),
        'patronymic_name': _person_ru.patronymic(_gender),
        'birth_date': _date.formatted_date(fmt='%Y-%m-%d',
                                           start=1990,
                                           end=2000),
        'email': _person.email(),
        'language': random.choice(LANGUAGES),
        'is_active': True,
        'is_staff': False,
        'is_superuser': False
    }
Пример #3
0
def importToAsset():
    try:
        dsnStr = cx_Oracle.makedsn("217.173.198.135", "1522", "orcltp")
        con = cx_Oracle.connect(user="******", password="******", dsn=dsnStr)
        num = int(input("How many rows should be entered? "))
        last_id = getLastID("asset")
        print("Fetching rows...")
        for x in range(num):
            y = mimesis.Person('en')
            d = mimesis.Datetime()
            name = 'Personal Computer'
            model_id = random.randint(1, getLastID("model"))
            supplier_id = random.randint(1, getLastID("supplier"))
            price = y.identifier(mask="####")
            date_of_creation = d.date(start=2015, end=2021)
            date_of_purchase = d.date(start=2015, end=2021)
            serial = y.identifier(mask="######")
            query = "INSERT INTO asset (id_asset, name, model_id, supplier_id, price, date_of_creation, date_of_purchase, serial) VALUES (:1, :2, :3, :4, :5, :6, :7, :8)"
            cursor = con.cursor()
            last_id = last_id + 1
            cursor.execute(query, (last_id, name, model_id, supplier_id, price,
                                   date_of_creation, date_of_purchase, serial))
            print(query)
            cursor.close()
        con.commit()
        print("Rows added successfully")
    except cx_Oracle.Error as error:
        print("Error occurred:")
        print(error)
    consoleInput()
Пример #4
0
    def seed():
        business = mimesis.Business()
        datetime = mimesis.Datetime()
        text = mimesis.Text()

        default_checkout_fields = ["First Name", "Last Name"]

        distributors = models.Distributor.query.all()

        for distributor in distributors:
            campaign = models.Campaign(
                name=f"{business.company()} Distributor - {distributor.id}",
                company_name=f"Campaign distributor {distributor.id}",
                start_date=datetime.datetime(start=2018, end=2019),
                end_date=datetime.datetime(start=2020, end=2021),
                storefront_pricing=random.choice((True, False)),
                company_allowance=random.randrange(30, 200),
                company_allowance_personal_pay=random.choice((True, False)),
                items_count_limit=1000,
                price_limit=10000,
                email_shopper=random.choice((True, False)),
                checkout_fields=default_checkout_fields,
                departments=None,
                managers=None,
                message=text.sentence(),
                bfl_cost=0.0,
                distributor_po=None,
                pick_pack_partner_message=text.sentence(),
                created_by_id=
                1,  # we must specify this manually, since no user is logged in
                pick_pack_partner=None,
                distributor=distributor,
            )
            db.session.add(campaign)

            shopper_role = models.Role.query.filter_by(name="Shopper").first()
            admin_buyer_role = models.Role.query.filter_by(
                name="Admin Buyer").first()

            # swap the existing shopper account over to this campaign
            shopper = models.Account.query.filter_by(
                distributor_id=distributor.id, role=shopper_role).first()
            shopper.distributor = None
            shopper.campaign = campaign
            db.session.add(shopper)

            # swap the existing admin buyer account over to this campaign
            admin_buyer = models.Account.query.filter_by(
                distributor_id=distributor.id, role=admin_buyer_role).first()
            admin_buyer.distributor = None
            admin_buyer.campaign = campaign
            admin_buyer.reports_enabled = True
            db.session.add(admin_buyer)

        db.session.commit()
Пример #5
0
def next_book(authors: typing.List[Author],
              data_locale: str) -> typing.Iterator[Book]:
    code = mimesis.Code(data_locale)
    date = mimesis.Datetime(data_locale)
    text = mimesis.Text(data_locale)

    book_id = 0

    while True:
        book_id += 1

        book = Book(book_id)
        book.title = text.title()
        book.author = random.choice(authors)
        book.isbn = code.isbn()
        book.release_at = date.date(start=1800, end=2018)

        yield book
Пример #6
0
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
Пример #7
0
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
Пример #8
0
def create_and_save_fake_feature_requests() -> None:

    if FeatureRequest.query.count() > 0:
        return

    new_feature_requests: List[FeatureRequest] = []
    client_ids: List[int] = [c.id for c in Client.query.all()]
    product_area_ids: List[int] = [pa.id for pa in ProductArea.query.all()]

    development_provider = mimesis.Development()
    datetime_provider = mimesis.Datetime()
    for counter in range(1, 5):
        for client_id in client_ids:
            new_feature_requests.append(FeatureRequest(
                title=f"{development_provider.database()} {random.choice(('problem', 'optimization', 'feature'))}",
                description=development_provider.software_license(),
                client_id=client_id,
                client_priority=counter,
                target_date=datetime.datetime.strptime(datetime_provider.date(2019, 2021), "%m/%d/%Y").date(),
                product_area_id=random.choice(product_area_ids)
            ))

    db_session.bulk_save_objects(new_feature_requests)
    db_session.commit()
Пример #9
0
def dt(request):
    return mimesis.Datetime(request.param)
min_age = config["customers"]["min_age"]
joined_start_date = config["customers"]["joined_start_date"]
joined_end_date = config["customers"]["joined_end_date"]
genders = config["genders"][language]
gender_prob = config["genders"]["percentages"]

# data processing config
amounts_cpu = config["data_processing"]["amount_in_cpu"]
auto_batch = True if config["data_processing"][
    "auto_batch_based_in_cpu"] == "True" else False

# loading mocking data type
business = mimesis.Business(language)
person = mimesis.Person(language)
address = mimesis.Address(language)
dates = mimesis.Datetime(language)

# Calculating random probabilities
# 245 countries
country_prob = common_functions.random_probabilities(1, 245)
ages_probab = common_functions.random_probabilities(min_age, max_age)

# Global customers array
customers = []


def generate_customers(amount, index_start):
    # generates customers' info
    # amount: number of customer to generate
    # index_start: from what index starts
Пример #11
0
def _datetime():
    return mimesis.Datetime()
Пример #12
0
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)
#         elif i % 5 == 1:
Пример #13
0
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
Пример #14
0
if len(sys.argv) != 3 or sys.argv[1][-4:] != '.csv' or not strIsInt(sys.argv[2]):
    print("Please use this program with the following command line parameters:")
    print("python generator.py [csv path] [tuples to generate]")
else:
    full_out = []

    for i in range(int(sys.argv[2])):
        int_out = []
        
        int_out.append(m.Person().username())
        int_out.append(m.Person().name())
        int_out.append(m.Person().last_name())
        int_out.append(m.Person().telephone())
        int_out.append(m.Address().address())
        int_out.append(m.Address().zip_code())
        int_out.append(m.Datetime().date())

        int_out.append(m.Datetime().date())

        int_out.append(m.Hardware().cpu())
        int_out.append(m.Hardware().cpu_frequency())
        int_out.append(m.Hardware().graphics())
        int_out.append(m.Hardware().manufacturer())
        int_out.append(m.Hardware().ram_size())
        int_out.append(m.Hardware().ram_type())
        int_out.append(m.Hardware().resolution())

        int_out.append(m.Games().game())
        int_out.append(m.Datetime().date())
        int_out.append(m.Text().text(2))
Пример #15
0
 def datetime(self):
     dt = mimesis.Datetime('ja')
     return dt.datetime()
Пример #16
0
    def handle(self, *args, **options):
        get_users_count = User.objects.all().count()
        print('users_count:', get_users_count)
        sleep(2)
        for i in range(users_count - get_users_count):
            User.objects.create(
                name=mimesis.Person('en').username(),
                birthday=mimesis.Datetime().date(start=1950, end=2002),
                registration_date=mimesis.Datetime().datetime(),
                email=mimesis.Person('en').email(),
                description=mimesis.Text('ru').sentence())
            this_sleep(i)
            print('users_count:', get_users_count + i, ' из ', users_count)

        get_publication_count = Publication.objects.all().count()
        print('publication_count:', get_publication_count)
        sleep(1)
        for i in range(publication_count - get_publication_count):
            Publication.objects.create(
                description=mimesis.Text('ru').sentence(),
                author=User.objects.get(pk=randint(1, users_count - 2)),
                title=mimesis.Text('ru').title())
            this_sleep(i)
            print('publication_count:', get_publication_count + i, 'из',
                  publication_count)

        get_comment_count = Comment.objects.all().count()
        print('comment_count:', get_comment_count)
        sleep(1)
        for i in range(comment_count - get_comment_count):
            Comment.objects.create(
                author=User.objects.get(pk=randint(1, users_count - 2)),
                publication=Publication.objects.get(
                    pk=randint(1, publication_count - 2)),
                comment=mimesis.Text('ru').sentence())
            this_sleep(i)
            print('comment_count:', get_comment_count + i, 'из', comment_count)

        get_like_count = Like.objects.all().count()
        print('like_count:', get_like_count)
        sleep(1)
        for i in range(like_count - get_like_count):
            if randint(0, 1):
                Like.objects.create(
                    author=User.objects.get(pk=randint(1, users_count - 2)),
                    publication=Publication.objects.get(
                        pk=randint(1, publication_count - 2)))
            else:
                Like.objects.create(
                    author=User.objects.get(pk=randint(1, users_count - 2)),
                    comment=Comment.objects.get(randint(1, comment_count - 2)))
            this_sleep(i)
            print('like_count:', get_like_count + i, 'из', like_count)

        get_tags_count = Tag.objects.all().count()
        print('tags_count:', get_tags_count)
        sleep(1)
        for i in range(tags_count - get_tags_count):
            tag = Tag(title=gen_tag())
            tag.save()
            for j in range(1, tags_publ_count):
                tag.publication.add(
                    Publication.objects.get(pk=randint(1, publication_count -
                                                       2)))
            tag.save()
            this_sleep(i)
            print('tags_count:', get_tags_count + i, 'из', tags_count)

        # need_date = (datetime.now() + timedelta(days=10)).date()
        # payouts_types = Payouts_type.objects.filter(date_end=need_date)
        # if len(payouts_types) > 0:
        #     message = "Через 10 дней закончится прием следующих заявлений: " + \
        #         ', '.join([ payout_type.payouts_type for payout_type in payouts_types])
        #     self.stdout.write(message)
        #     admins = Students.objects.filter(proforg__gte=3).exclude(vk_id="")
        #     if len(admins) > 0:
        #         message_send({
        #             'user_ids': ','.join([ admin.vk_id for admin in admins]),
        #             'message': message,
        #         })
        # self.stdout.write('Successfully test')
        return