Working top map location for now()

pull/18/head
Sami Mokaddem 2017-10-25 17:32:06 +02:00
parent bffca0c20c
commit 7bc42377a3
2 changed files with 73 additions and 10 deletions

View File

@ -1,11 +1,12 @@
#!/usr/bin/env python3.5 #!/usr/bin/env python3.5
from flask import Flask, render_template, Response from flask import Flask, render_template, request, Response, jsonify
import json import json
import redis import redis
import random import random
import configparser import configparser
from time import gmtime as now from time import gmtime as now
from time import sleep, strftime from time import sleep, strftime
import datetime
import os import os
configfile = os.path.join(os.environ['VIRTUAL_ENV'], '../config.cfg') configfile = os.path.join(os.environ['VIRTUAL_ENV'], '../config.cfg')
@ -22,6 +23,10 @@ redis_server_map = redis.StrictRedis(
host=cfg.get('RedisMap', 'host'), host=cfg.get('RedisMap', 'host'),
port=cfg.getint('RedisMap', 'port'), port=cfg.getint('RedisMap', 'port'),
db=cfg.getint('RedisMap', 'db')) db=cfg.getint('RedisMap', 'db'))
serv_redis_db = redis.StrictRedis(
host=cfg.get('RedisDB', 'host'),
port=cfg.getint('RedisDB', 'port'),
db=cfg.getint('RedisDB', 'db'))
subscriber_log = redis_server_log.pubsub(ignore_subscribe_messages=True) subscriber_log = redis_server_log.pubsub(ignore_subscribe_messages=True)
subscriber_log.psubscribe(cfg.get('RedisLog', 'channel')) subscriber_log.psubscribe(cfg.get('RedisLog', 'channel'))
@ -86,6 +91,15 @@ class EventMessage():
to_ret = { 'log': self.feed, 'feedName': self.feedName, 'zmqName': self.zmqName } to_ret = { 'log': self.feed, 'feedName': self.feedName, 'zmqName': self.zmqName }
return 'data: {}\n\n'.format(json.dumps(to_ret)) return 'data: {}\n\n'.format(json.dumps(to_ret))
def getZrange(keyCateg, wantedDate, topNum):
aDateTime = datetime.datetime.now()
date_str = str(aDateTime.year)+str(aDateTime.month)+str(aDateTime.day)
keyname = "{}:{}".format(keyCateg, date_str)
data = serv_redis_db.zrange(keyname, 0, 5, desc=True, withscores=True)
return data
@app.route("/") @app.route("/")
def index(): def index():
ratioCorrection = 88 ratioCorrection = 88
@ -111,6 +125,29 @@ def index():
def geo(): def geo():
return render_template('geo.html') return render_template('geo.html')
@app.route("/_getTopCoord")
def getTopCoord():
try:
dayNum = int(request.args.get('dayNum'))
except:
dayNum = 1
keyCateg = "GEO_COORD"
topNum = 6 # default Num
data = getZrange(keyCateg, dayNum, topNum)
data = [ [record[0].decode('utf8'), record[1]] for record in data ]
return jsonify(data)
@app.route("/_getHitMap")
def getHitMap():
try:
dayNum = int(request.args.get('dayNum'))
except:
dayNum = 1
keyCateg = "GEO_COUNTRY"
topNum = -1 # default Num
data = getZrange(keyCateg, dayNum, topNum)
return jsonify(data)
@app.route("/_logs") @app.route("/_logs")
def logs(): def logs():
return Response(event_stream_log(), mimetype="text/event-stream") return Response(event_stream_log(), mimetype="text/event-stream")

View File

@ -86,7 +86,7 @@ small {
<div class="col-lg-6"> <div class="col-lg-6">
<div class="panel panel-default" style=""> <div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;"> <div class="panel-heading bg-info" style="font-weight: bold;">
<b id="topMap1Header">No map </b> <b id="topMap1Header">1. Top location</b>
</div> </div>
<div id="panelbody" class="panel-body" style=""> <div id="panelbody" class="panel-body" style="">
<div id="topMap1" style="width:100%; height: calc(75vh / 3);"></div> <div id="topMap1" style="width:100%; height: calc(75vh / 3);"></div>
@ -95,7 +95,7 @@ small {
<div class="panel panel-default" style=""> <div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;"> <div class="panel-heading bg-info" style="font-weight: bold;">
<b id="topMap3Header">No map </b> <b id="topMap3Header">3. Top location</b>
</div> </div>
<div id="panelbody" class="panel-body" style=""> <div id="panelbody" class="panel-body" style="">
<div id="topMap3" style="width:100%; height: calc(75vh / 3);"></div> <div id="topMap3" style="width:100%; height: calc(75vh / 3);"></div>
@ -104,7 +104,7 @@ small {
<div class="panel panel-default" style=""> <div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;"> <div class="panel-heading bg-info" style="font-weight: bold;">
<b id="topMap5Header">No map </b> <b id="topMap5Header">5. Top location</b>
</div> </div>
<div id="panelbody" class="panel-body" style=""> <div id="panelbody" class="panel-body" style="">
<div id="topMap5" style="width:100%; height: calc(75vh / 3);"></div> <div id="topMap5" style="width:100%; height: calc(75vh / 3);"></div>
@ -115,7 +115,7 @@ small {
<div class="col-lg-6"> <div class="col-lg-6">
<div class="panel panel-default" style=""> <div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;"> <div class="panel-heading bg-info" style="font-weight: bold;">
<b id="topMap2Header">No map </b> <b id="topMap2Header">2. Top location</b>
</div> </div>
<div id="panelbody" class="panel-body" style=""> <div id="panelbody" class="panel-body" style="">
<div id="topMap2" style="width:100%; height: calc(75vh / 3);"></div> <div id="topMap2" style="width:100%; height: calc(75vh / 3);"></div>
@ -124,7 +124,7 @@ small {
<div class="panel panel-default" style=""> <div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;"> <div class="panel-heading bg-info" style="font-weight: bold;">
<b id="topMap4Header">No map </b> <b id="topMap4Header">4. Top location</b>
</div> </div>
<div id="panelbody" class="panel-body" style=""> <div id="panelbody" class="panel-body" style="">
<div id="topMap4" style="width:100%; height: calc(75vh / 3);"></div> <div id="topMap4" style="width:100%; height: calc(75vh / 3);"></div>
@ -133,7 +133,7 @@ small {
<div class="panel panel-default" style=""> <div class="panel panel-default" style="">
<div class="panel-heading bg-info" style="font-weight: bold;"> <div class="panel-heading bg-info" style="font-weight: bold;">
<b id="topMap6Header">No map </b> <b id="topMap6Header">6. Top location</b>
</div> </div>
<div id="panelbody" class="panel-body" style=""> <div id="panelbody" class="panel-body" style="">
<div id="topMap6" style="width:100%; height: calc(75vh / 3);"></div> <div id="topMap6" style="width:100%; height: calc(75vh / 3);"></div>
@ -188,6 +188,7 @@ small {
const OSMURL='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; const OSMURL='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const OSMATTRIB='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'; const OSMATTRIB='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
var ZOOMLEVEL = 17;
var allOpenStreetMap = {}; var allOpenStreetMap = {};
for(var i=1; i<7; i++) { for(var i=1; i<7; i++) {
@ -195,7 +196,6 @@ small {
new L.TileLayer(OSMURL, {minZoom: 0, maxZoom: 18}).addTo(allOpenStreetMap[i]); new L.TileLayer(OSMURL, {minZoom: 0, maxZoom: 18}).addTo(allOpenStreetMap[i]);
} }
var vectorMapConfig = { var vectorMapConfig = {
map: 'world_mill', map: 'world_mill',
markers: [], markers: [],
@ -217,8 +217,34 @@ small {
}, },
} }
function updateTopMaps(dayNum) {
$.getJSON("{{ url_for('getTopCoord') }}?dayNum="+dayNum, function(list){
for(var i=0; i<6 && i<list.length; i++) {
coordJson = JSON.parse(list[i][0]);
allOpenStreetMap[i+1].flyTo([coordJson.lat, coordJson.lon], ZOOMLEVEL);
var marker = L.marker([coordJson.lat, coordJson.lon]).addTo(allOpenStreetMap[i+1]);
marker.bindPopup('lat: '+coordJson.lat+', lon: '+coordJson.lon+' - '+list[i][1]).openPopup();
}
});
}
function updateWorldMap(dateStart, dateEnd) {
$.getJSON("{{ url_for('getHitMap') }}?dayNum="+dayNum, function(list){
for(var i=0; i<list.length; i++) {
coordJson = JSON.parse(list[i][0]);
allOpenStreetMap[i+1].flyTo([coordJson.lat, coordJson.lon], ZOOMLEVEL);
var marker = L.marker([coordJson.lat, coordJson.lon]).addTo(allOpenStreetMap[i+1]);
marker.bindPopup('lat: '+coordJson.lat+', lon: '+coordJson.lon+' - '+list[i][1]).openPopup();
}
});
}
$(document).ready(function () {
$('#worldMap').vectorMap(vectorMapConfig); $('#worldMap').vectorMap(vectorMapConfig);
worldMapObj = $("#worldMap").vectorMap('get','mapObject'); worldMapObj = $("#worldMap").vectorMap('get','mapObject');
updateTopMaps(1);
});
</script> </script>