Last active
September 21, 2015 19:28
-
-
Save mvidalgarcia/01761bfdb3633c2efe00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import uniform, randint | |
import time | |
import json | |
__author__ = 'mvidalgarcia' | |
current_milli_time = lambda: int(round(time.time() * 1000)) | |
cat_description = [ | |
{'category_id': 2, 'description': "OMG I lost my pocket. Somebody robbed me"}, | |
{'category_id': 1, 'description': "My sister was abducted for a few hours. Do not go close to this zone."}, | |
{'category_id': 4, 'description': "I saw a street fight there. It was incredible. I advise you avoiding this zone."}, | |
{'category_id': 5, 'description': "A computer had exploded and the Computer Science School began to burn."}, | |
{'category_id': 6, 'description': "My laptop was violently robbed by an angry teacher in the Computer Science School. Be careful wandering this area."}, | |
{'category_id': 3, 'description': "I found my front door broken and all my personal belongings disappeared. Jesus Christ, damn thieves!"} | |
] | |
coord_limits = [ | |
{'city': 'madrid', 'minlat': 40.45, 'maxlat': 40.38, 'minlng': -3.781377, 'maxlng': -3.633188}, | |
{'city': 'barcelona', 'minlat': 41.416678, 'maxlat': 41.358723, 'minlng': 2.121302, 'maxlng': 2.227045}, | |
{'city': 'sevilla', 'minlat': 37.35, 'maxlat': 37.405922, 'minlng': -6.018656, 'maxlng': -5.96}, | |
{'city': 'bilbao', 'minlat': 43.252635, 'maxlat': 43.271198, 'minlng': -2.955709, 'maxlng': -2.915969}, | |
{'city': 'valladolid', 'minlat': 41.611834, 'maxlat': 41.669820, 'minlng': -4.772292, 'maxlng': -4.689208}, | |
{'city': 'valencia', 'minlat': 39.423598, 'maxlat': 39.498876, 'minlng': -0.420972, 'maxlng': -0.333082}, | |
] | |
coords_global = { | |
'big_square': {'minlat': 37.164129, 'maxlat': 43.272624, 'minlng': -8.543806, 'maxlng': -2.1103922}, | |
'medium_square': {'minlat': 38.835196, 'maxlat': 43.204540, 'minlng': -2.111942, 'maxlng': -0.463787}, | |
'small_square': {'minlat': 40.869929, 'maxlat': 43.204540, 'minlng': -0.463787, 'maxlng': 0.563645}, | |
'tiny_square': {'minlat': 41.257259, 'maxlat': 42.678052, 'minlng': 0.769131, 'maxlng': 2.803446} | |
} | |
def generate(id_min, id_max, type='cities'): | |
result = [] | |
for identifier in range(id_min, id_max): | |
index_desc = randint(0, len(cat_description)-1) | |
if type is 'cities': | |
index_coords = randint(0, len(coord_limits)-1) | |
limits = coord_limits[index_coords] | |
elif type is 'global': | |
ponderation = randint(1, 15) | |
if ponderation <= 9: | |
limits = coords_global['big_square'] | |
elif ponderation <= 12: | |
limits = coords_global['medium_square'] | |
elif ponderation <= 14: | |
limits = coords_global['small_square'] | |
else: | |
limits = coords_global['tiny_square'] | |
lat = uniform(limits['minlat'], limits['maxlat']) | |
lng = uniform(limits['minlng'], limits['maxlng']) | |
result.append({ | |
'category_id': cat_description[index_desc]['category_id'], | |
'description': cat_description[index_desc]['description'], | |
'lat': lat, | |
'lng': lng, | |
'time': current_milli_time(), | |
'user_id': randint(1, 2), | |
'id': identifier | |
}) | |
json_result = json.dumps(result) | |
print(json_result) | |
generate(15, 50) | |
generate(51, 1000, type='global') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment