Skip to content

Commit

Permalink
Changed the alert to a side bar so it's always there. That will be me…
Browse files Browse the repository at this point in the history
…rged to master even if other features on this one don't work out. Really close with the lines implementation, literally one stumbling block. I have a list of strings, I need a list of sets. If I try to convert it, it treats every character as an index to add... so too many sets.
  • Loading branch information
shmink committed Sep 30, 2016
1 parent d0f11de commit b8fa8e4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 16 deletions.
15 changes: 13 additions & 2 deletions simplemap/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ZOOM_DEFAULT = 11

class Map(object):
def __init__(self, title, center=None, zoom=11, markers=None, message=None, html_template='basic.html', config_file='config.json'):
def __init__(self, title, center=None, zoom=11, markers=None, message=None, points=None, html_template='basic.html', config_file='config.json'):
self._env = Environment(loader=TEMPLATES_DIR, trim_blocks=True, undefined=SilentUndefined)
self.title = title
self.template = self._env.get_template(html_template)
Expand All @@ -28,6 +28,8 @@ def __init__(self, title, center=None, zoom=11, markers=None, message=None, html
self.markers = markers
# message added in.
self.message = message
# points for lines added in
self.points = points

def set_center(self, center_point):
self._center = '{{ lat:{}, lng:{}}}'.format(*center_point) if center_point else 'null'
Expand All @@ -48,6 +50,13 @@ def set_message(self, message):
def get_message(self):
return self._message

# Points setter and getter
def set_points(self, points):
self._points = points

def get_points(self):
return self._points

def get_zoom(self):
return self._zoom

Expand Down Expand Up @@ -83,11 +92,13 @@ def get_markers(self):
zoom = property(get_zoom, set_zoom)
# Declare the names of the setter and getters
message = property(get_message, set_message)
# Declare the names of the setter and getters
points = property(get_points, set_points)

def write(self, output_path):
try:
html = self.template.render(map_title = self.title, center=self.center,
zoom=self.zoom, markers=self.markers, message=self.message, api_key=self.config['api_key'])
zoom=self.zoom, markers=self.markers, message=self.message, points=self.points, api_key=self.config['api_key'])
with open(output_path, "w") as out_file:
out_file.write(html)
return 'file://' + os.path.join(os.path.abspath(os.curdir), output_path)
Expand Down
Binary file modified simplemap/map.pyc
Binary file not shown.
17 changes: 12 additions & 5 deletions simplemap/templates/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@
<link rel="stylesheet" href="simplemap/templates/static/css/basic.css">
</head>
<body>
<div id="sidebar">
<h2>Waypointer</h2>
<!--<p>Sequence:</p>
<p>Date:</p>
<p>UUID:</p>-->
<p>{{ message|safe }}</p>
</div>
<div id="map"></div>
<script>

function initMap() {

var message = "{{ message|safe }}";
/*var message = "{{ message|safe }}";
//If a message has been added to the alert system be sure to write it.
if (message) {
alert(message);
}
}*/

var bounds = new google.maps.LatLngBounds();
var center_lat_lon = {{center|safe}};
Expand All @@ -27,11 +34,13 @@
});

var markers = {{ markers|safe }};
//points need to be {lon:5.4..., lng:6.342...}
var points = {{ points|safe }}

//Doing this on the 'lines' branch
//Draw a line from point to point, not working currently.
var flightPath = new google.maps.Polyline({
path: markers,
path: points,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
Expand All @@ -56,8 +65,6 @@

{{ 'map.fitBounds(bounds);' if center == 'null' else '' }}
}


</script>
<script src="https://maps.googleapis.com/maps/api/js?key={{ api_key }}&signed_in=true&callback=initMap"
async defer></script>
Expand Down
6 changes: 6 additions & 0 deletions simplemap/templates/static/css/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ html, body {
#map {
height: 100%;
width: 80%;
}

#sidebar {
float:right;
margin-right: 1%;
overflow: auto;
}
37 changes: 28 additions & 9 deletions waypointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Add an optional alert message to the html file
alert = ''


