Skip to content

Instantly share code, notes, and snippets.

@kdeloach
Forked from jwalgran/make_random_surveys.py
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdeloach/e54dedd76dd8322aab71 to your computer and use it in GitHub Desktop.
Save kdeloach/e54dedd76dd8322aab71 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from random import SystemRandom
from django.core.management.base import BaseCommand
from django.db import transaction
from apps.core.models import User
from apps.survey.models import Survey, Blockface
def _create_surveys(user, min_id, max_id, num):
r = SystemRandom()
created = 0
for x in xrange(num):
id = r.randint(min_id, max_id)
try:
b = Blockface.objects.get(pk=id)
Survey.objects.create(
user=user, blockface=b, has_trees=False,
is_left_side=False,
is_mapped_in_blockface_polyline_direction=False)
created = created + 1
except Blockface.DoesNotExist:
pass
return created
class Command(BaseCommand):
"""
Print the id of any Survey that triggers and exception when
running the "geometry constructor."
Usage:
./manage.py find_invalid_surveys
"""
@transaction.atomic
def handle(self, *args, **options):
u = User.objects.get(pk=1)
print(_create_surveys(u, 100000, 199999, 5000))
print(_create_surveys(u, 200000, 299999, 10000))
print(_create_surveys(u, 300000, 399999, 3000))
print(_create_surveys(u, 400000, 499999, 20000))
print(_create_surveys(u, 500000, 599999, 500))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment