Example #1
0
 def registration_positive_test(self, device: Device) -> None:
     generator = Person()
     assert "success" in UserRegistration(
         Identity(generator.name(), generator.last_name(),
                  generator.telephone()),
         Credentials(generator.email(), generator.password(), "0"),
     ).registration_response(device)
Example #2
0
def create_human(n):  # function of creating new client
    if n == 1:
        person = Person('ru')
    else:
        person = Person('en')

    # Выводим исландские мужские имена.
    client_info = generate_id_passport()

    print('\nфамилия:\t', person.last_name())
    print('имя:\t\t', person.name())
    print('отчество:\t', person.surname(), '\n')

    passport = generate_number_passport()
    print('личный №:\t', client_info.get('idn'))
    print('документ:\t', passport)

    print('пол:\t\t', client_info.get('sex'))
    print('возраст:\t', person.age(13, 70), '\n')
    # print('аватар\t', person.avatar())
    print('гражд-во:\t', person.get_current_locale())
    print('Нац-сть:\t', person.nationality())
    print('телефон:\t', person.telephone('+37529#######'))
    print('email:\t\t', '*****@*****.**')
    # print('email:\t\t', person.email())
    print('проф-ия:\t', person.occupation(), '\n')
    print('обращение:\t', person.title())
    print('взгляды:\t', person.views_on())
    print('вера:\t\t', person.worldview(), '\n')
def run():
    person = Person()
    text = Text()
    internet = Internet()
    dateTime = Datetime()

    for i in range(100):
        User.objects.create(password="******",
                            username=person.username(),
                            first_name=person.name(),
                            last_name=person.last_name(),
                            email=person.email())

    users = User.objects.all()

    for i in range(100):
        Post.objects.create(author=choice(users),
                            link=internet.home_page(),
                            title=text.title(),
                            description=text.text())

    posts = Post.objects.all()

    for i in range(100):
        Comment.objects.create(author=choice(users),
                               post=choice(posts),
                               description=text.text())
Example #4
0
    def seed():

        # Data
        m_datetime = Datetime()
        person = Person()
        dates_range = dict(start=(datetime.utcnow() -
                                  timedelta(days=366)).year,
                           end=datetime.utcnow().year)

        _role = models.Role.query.filter_by(name="Shopper").first()
        accounts = models.Account.query.filter_by(role=_role).all()

        for account in accounts:
            # only make orders for accounts with at least one campaign
            if not account.campaign:
                continue

            # Generate and save orders
            for _ in range(randint(0, 4)):
                order = models.Order(
                    account=account,
                    campaign=account.campaign,
                    created_at=m_datetime.datetime(start=dates_range["start"],
                                                   end=dates_range["end"]),
                    checkout_fields={
                        "First Name": person.name(),
                        "Last Name": person.last_name()
                    },
                )
                db.session.add(order)

        db.session.commit()
    def handle(self, *args, **options):
        # raise NotImplementedError()
        Snippet.objects.all().delete()
        users = []
        person = Person()
        for _ in range(40):
            User.objects.create(password=person.password(),
                                username=person.username(),
                                first_name=person.name(),
                                last_name=person.last_name(),
                                email=person.email())

        text = Text()
        users = User.objects.all()

        for _ in range(30):
            language = choice(['python', 'javascript', 'ruby', 'java'])

            if language == "java":
                content = open(BASE_DIR + "/core/fakecode/file.java").read()
            elif language == "python":
                content = open(BASE_DIR + "/core/fakecode/python.py").read()
            elif language == "javascript":
                content = open(BASE_DIR +
                               "/core/fakecode/javascript.js").read()
            else:
                content = open(BASE_DIR + "/core/fakecode/ruby.rb").read()
            title = text.sentence()
            if not Snippet.objects.filter(title=title).exists():
                Snippet.objects.create(author=choice(users),
                                       title=title,
                                       language=language,
                                       content=content)
def create_human(n):
    """

    :param n: язык генерации данных
    :return: сгенерированные фейковые данные
    """
    log.info("Генерируем тестовые данные")
    if n == 1:
        person = Person('ru')
    else:
        person = Person('en')
    log.info("person: " + str(person))

    client_info = generate_id_passport()

    print('\nфамилия:\t', person.last_name())
    print('имя:\t\t', person.name())
    print('отчество:\t', person.surname(), '\n')

    passport = generate_number_passport()
    print('личный №:\t', client_info.get('idn'))
    print('документ:\t', passport)

    print('пол:\t\t', client_info.get('sex'))
    print('возраст:\t', person.age(13, 70), '\n')
    # print('аватар\t', person.avatar())
    print('гражд-во:\t', person.get_current_locale())
    print('Нац-сть:\t',person.nationality())
    print('телефон:\t', person.telephone('+37529#######'))
    print('email:\t\t', person.email())
    print('проф-ия:\t', person.occupation(), '\n')
    print('обращение:\t', person.title())
    print('взгляды:\t', person.views_on())
    print('вера:\t\t', person.worldview(), '\n')
def fill_persondata():
    db = MySQLdb.connect(host=config.DB_HOST,
                         user=config.DB_USER,
                         passwd=config.DB_PASSWORD,
                         db=config.DB_NAME)
    cursor = db.cursor()

    # Zero client, anon
    cursor.execute(
        """INSERT INTO PersonData (first_name, last_name, birth_date, email, mobile, gender) VALUES (%s, %s, %s, %s,
            %s, %s);""", [
            'anon', 'anon',
            Datetime().date(start=1950, end=2001), None, None, None
        ])
    for _ in range(config.N_PERSONS):
        p = Person('ru')
        cursor.execute(
            """INSERT INTO PersonData (first_name, last_name, birth_date, email, mobile, gender) VALUES (%s, %s, %s,
                %s, %s, %s);""", [
                p.name(),
                p.surname(),
                Datetime().date(start=1950, end=2001),
                p.email(),
                p.telephone('#' * 11),
                'M' if p.gender(iso5218=True) == 1 else 'F'
            ])

    db.commit()
    cursor.close()
    db.close()
Example #8
0
    def fake(self):
        p = Person()
        students = Student.objects.filter(sis_id__isnull=False).all()
        for student in tqdm(students, desc="Faking students", leave=False):
            student.first_name = p.name()
            student.last_name = p.last_name()
            student.save()

        profiles = UserProfile.objects.filter(sis_id__isnull=False).all()
        for profile in tqdm(profiles, desc="Faking users", leave=False):
            user = profile.user
            user.first_name = p.name()
            user.last_name = p.last_name()
            user.save()

        self.stdout.write(
            self.style.SUCCESS(
                f'Faked {len(students)} students and {len(profiles)} users.'))
Example #9
0
 def test(self, grid: str, device: Device) -> None:
     chrome: Remote = Chrome(grid)
     registration = RegisterAccountPage(chrome)
     registration.load(device)
     person = Person()
     registration.fill_personal_details(person.name(), person.last_name(),
                                        person.email(), person.telephone())
     registration.fill_password(person.password())
     registration.press_continue()
     assert RegistrationSuccessPage(chrome).available()
Example #10
0
def generate_users(count=1024, locale="en"):
    logging.info(f"Generating {count} users.")
    person = Person(locale)
    for i in range(count):
        user = UserModel()
        user.first_name = person.name()
        user.last_name = person.surname()
        user.email = person.email()
        user.password = person.password()
        user.phone = person.telephone(mask="###.###.####")
        user.save()
Example #11
0
 def test_contact_us(self, device: Device) -> None:
     person = Person()
     assert_if_request_contains_success_response_url(
         Post(
             f"https://{device.connections.main.ip}/index.php?route=information/contact",
             {
                 "name": person.name(),
                 "email": person.email(),
                 "enquiry": "test data test data"
             },
         ))
Example #12
0
def create_personalData():  # function of generate new client data
    passport = ''
    person = Person('ru')

    # Выводим исландские мужские имена.

    lastname = person.last_name()
    personalData['lastname'] = lastname
    # print('\nфамилия:\t', personalData['lastname'])

    name = person.name()
    personalData['name'] = name
    # print('имя:\t\t', personalData['name'])

    surname = person.surname()
    personalData['surname'] = surname
    # print('отчество:\t', personalData['surname'])

    gender = person.gender()
    personalData['gender'] = gender
    # print('пол:\t\t', personalData['gender'])

    for _ in range(2):
        varLet = random.choice(string.ascii_uppercase)
        passport += varLet
    passport += person.telephone('#######')
    personalData['passport'] = passport
    # print('паспорт:\t', personalData['passport'])

    ### birthday
    currentDate()
    personalData['age'] = age
    personalData['age'][2] = str(
        int(personalData['age'][2]) - person.age(16, 70))
    # print('возраст:\t', personalData['age'], '\n')
    ###

    # print('гражд-во:\t', person.get_current_locale())
    # print('Нац-сть:\t',person.nationality())

    ### mobile
    mobile = person.telephone('+37529#######')
    personalData['mobile'] = mobile
    # print('телефон:\t', personalData['mobile'])
    ###
    ### email
    # personalData['email'] = person.email()
    # print('email:\t\t', personalData['email'])
    ###
    # print('проф-ия:\t', person.occupation(), '\n')
    # print('обращение:\t', person.title())
    # print('взгляды:\t', person.views_on())
    # print('вера:\t\t', person.worldview(), '\n')
    return personalData
Example #13
0
def inf_file_unpack(path_to_file):
    with open(path_to_file, 'r', encoding='UTF-8') as inf_file:
        inf_file_dic = yaml.load(inf_file, Loader=yaml.FullLoader)
        logger.debug(f'Распаковали inf.txt')
        token = inf_file_dic['token']
        logger.debug(f'Ваш токен: {token}')
        country_name = inf_file_dic['country_name']
        country_auto_select = inf_file_dic['country_auto_select']
        logger.debug(f'Выбранная страна: {country_name}')
        sex = inf_file_dic['sex']
        logger.debug(f'Выбранный пол: {sex}')
        person = Person('ru')
        if sex == 'FEMALE':
            name = person.name(gender=Gender.FEMALE)
            surname = person.surname(gender=Gender.FEMALE)
        else:
            name = person.name(gender=Gender.MALE)
            surname = person.surname(gender=Gender.MALE)

        return token, country_name, name, surname, country_auto_select
Example #14
0
def _generate_user_data(locale='ru'):
    person = Person(locale)
    date = Datetime(locale)
    gender = get_random_item(Gender)
    return {
        'password': _generate_password(),
        'first_name': person.surname(gender=gender),
        'last_name': person.name(gender=gender),
        'email': person.email(),
        'date_joined': date.datetime(start=2014, end=2015).replace(tzinfo=utc),
    }
    def handle(self, *args, **options):
        person = Person('ru')
        for i in range(25):
            gender = random.choice([Gender.FEMALE, Gender.MALE])
            user = User.objects.create_user(email=person.email(),
                                            password='******')

            user.first_name = person.name(gender=gender)
            user.last_name = person.last_name(gender=gender)

            user.save()

        self.stdout.write(self.style.SUCCESS('Пользователи успешно созданы'))
Example #16
0
def create_person():
    from mimesis import Person as MimesisPerson, locales, Address

    person = MimesisPerson(locales.RU)
    address = Address(locales.RU)

    with transaction.atomic():
        first_name = person.name()
        last_name = person.surname()

        gender = person.gender()
        if gender == 'Муж.':
            patronymic = choice([
                'Сергеевич', 'Николаевич', 'Артурович', 'Константинович',
                'Игоревич'
            ])
        else:
            patronymic = choice([
                'Александровна', 'Борисовна', 'Петровна', 'Юрьевна',
                'Анатольевна'
            ])

        birth_date = generate_birthdate()
        address = '{}, {}'.format(address.federal_subject(), address.address())

        passport_series = randint(1000, 7000)
        passport_number = randint(100000, 999999)

        pair = generate_RSA_pair()

        signature_public_key = pair[1]
        load_key_to_file(
            '../../../person_signature_private_keys/{}_{}_{}_{}.pem'.format(
                passport_series, passport_number, last_name, first_name),
            pair[0])

        person_info = '{} {} {} {} {} {} {} {}'.format(
            first_name, last_name, patronymic, birth_date, address,
            passport_series, passport_number, signature_public_key)

        signature_i = sign_person_info(person_info)

        Person(first_name=first_name,
               last_name=last_name,
               patronymic=patronymic,
               birth_date=birth_date,
               address=address,
               passport_series=passport_series,
               passport_number=passport_number,
               signature_public_key=signature_public_key,
               signature_i=signature_i).save()
Example #17
0
    def setUp(self):
        """Generate some fake data."""
        self.app = Flask('test')
        util.init_app(self.app)
        self.app.config['CLASSIC_DATABASE_URI'] = 'sqlite:///test.db'
        self.app.config['CLASSIC_SESSION_HASH'] = 'foohash'

        with self.app.app_context():
            util.create_all()
            with util.transaction() as session:
                person = Person('en')
                net = Internet('en')
                ip_addr = net.ip_v4()
                email = person.email()
                approved = 1
                deleted = 0
                banned = 0
                first_name = person.name()
                last_name = person.surname()
                suffix_name = person.title()
                joined_date = util.epoch(
                    Datetime('en').datetime().replace(tzinfo=EASTERN))
                db_user = models.DBUser(
                    first_name=first_name,
                    last_name=last_name,
                    suffix_name=suffix_name,
                    share_first_name=1,
                    share_last_name=1,
                    email=email,
                    flag_approved=approved,
                    flag_deleted=deleted,
                    flag_banned=banned,
                    flag_edit_users=0,
                    flag_edit_system=0,
                    flag_email_verified=1,
                    share_email=8,
                    email_bouncing=0,
                    policy_class=2,  # Public user. TODO: consider admin.
                    joined_date=joined_date,
                    joined_ip_num=ip_addr,
                    joined_remote_host=ip_addr)
                session.add(db_user)

                self.user = domain.User(user_id=str(db_user.user_id),
                                        username='******',
                                        email=db_user.email,
                                        name=domain.UserFullName(
                                            forename=db_user.first_name,
                                            surname=db_user.last_name,
                                            suffix=db_user.suffix_name))
Example #18
0
 def test(self, grid: str, device: Device) -> None:
     chrome: Remote = Chrome(grid)
     registration = RegisterAffiliatePage(chrome)
     person = Person()
     registration.load(device)
     registration.fill_personal_details(person.name(), person.last_name(),
                                        person.email(), person.telephone())
     registration.press_pay_method()
     registration.fill_information(person.full_name(),
                                   f"www.{person.username()}.com",
                                   "2332153467", person.email())
     registration.fill_password(person.password())
     registration.press_continue()
     assert RegAffiliateSuccessPage(chrome).available()
Example #19
0
    def make_full_name(self, loc, value):
        global sex
        per = Person(loc)
        rsp = RussiaSpecProvider()

        if value == 'male':
            sex = Gender.MALE
        elif value == 'famale':
            sex = Gender.FEMALE
        name = per.name(sex)
        surname = per.surname(sex)
        patron = rsp.patronymic(sex)
        age = per.age(16, 66)
        occup = per.occupation()
        return name, surname, patron, age, occup
Example #20
0
def update():
    db.users.remove({})
    db.goods.remove({})
    users, goods = [], []
    for _ in range(30):
        person = Person(locales.ZH)
        user = {
            "name": person.name(),
            "age": person.age(),
            "sex": choice(["boy", "girl"]),
            "mobile": person.telephone(),
            "wechat": person.email(),
            "status": choice(["normal", "in_debt"]),
            "isVip": Development().boolean(),
        }
        users.append(user)
    db.users.insert_many(users)
Example #21
0
    def _bootstrap(count):
        from mimesis import Person

        person = Person("en")

        for _ in range(count):
            u = User(
                email=person.email(),
                confirmed=True,
                first_name=person.name(),
                last_name=person.surname(),
            )

            db.session.add(u)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()
    def handle(self, *args, **options):
        Chilipili.objects.all().delete()
        Like.objects.all().delete()
        users = []
        person = Person()
        for _ in range(10):
            User.objects.create(password=person.password(), username=person.username(
            ), first_name=person.name(), last_name=person.last_name(), email=person.email())
        # date = Datetime()
        text = Text()
        users = User.objects.all()
        for _ in range(20):
            Chilipili.objects.create(author_user=choice(
                users), text=text.sentence())

        chilipilis = Chilipili.objects.all()
        for _ in range(100):
            Like.objects.create(like_user=choice(
                users), chilipili=choice(chilipilis))
Example #23
0
def _generate_questionnaire_data(locale='ru') -> dict:
    person = Person(locale)
    rus_spec = RussiaSpecProvider()
    datetime = Datetime(locale)
    g = get_random_item(Gender)
    created = datetime.datetime(start=2015, end=2018)
    return {
        'id': uuid.uuid4(),
        'created': created.replace(tzinfo=utc),
        'updated': created.replace(tzinfo=utc),
        'surname': person.surname(gender=g),
        'first_name': person.name(gender=g),
        'patronymic': rus_spec.patronymic(gender=g),
        'birth_date': datetime.datetime(start=1960, end=1998).date(),
        'phone_num': person.telephone(),
        'pass_ser': rus_spec.passport_series(),
        'pass_num': rus_spec.passport_number(),
        'score': randint(0, 2000),
    }
