Skip to content

Instantly share code, notes, and snippets.

@sillyfellow
Created July 29, 2015 15:29
Show Gist options
  • Save sillyfellow/d3f7c4b3a209c11c4733 to your computer and use it in GitHub Desktop.
Save sillyfellow/d3f7c4b3a209c11c4733 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import numpy as np
from random import randint
def gen_points(a, b, num_divisions):
if num_divisions == 0:
return [a]
xdiff = b[0] - a[0]
ydiff = b[1] - a[1]
if (xdiff == 0) and (ydiff == 0):
return [a]
xs = np.arange(a[0], b[0], xdiff / num_divisions) if xdiff != 0 else [a[0]] * num_divisions
ys = np.arange(a[1], b[1], ydiff / num_divisions) if ydiff != 0 else [a[1]] * num_divisions
return zip([float("{0:.8f}".format(x)) for x in xs], [float("{0:.8f}".format(y)) for y in ys])
def cons(list, count):
if count <= 0:
count = 1
for i in range(len(list) - count + 1):
yield list[i: i+count]
def move_coords(new_origin, coordinates):
return [(new_origin[0] + x[0], new_origin[1] + x[1]) for x in coordinates]
def altitude():
return randint(10, 30)
def time_offset():
now = 0
while True:
now = now + randint(40, 60)
yield now
def divide_by_ten(pair):
return (0.1 * pair[0], 0.1 * pair[1])
area_x_boundaries = [(0, 1.0), (1.0, 3.0), (3.0, 5.0)]
area_x_boundaries = [divide_by_ten(x) for x in area_x_boundaries]
coordinates = [ (1.5, 2.8), (0.8, 2.3), (0.5, 2), (0.8, 1.9), (1.2, 1.8), (2, 1.7), (2.5, 1.6), (3.2, 1.5), (3.6, 1.4), (3.5, 1.3), (3, 1.2), (2.4, 1.1), (1.8, 1.0), (1.8, 1), (1, 1), (0.6, 0.9)]
coordinates = [divide_by_ten(x) for x in coordinates] # we need to make them smaller
origin = (50, 12)
new_coords = move_coords(origin, coordinates)
points = [gen_points(x[0], x[1], 40) for x in cons(new_coords, 2)]
new_boundaries = [(x[0] + origin[0], x[1] + origin[0]) for x in area_x_boundaries]
# flatten
line = reduce(lambda x, y: x + y, points, [])
# add height and weight
with_height = zip([(x[0], x[1], altitude()) for x in line], time_offset())
with_time_added = [x[0] + (x[1],) for x in with_height]
records = []
for boundaries in new_boundaries:
records.append([point for point in with_time_added if (point[0] >= boundaries[0] and point[0] < boundaries[1])])
print "FAKE_TRACK_BIG = ", with_time_added
for record in records:
print ""
print "FAKE_TRACK_XX = ", record
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment