autopep8, the formatting was all over the place to the point where it wouldn't run
Signed-off-by: Abdulkadir Furkan Şanlı <me@abdulocra.cy>
This commit is contained in:
parent
711c2ee938
commit
366de19017
48
naut.py
48
naut.py
@ -11,8 +11,10 @@ from time import strftime
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
# haversine function to determine distance between two lat,long points
|
# haversine function to determine distance between two lat,long points
|
||||||
|
|
||||||
|
|
||||||
def haversine(lat1, lon1, lat2, lon2):
|
def haversine(lat1, lon1, lat2, lon2):
|
||||||
R = 3959.87433 #earth radius in miles
|
R = 3959.87433 # earth radius in miles
|
||||||
dLat = radians(lat2 - lat1)
|
dLat = radians(lat2 - lat1)
|
||||||
dLon = radians(lon2 - lon1)
|
dLon = radians(lon2 - lon1)
|
||||||
a = sin(dLat/2)**2 + cos(lat1)*cos(lat2)*sin(dLon/2)**2
|
a = sin(dLat/2)**2 + cos(lat1)*cos(lat2)*sin(dLon/2)**2
|
||||||
@ -20,12 +22,15 @@ def haversine(lat1, lon1, lat2, lon2):
|
|||||||
return R*c
|
return R*c
|
||||||
|
|
||||||
# get a random enough number
|
# get a random enough number
|
||||||
|
|
||||||
|
|
||||||
def getfloat():
|
def getfloat():
|
||||||
output = random.random()
|
output = random.random()
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def str_time_prop(start, end, format, prop):
|
def str_time_prop(start, end, format, prop):
|
||||||
#get a time at a proportion of a range of two formatted times
|
# get a time at a proportion of a range of two formatted times
|
||||||
stime = start
|
stime = start
|
||||||
etime = end
|
etime = end
|
||||||
ptime = stime + prop * (etime - stime)
|
ptime = stime + prop * (etime - stime)
|
||||||
@ -33,15 +38,19 @@ def str_time_prop(start, end, format, prop):
|
|||||||
return time.strftime(format, time.localtime(ptime))
|
return time.strftime(format, time.localtime(ptime))
|
||||||
|
|
||||||
# get random time in the future
|
# get random time in the future
|
||||||
|
|
||||||
|
|
||||||
def random_date(start, end, prop):
|
def random_date(start, end, prop):
|
||||||
return str_time_prop(start, end, '%m/%d/%Y %I:%M%p', prop)
|
return str_time_prop(start, end, '%m/%d/%Y %I:%M%p', prop)
|
||||||
|
|
||||||
# function to generate a lat,long coordinate within a range
|
# function to generate a lat,long coordinate within a range
|
||||||
# inspiration from this post:
|
# inspiration from this post:
|
||||||
# https://gis.stackexchange.com/questions/25877/generating-random-locations-nearby
|
# https://gis.stackexchange.com/questions/25877/generating-random-locations-nearby
|
||||||
def create_random_point(x0,y0,distance):
|
|
||||||
#approximately 1609 meters in a mile
|
|
||||||
#5 miles = about 8045
|
def create_random_point(x0, y0, distance):
|
||||||
|
# approximately 1609 meters in a mile
|
||||||
|
# 5 miles = about 8045
|
||||||
# 111300 = meters in a degree
|
# 111300 = meters in a degree
|
||||||
# 69 = miles in a degree
|
# 69 = miles in a degree
|
||||||
r = distance / 111300
|
r = distance / 111300
|
||||||
@ -67,13 +76,13 @@ newplot = ()
|
|||||||
loghandle = './naut.log'
|
loghandle = './naut.log'
|
||||||
logfile = open(loghandle, "a")
|
logfile = open(loghandle, "a")
|
||||||
|
|
||||||
#home_base (starting point), set to Warsaw center.
|
# home_base (starting point), set to Warsaw center.
|
||||||
latitude1, longitude1 = 52.229832,21.011734
|
latitude1, longitude1 = 52.229832, 21.011734
|
||||||
|
|
||||||
#window_secs = 10800
|
#window_secs = 10800
|
||||||
window_secs = 1800
|
window_secs = 1800
|
||||||
|
|
||||||
#how far to travel in meters from home base
|
# how far to travel in meters from home base
|
||||||
meters_out = 4827
|
meters_out = 4827
|
||||||
|
|
||||||
##### End User Defined variables #####
|
##### End User Defined variables #####
|
||||||
@ -82,27 +91,28 @@ current_time = time.time()
|
|||||||
window = current_time + window_secs
|
window = current_time + window_secs
|
||||||
|
|
||||||
# for loop to get multiple points if desired (for future development - void/attractor calculations)
|
# for loop to get multiple points if desired (for future development - void/attractor calculations)
|
||||||
for i in range(1,2):
|
for i in range(1, 2):
|
||||||
timex = float(getfloat())
|
timex = float(getfloat())
|
||||||
x,y = create_random_point(latitude1,longitude1, meters_out)
|
x, y = create_random_point(latitude1, longitude1, meters_out)
|
||||||
future_time = random_date(current_time, window, timex)
|
future_time = random_date(current_time, window, timex)
|
||||||
dest_lat = str(format(x,'.5f'))
|
dest_lat = str(format(x, '.5f'))
|
||||||
dest_long = str(format(y,'.5f'))
|
dest_long = str(format(y, '.5f'))
|
||||||
orig_lat = str(latitude1)
|
orig_lat = str(latitude1)
|
||||||
orig_long = str(longitude1)
|
orig_long = str(longitude1)
|
||||||
newplot = (x,y)
|
newplot = (x, y)
|
||||||
origplot = (latitude1,longitude1)
|
origplot = (latitude1, longitude1)
|
||||||
dist = haversine(origplot[0],origplot[1],newplot[0],newplot[1])
|
dist = haversine(origplot[0], origplot[1], newplot[0], newplot[1])
|
||||||
dist = str(format(dist,'.2f'))
|
dist = str(format(dist, '.2f'))
|
||||||
print "Distance between points is ",dist
|
print "Distance between points is ", dist
|
||||||
print "destination: "+dest_lat+" "+dest_long
|
print "destination: "+dest_lat+" "+dest_long
|
||||||
print "future_time: "+future_time
|
print "future_time: "+future_time
|
||||||
logfile.write(dtime+" homebase_lat="+orig_lat+" homebase_long="+orig_long+" dest_lat="+dest_lat+" dest_long="+dest_long+" future_time="+future_time+" dist="+dist)
|
logfile.write(dtime+" homebase_lat="+orig_lat+" homebase_long="+orig_long+" dest_lat=" +
|
||||||
|
dest_lat+" dest_long="+dest_long+" future_time="+future_time+" dist="+dist)
|
||||||
|
|
||||||
msg_breaker = '~'
|
msg_breaker = '~'
|
||||||
msg_space = '`'
|
msg_space = '`'
|
||||||
msg_space2 = '```'
|
msg_space2 = '```'
|
||||||
#homage to the Matrix
|
# homage to the Matrix
|
||||||
init1_msg = 'Wake up, Neo...'
|
init1_msg = 'Wake up, Neo...'
|
||||||
init_msg = 'The Matrix has you..'
|
init_msg = 'The Matrix has you..'
|
||||||
rabbit_msg1 = 'follow the'
|
rabbit_msg1 = 'follow the'
|
||||||
|
Loading…
Reference in New Issue
Block a user