Example #24
0
def generate():
    inserts = []
    counter = 330

    person = Person('en')
    business = Business('en')
    address = Address('en')
    internet = Internet('en')

    for index in range(counter, 15000, 1):
        inserts.append(template.substitute(id=index,
                                           name=person.name().replace("'", "''"),
                                           surname=person.surname().replace("'", "''"),
                                           email=person.email().replace("'", "''"),
                                           phone=person.telephone(),
                                           customer_id=random.randint(330, 14999)
                                           ))

    inserts_file = open('result_scripts/contacts.sql', 'w', encoding='utf-8')
    inserts_file.writelines('\n'.join(inserts))
    inserts_file.close()
 def test_affiliate_reg(self, device: Device) -> None:
     urllib3.disable_warnings()
     person = Person()
     (assert_if_request_contains_success_response_url(
         Post(
             f"https://{device.connections.main.ip}/index.php?route=affiliate/register",
             {
                 "firstname": person.name(),
                 "lastname": person.last_name(),
                 "email": person.email(),
                 "telephone": person.telephone(),
                 "company": person.full_name(),
                 "website": f"www.{person.username()}.net",
                 "tax": "123456",
                 "payment": "paypal",
                 "paypal": person.email(),
                 "password": person.password(),
                 "confirm": person.password(),
                 "agree": 1,
             },
         )))
def users(count: int = 500) -> List[models.User]:
    """Generate a bunch of random users."""
    _users = []
    for i in range(count):
        locale = _get_locale()
        person = Person(locale)
        net = Internet(locale)
        ip_addr = net.ip_v4()
        _users.append(
            models.User(
                first_name=person.name(),
                last_name=person.surname(),
                suffix_name=person.title(),
                share_first_name=1,
                share_last_name=1,
                email=person.email(),
                share_email=8,
                email_bouncing=0,
                policy_class=2,  # Public user.
                joined_date=_epoch(Datetime(locale).datetime()),
                joined_ip_num=ip_addr,
                joined_remote_host=ip_addr))
    return _users
Example #27
0
    def setUp(self):
        """Generate some fake data."""
        self.app = Flask('test')
        util.init_app(self.app)
        self.app.config['CLASSIC_DATABASE_URI'] = 'sqlite:///test.db'
        self.app.config['CLASSIC_SESSION_HASH'] = 'foohash'

        with self.app.app_context():
            util.create_all()
            with util.transaction() as session:
                person = Person('en')
                net = Internet('en')
                ip_addr = net.ip_v4()
                email = "*****@*****.**"
                approved = 1
                deleted = 0
                banned = 0
                first_name = person.name()
                last_name = person.surname()
                suffix_name = person.title()
                joined_date = util.epoch(
                    Datetime('en').datetime().replace(tzinfo=EASTERN))
                db_user = models.DBUser(
                    first_name=first_name,
                    last_name=last_name,
                    suffix_name=suffix_name,
                    share_first_name=1,
                    share_last_name=1,
                    email=email,
                    flag_approved=approved,
                    flag_deleted=deleted,
                    flag_banned=banned,
                    flag_edit_users=0,
                    flag_edit_system=0,
                    flag_email_verified=1,
                    share_email=8,
                    email_bouncing=0,
                    policy_class=2,  # Public user. TODO: consider admin.
                    joined_date=joined_date,
                    joined_ip_num=ip_addr,
                    joined_remote_host=ip_addr)
                session.add(db_user)

                self.user = domain.User(user_id=str(db_user.user_id),
                                        username='******',
                                        email=db_user.email,
                                        name=domain.UserFullName(
                                            forename=db_user.first_name,
                                            surname=db_user.last_name,
                                            suffix=db_user.suffix_name))

            ok_patterns = ['%w3.org', '%aaas.org', '%agu.org', '%ams.org']
            bad_patterns = ['%.com', '%.net', '%.biz.%']

            with util.transaction() as session:
                for pattern in ok_patterns:
                    session.add(models.DBEmailWhitelist(pattern=str(pattern)))
                for pattern in bad_patterns:
                    session.add(models.DBEmailBlacklist(pattern=str(pattern)))

                session.add(
                    models.DBEndorsementDomain(
                        endorsement_domain='test_domain',
                        endorse_all='n',
                        mods_endorse_all='n',
                        endorse_email='y',
                        papers_to_endorse=3))

                for category, definition in taxonomy.CATEGORIES_ACTIVE.items():
                    if '.' in category:
                        archive, subject_class = category.split('.', 1)
                    else:
                        archive, subject_class = category, ''
                    session.add(
                        models.DBCategory(archive=archive,
                                          subject_class=subject_class,
                                          definitive=1,
                                          active=1,
                                          endorsement_domain='test_domain'))
Example #28
0
    def setUpClass(cls):
        """Generate some fake data."""
        cls.app = Flask('test')
        util.init_app(cls.app)
        cls.app.config['CLASSIC_DATABASE_URI'] = 'sqlite:///test.db'
        cls.app.config['CLASSIC_SESSION_HASH'] = 'foohash'
        cls.app.config['CLASSIC_SESSION_TIMEOUT'] = '36000'

        with cls.app.app_context():
            util.create_all()
            COUNT = 50

            cls.users = []

            _users = []
            _domain_users = []
            for i in range(COUNT):
                with util.transaction() as session:
                    locale = _get_locale()
                    person = Person(locale)
                    net = Internet(locale)
                    ip_addr = net.ip_v4()
                    email = person.email()
                    approved = 1 if _prob(90) else 0
                    deleted = 1 if _prob(2) else 0
                    banned = 1 if random.randint(0, 100) <= 1 else 0
                    first_name = person.name()
                    last_name = person.surname()
                    suffix_name = person.title()
                    name = (first_name, last_name, suffix_name)
                    joined_date = util.epoch(
                        Datetime(locale).datetime().replace(tzinfo=EASTERN))
                    db_user = models.DBUser(
                        first_name=first_name,
                        last_name=last_name,
                        suffix_name=suffix_name,
                        share_first_name=1,
                        share_last_name=1,
                        email=email,
                        flag_approved=approved,
                        flag_deleted=deleted,
                        flag_banned=banned,
                        flag_edit_users=0,
                        flag_edit_system=0,
                        flag_email_verified=1,
                        share_email=8,
                        email_bouncing=0,
                        policy_class=2,  # Public user. TODO: consider admin.
                        joined_date=joined_date,
                        joined_ip_num=ip_addr,
                        joined_remote_host=ip_addr)
                    session.add(db_user)

                    # Create a username.
                    username_is_valid = 1 if _prob(90) else 0
                    username = person.username()
                    db_nick = models.DBUserNickname(
                        user=db_user,
                        nickname=username,
                        flag_valid=username_is_valid,
                        flag_primary=1)

                    # Create the user's profile.
                    archive, subject_class = _random_category()
                    db_profile = models.DBProfile(
                        user=db_user,
                        country=locale,
                        affiliation=person.university(),
                        url=net.home_page(),
                        rank=random.randint(1, 5),
                        archive=archive,
                        subject_class=subject_class,
                        original_subject_classes='',
                        flag_group_math=1 if _prob(5) else 0,
                        flag_group_cs=1 if _prob(5) else 0,
                        flag_group_nlin=1 if _prob(5) else 0,
                        flag_group_q_bio=1 if _prob(5) else 0,
                        flag_group_q_fin=1 if _prob(5) else 0,
                        flag_group_stat=1 if _prob(5) else 0)

                    # Set the user's password.
                    password = person.password()
                    db_password = models.DBUserPassword(
                        user=db_user,
                        password_storage=2,
                        password_enc=util.hash_password(password))

                    # Create some endorsements.
                    archive, subject_class = _random_category()
                    net_points = 0
                    for _ in range(0, random.randint(1, 4)):
                        etype = random.choice(['auto', 'user', 'admin'])
                        point_value = random.randint(-10, 10)
                        net_points += point_value
                        if len(_users) > 0 and etype == 'auto':
                            endorser_id = random.choice(_users).user_id
                        else:
                            endorser_id = None
                        issued_when = util.epoch(
                            Datetime(locale).datetime().replace(
                                tzinfo=EASTERN))
                        session.add(
                            models.DBEndorsement(endorsee=db_user,
                                                 endorser_id=endorser_id,
                                                 archive=archive,
                                                 subject_class=subject_class,
                                                 flag_valid=1,
                                                 endorsement_type=etype,
                                                 point_value=point_value,
                                                 issued_when=issued_when))

                    session.add(db_password)
                    session.add(db_nick)
                    session.add(db_profile)
                    _users.append(db_user)
                    _domain_users.append(
                        (domain.User(user_id=str(db_user.user_id),
                                     username=db_nick.nickname,
                                     email=db_user.email,
                                     name=domain.UserFullName(
                                         forename=db_user.first_name,
                                         surname=db_user.last_name,
                                         suffix=db_user.suffix_name),
                                     verified=bool(
                                         db_user.flag_email_verified)),
                         domain.Authorizations(
                             classic=util.compute_capabilities(db_user), )))
                    session.commit()
                    # We'll use these data to run tests.
                    cls.users.append((
                        email,
                        username,
                        password,
                        name,
                        (archive, subject_class, net_points),
                        (approved, deleted, banned),
                    ))
