How to create a randomly generated user profile within a city boundary in Geodjango?

119 Views Asked by At

Disclaimer: I have limited knowledge in python.I asked this question in gis.stackexchange, but was voted "unclear what you are asking", may be because it is a programming question, not gis?

I have used randomly generate users python script from this source , while the command creates a postgis table, it does not create the randomly generate user profile (the table is empty). What is missing in creating the random user profile in the postgis table?

from django.core.management.base import BaseCommand
from django.contrib.gis.geos import Point
import random
import uuid
import numpy as np
from mymap_app.models import LoveFinderUser


class Command(BaseCommand):
    help = 'generate 1M users for Addis_Ababa with random sex, age, radius, location'

    def handle(self, *args, **options):
        Addis_Ababa__lat__min = 8.834544
        Addis_Ababa__lat__max = 9.099231
        Addis_Ababa__lng__min = 38.640241
        Addis_Ababa__lng__max = 38.907086

        for i in xrange(10**5):
            new_random_lat = random.uniform(Addis_Ababa__lat__min, Addis_Ababa__lat__max)
            new_random_lng = random.uniform(Addis_Ababa__lng__min, Addis_Ababa__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'])
            user_prefered_sex=random.choice(['F', 'M'])

            new_user=LoveFinderUser.objects.create(
                nickname=str(uuid.uuid4()),
                age=user_age,
                sex=user_sex,
                prefered_sex=user_prefered_sex,
                prefered_age_min=(user_age-user_delta_minus),
                prefered_age_max=(user_age+user_delta_plus),
                last_location=Point(float(new_random_lng), float(new_random_lat)),
                prefered_radius=random.choice([5, 10, 15, 20, 25, 30])
            )
            new_user.save()
1

There are 1 best solutions below

0
On

Thanks to @HåkenLid. I used the command from the project directory: (myvenv_python3)C:\Users\Kaleab\Desktop\myproject> django-admin generate_1M_LL_users and it worked, also i had to change xrange to range.