-
Notifications
You must be signed in to change notification settings - Fork 13
/
generate_random_users.py
52 lines (42 loc) · 1.89 KB
/
generate_random_users.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import numpy as np
import random
import uuid
from django.core.management.base import BaseCommand
from django.contrib.gis.geos import Point
from api.models import DjTinderUser, get_opposed_sex
class Command(BaseCommand):
help = 'generate 1M users for Warsaw with random ' \
'sex, age, orientation, radius, location'
def add_arguments(self, parser):
parser.add_argument('count', type=int)
def handle(self, *args, **options):
count = options['count']
warsaw__lat__min = 52.09
warsaw__lat__max = 52.31
warsaw__lng__min = 20.87
warsaw__lng__max = 21.17
for i in range(count):
new_random_lat = random.uniform(warsaw__lat__min, warsaw__lat__max)
new_random_lng = random.uniform(warsaw__lng__min, warsaw__lng__max)
user_age = random.randrange(18, 55)
user_delta_plus = random.choice([1, 2, 3, 5, 8, 13])
user_delta_minus = random.choice([1, 2, 3, 5, 8, 13])
user_sex = random.choice(['F', 'M'])
sexual_orientation = ['hetero', 'homo']
chosen_at_random_sexual_orientation = np.random.choice(
sexual_orientation, p=[0.95, 0.05])
if chosen_at_random_sexual_orientation == 'homo':
user_preferred_sex = user_sex
else:
user_preferred_sex = get_opposed_sex(user_sex)
DjTinderUser.objects.create(
nickname=str(uuid.uuid4()),
age=user_age,
sex=user_sex,
preferred_sex=user_preferred_sex,
preferred_age_min=(user_age-user_delta_minus),
preferred_age_max=(user_age+user_delta_plus),
last_location=Point(float(new_random_lng),
float(new_random_lat)),
preferred_radius=random.choice([5, 10, 15, 20, 25, 30])
)