2022-09-24 21:44:00 +02:00
|
|
|
# !/usr/bin/python
|
|
|
|
|
2022-09-24 22:01:03 +02:00
|
|
|
|
2022-09-24 21:44:00 +02:00
|
|
|
from math import radians, cos, sin, asin, sqrt
|
|
|
|
import numpy as np
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import json
|
|
|
|
from time import strftime
|
|
|
|
import random
|
|
|
|
|
|
|
|
# haversine function to determine distance between two lat,long points
|
2022-09-24 21:45:42 +02:00
|
|
|
|
|
|
|
|
2022-09-24 21:44:00 +02:00
|
|
|
def haversine(lat1, lon1, lat2, lon2):
|
2022-09-24 21:45:42 +02:00
|
|
|
R = 3959.87433 # earth radius in miles
|
|
|
|
dLat = radians(lat2 - lat1)
|
|
|
|
dLon = radians(lon2 - lon1)
|
|
|
|
a = sin(dLat/2)**2 + cos(lat1)*cos(lat2)*sin(dLon/2)**2
|
|
|
|
c = 2*asin(sqrt(a))
|
|
|
|
return R*c
|
2022-09-24 21:44:00 +02:00
|
|
|
|
|
|
|
# get a random enough number
|
2022-09-24 21:45:42 +02:00
|
|
|
|
|
|
|
|
2022-09-24 21:44:00 +02:00
|
|
|
def getfloat():
|
2022-09-24 21:45:42 +02:00
|
|
|
output = random.random()
|
|
|
|
return output
|
|
|
|
|
2022-09-24 21:44:00 +02:00
|
|
|
|
|
|
|
def str_time_prop(start, end, format, prop):
|
2022-09-24 21:45:42 +02:00
|
|
|
# get a time at a proportion of a range of two formatted times
|
|
|
|
stime = start
|
|
|
|
etime = end
|
|
|
|
ptime = stime + prop * (etime - stime)
|
2022-09-24 21:44:00 +02:00
|
|
|
|
2022-09-24 21:45:42 +02:00
|
|
|
return time.strftime(format, time.localtime(ptime))
|
2022-09-24 21:44:00 +02:00
|
|
|
|
|
|
|
# get random time in the future
|
2022-09-24 21:45:42 +02:00
|
|
|
|
|
|
|
|
2022-09-24 21:44:00 +02:00
|
|
|
def random_date(start, end, prop):
|
2022-09-24 21:45:42 +02:00
|
|
|
return str_time_prop(start, end, '%m/%d/%Y %I:%M%p', prop)
|
2022-09-24 21:44:00 +02:00
|
|
|
|
|
|
|
# function to generate a lat,long coordinate within a range
|
|
|
|
# inspiration from this post:
|
|
|
|
# https://gis.stackexchange.com/questions/25877/generating-random-locations-nearby
|
2022-09-24 21:45:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def create_random_point(x0, y0, distance):
|
|
|
|
# approximately 1609 meters in a mile
|
|
|
|
# 5 miles = about 8045
|
|
|
|
# 111300 = meters in a degree
|
|
|
|
# 69 = miles in a degree
|
|
|
|
r = distance / 111300
|
|
|
|
r = r/2
|
|
|
|
u = float(getfloat())
|
|
|
|
v = float(getfloat())
|
|
|
|
w = r * np.sqrt(u)
|
|
|
|
t = 2 * np.pi * v
|
|
|
|
x = w * np.cos(t)
|
|
|
|
x1 = x / np.cos(y0)
|
|
|
|
y = w * np.sin(t)
|
2022-09-24 22:01:03 +02:00
|
|
|
print("u="+str(u))
|
|
|
|
print("v="+str(v))
|
2022-09-24 21:45:42 +02:00
|
|
|
return (x0+x1, y0+y)
|
2022-09-24 21:44:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
init_start = time.time()
|
|
|
|
dtime = strftime("%m-%d-%Y %H:%M:%S")
|
|
|
|
newplot = ()
|
|
|
|
|
|
|
|
##### User defined variables #####
|
|
|
|
|
|
|
|
loghandle = './naut.log'
|
|
|
|
logfile = open(loghandle, "a")
|
|
|
|
|
2022-09-24 21:45:42 +02:00
|
|
|
# home_base (starting point), set to Warsaw center.
|
|
|
|
latitude1, longitude1 = 52.229832, 21.011734
|
2022-09-24 21:44:00 +02:00
|
|
|
|
|
|
|
#window_secs = 10800
|
|
|
|
window_secs = 1800
|
|
|
|
|
2022-09-24 21:45:42 +02:00
|
|
|
# how far to travel in meters from home base
|
2022-09-24 21:44:00 +02:00
|
|
|
meters_out = 4827
|
|
|
|
|
|
|
|
##### End User Defined variables #####
|
|
|
|
|
|
|
|
current_time = time.time()
|
|
|
|
window = current_time + window_secs
|
|
|
|
|
|
|
|
# for loop to get multiple points if desired (for future development - void/attractor calculations)
|
2022-09-24 21:45:42 +02:00
|
|
|
for i in range(1, 2):
|
|
|
|
timex = float(getfloat())
|
|
|
|
x, y = create_random_point(latitude1, longitude1, meters_out)
|
|
|
|
future_time = random_date(current_time, window, timex)
|
|
|
|
dest_lat = str(format(x, '.5f'))
|
|
|
|
dest_long = str(format(y, '.5f'))
|
|
|
|
orig_lat = str(latitude1)
|
|
|
|
orig_long = str(longitude1)
|
|
|
|
newplot = (x, y)
|
|
|
|
origplot = (latitude1, longitude1)
|
|
|
|
dist = haversine(origplot[0], origplot[1], newplot[0], newplot[1])
|
|
|
|
dist = str(format(dist, '.2f'))
|
2022-09-24 22:01:03 +02:00
|
|
|
print("Distance between points is ", dist)
|
|
|
|
print("destination: "+dest_lat+" "+dest_long)
|
|
|
|
print("future_time: "+future_time)
|
2022-09-24 21:45:42 +02:00
|
|
|
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_space = '`'
|
|
|
|
msg_space2 = '```'
|
|
|
|
# homage to the Matrix
|
|
|
|
init1_msg = 'Wake up, Neo...'
|
|
|
|
init_msg = 'The Matrix has you..'
|
|
|
|
rabbit_msg1 = 'follow the'
|
|
|
|
rabbit_msg2 = 'white rabbit...'
|
|
|
|
|
|
|
|
logfile.write("\n")
|
2022-09-24 22:01:03 +02:00
|
|
|
print(init1_msg)
|
2022-09-24 21:45:42 +02:00
|
|
|
time.sleep(5)
|
2022-09-24 22:01:03 +02:00
|
|
|
print(msg_breaker)
|
|
|
|
print(init_msg)
|
2022-09-24 21:45:42 +02:00
|
|
|
time.sleep(5)
|
2022-09-24 22:01:03 +02:00
|
|
|
print(msg_breaker)
|
|
|
|
print(rabbit_msg1)
|
|
|
|
print(msg_breaker)
|
|
|
|
print(msg_space2)
|
|
|
|
print(rabbit_msg2)
|
2022-09-24 21:45:42 +02:00
|
|
|
time.sleep(5)
|
2022-09-24 22:01:03 +02:00
|
|
|
print(msg_breaker)
|
|
|
|
print(" "+future_time)
|
|
|
|
print(msg_breaker)
|
|
|
|
print(" "+dest_lat)
|
|
|
|
print(msg_space)
|
|
|
|
print(dest_long)
|
|
|
|
print("https://www.google.com/maps/search/?api=1&query="+dest_lat+","+dest_long+" Time: "+future_time)
|