# In an effor to make this system more modular the user passes in a sequence number and table for the waypoints.
# this is that argument system. It still doesn't seem right to me but I've tested it enough that it works.
if __name__ == '__main__':
Expand Down Expand Up @@ -54,21 +55,18 @@ def get_coordinates(database):
# Due to the nature of the way the data is extracted from the SQL table
# this dirty data manipulation has to happen. It's just not elegant :(
totalsequences = int(str(c.fetchone()).translate(None, "(),"))
# Print out some info extra information. Hoping to make this better for user in future.
print '\nFrom the table with the UUID:', uuid, '\nthere are a total of', totalsequences, 'sequences.\n'
# Check the sequence number from user against total amount of sequences.
if (int(sequence) < totalsequences):
if (int(sequence) < (totalsequences + 1)):
# sqlite3 library documentation says it's more 'secure' to insert values into querys like so.
t = (sequence,)
c.execute('SELECT ZWP_WP_NR, ZWP_LAT, ZWP_LON FROM ZWAYPOINT WHERE ZMSD_SEQUENCE_NUMBER = ?;', t)
c.execute('SELECT ZWP_WP_NR, ZWP_LAT, ZWP_LON FROM ZWAYPOINT WHERE ZMSD_SEQUENCE_NUMBER = ? ORDER BY ZWP_WP_NR ASC;', t)
# Get the results of the query.
coordinates = c.fetchall()
# Again another issue, this time with data types. The sql query spits out a list of tuples.
# the google maps api wants a list of lists....
# We also want the waypoint number in there so you can hover over waypoint in the html file
for x in range(0, len(coordinates)):
coordinates[x] = list(coordinates[x])

for x in range(0, len(coordinates)):
coordinates[x][0] = str(coordinates[x][0])
# Finally return the results to wherever this function was called from
return coordinates
Expand Down Expand Up @@ -100,14 +98,25 @@ def get_alert(database):
timeinseconds = float(timeinsecondsStr)
#from import datetime library you can simply convert seconds elapsed from 1/1/1970 to get a date. Which is what we are doing here.
date = datetime.fromtimestamp(timeinseconds)
print 'Sequence:', str(sequence), '\nFlown on:', date, '\nUUID:', uuid
# Finally we return the string of relevant info that'll eventually be inserted into the alert box.
get_alertOutput = "Sequence: " + str(sequence) + ", Flown on: " + str(date) + ", UUID: " + str(uuid)
get_alertOutput = "Sequence: " + str(sequence) + "<br>Flown on: " + str(date) + "<br>UUID: " + str(uuid)
return get_alertOutput
except:
return 'Could not retrieve either UUID or date from database.'


def make_points(coords):
if(coords):
for x in range(0, len(coords)):
coords[x].pop(0)
#coords[x] = str(coords[x])
coords[x] = str(coords[x]).replace("[", "{lat: ").replace(",", ", lng:").replace("]", "}")
#coords[x].replace(",", ", lng:")
#coords[x].replace("]", "}")
print '\n', coords[x]
return coords



##################################################
# #
Expand All @@ -122,9 +131,19 @@ def get_alert(database):
# This gets the information to display in the alert pop up box
alert = get_alert(db)


#Test
plots = make_points(get_coordinates(db))

print plots

#print plots[0]
#print type(plots[0])
#print str(plots[0]).replace("[", "{lat: ").replace(",", ", lng:").replace("]", "}")

# Here we generate the html page by passing the above
# information to the relevant files
example_map = simplemap.Map(map_title, markers=gps_markers, message=alert)
example_map = simplemap.Map(map_title, markers=gps_markers, message=alert, points=plots)
# We also need a name for the html file that's being outputted
example_map.write('sequence' + str(sequence) + '.html')

Expand Down

0 comments on commit b8fa8e4

Please sign in to comment.