def main():

    try:
        num_gen = int(sys.argv[1])
    except:
        num_gen = -1

    if len(sys.argv) < 2 or num_gen == -1:
        print(
            "Usage: python faker_customers_to_csv.py <INT: Number of Customers to generate>"
        )
        print("Exymple: python faker_customers_to_csv.py 10000")
        return

    # Generate Customers that are between 18 and 100 years old
    ls_dates = [
        fake_de.date_time_between(start_date="-100y",
                                  end_date="-18y",
                                  tzinfo=None) for i in range(0, num_gen)
    ]
    ls_dates.sort()

    ls_customer = []
    for i in range(0, len(ls_dates)):
        s_country = random_country()
        address = None
        person = None
        s_nationality = None
        if s_country == 'DE':
            address = Address('de')
            person = Person('de')
            s_nationality = 'Germany'
        elif s_country == 'AT':
            address = Address('de-at')
            person = Person('de-at')
            s_nationality = 'Austria'
        else:
            address = Address('de-ch')
            person = Person('de-ch')
            s_nationality = 'Switzerland'

        s_sex = random_mf_flag()
        gender = mimesis.enums.Gender.FEMALE if s_sex == 'F' else mimesis.enums.Gender.MALE
        s_first_name = person.name(gender)
        s_last_name = person.last_name(gender)
        s_marital_status = random_marital_status_flag()
        s_job = person.occupation()
        s_email = person.email()
        s_phone = person.telephone()
        i_number_children = random.randint(0, 4)
        s_address_street = address.address()
        s_address_zip = address.postal_code()
        s_address_city = address.city()

        t_customer = (customer_number(i), s_sex, s_first_name, s_last_name,
                      s_job, s_email, s_phone, i_number_children,
                      s_marital_status, ls_dates[i].replace(hour=0,
                                                            minute=0,
                                                            second=0,
                                                            microsecond=0),
                      s_address_street, s_address_zip, s_address_city,
                      s_country, s_nationality)
        ls_customer.append(t_customer)

    ls_columns = [
        'customer_id', 'gender', 'first_name', 'last_name', 'job', 'email',
        'phone', 'number_children', 'marital_status', 'date_of_birth',
        'street', 'zip', 'city', 'country_code', 'nationality'
    ]

    df_customer = pd.DataFrame(ls_customer, columns=ls_columns)

    df_customer.to_csv('output/customers__de_at_ch.csv',
                       sep=',',
                       index=False,
                       header=ls_columns)
Example #30
0
    noise = noise_ampl*np.random.normal(0.01, 1.7, df.shape[0])
    gated_age = np.heaviside(df[age] - min_age, 0.5) - np.heaviside(df[age] - max_age, 0.5)
    return 0.01*pow(np.abs(df[age] - 30), 2.5) + df[age] + 50*df[marketing_level]*gated_age + 2*df[account_balance] + noise


##################################################

##################################################
### Generate a DataFrame of user information
##################################################
# Generate 10,000 rows of the following:
# user_id, first_name, last_name, email, password, address,
# birth_date, credit_card_num, credit_card_exp, security_answer,
# account_balance

user_df = pd.DataFrame([[x, person.name(), person.surname(), person.gender(),
                        person.email(), hashed_passwd(person.password()),
                        address.address(), person.age(),
                        payment.credit_card_number(),
                        payment.credit_card_expiration_date(), text.word(),
                        account_balance(), np.random.randint(1, 11)]
                        for x in range(10000)])

user_df.columns = ["user_id", "first_name", "last_name",
                   "gender", "email", "password_hashed", "address",
                   "age", "credit_card_num", "credit_card_exp",
                   "security_answer", "account_balance",
                   "marketing_level"]

# Generate sales, based on a noisy linear model
user_df['sales'] = generate_sales(user_df)