From eb31da76013c9a1058dcb6641738570bf2efd22a Mon Sep 17 00:00:00 2001 From: Adnan Memic Date: Tue, 10 Mar 2020 02:37:51 +0000 Subject: [PATCH] map js --- location_app/app/favicon.ico | Bin 1150 -> 0 bytes location_app/app/functions/auth/base.py | 8 +- .../app/functions/auth/change_password.py | 1 - .../app/functions/auth/create_profile.py | 7 +- location_app/app/functions/auth/login.py | 3 - .../app/functions/data_tools/data_getter.py | 28 +- location_app/app/mqtt/mqtt_message_handler.py | 5 +- location_app/app/routes/__init__.py | 4 +- location_app/app/routes/images.py | 10 + location_app/app/routes/index.py | 4 +- location_app/app/routes/map.py | 4 +- location_app/app/static/css/login/create.css | 47 +-- location_app/app/static/img/map/dot.svg | 66 ++++ location_app/app/static/img/map/end.svg | 1 + location_app/app/static/img/map/start.svg | 1 + location_app/app/static/js/map/index.js | 318 ++++++++++++++++++ location_app/app/static/js/map/math.js | 88 +++++ location_app/app/static/js/map/test.js | 118 ------- location_app/app/templates/login/create.html | 21 -- location_app/app/templates/login/forgot.html | 14 +- location_app/app/templates/main/index.html | 4 +- location_app/app/templates/map/index.html | 9 +- 22 files changed, 526 insertions(+), 235 deletions(-) delete mode 100644 location_app/app/favicon.ico create mode 100644 location_app/app/routes/images.py create mode 100644 location_app/app/static/img/map/dot.svg create mode 100644 location_app/app/static/img/map/end.svg create mode 100644 location_app/app/static/img/map/start.svg create mode 100644 location_app/app/static/js/map/index.js create mode 100644 location_app/app/static/js/map/math.js delete mode 100644 location_app/app/static/js/map/test.js diff --git a/location_app/app/favicon.ico b/location_app/app/favicon.ico deleted file mode 100644 index f734b07576dfb7c07c2376f537f1c864383e26c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1150 zcmbW1>rdNd6vuxsO6djKLMf$O>eeDmU|hCBxn4lIaVGC6~!|qvZN|_9Gkc=>O5K%fM;p#m^gvi)$ z){&PIO;LIj8CDHujX#mW{zQca5h?7^LYl)>yIie8hDjqQOzB5<>R!Bk6)m)oy#sx*?E1U(zml}vXQGvn#NU6f8mVk8v_VR#(HG#8}dY;e$f`W)`A zA%>i_TpTRtkNfACcI>4*&A_dTEu0^0;H}|f47F5H5~rieo(E zGul+hqQ}motqFRwgGn~*VPmSC_0e=%4~0<@Z^Yd*OI@3n!$~HJ42v;kxX!&5 zFJsjfY&&ryG-Cc#n8dsqv?{{2YP7=74h%|vQgjlHF9gz;tKUUqqMU int(today[0]): return False elif int(year) == int(today[0]): - if int(month) >= int(today[1]): + if int(month) > int(today[1]): return False else: - if int(day) >= int(today[2]): + if int(day) > int(today[2]): return False else: - return check_month(int(today[1]), int(today[2])) + return check_month(int(month), int(day)) else: return check_month(int(month), int(day)) \ No newline at end of file diff --git a/location_app/app/functions/auth/change_password.py b/location_app/app/functions/auth/change_password.py index 5b7dd73..c7148f1 100644 --- a/location_app/app/functions/auth/change_password.py +++ b/location_app/app/functions/auth/change_password.py @@ -3,7 +3,6 @@ from app.functions.auth import base database_user = "app/databases/users.db" -database_locations = 'app/databases/locations.db' def change_password(data): base.create() diff --git a/location_app/app/functions/auth/create_profile.py b/location_app/app/functions/auth/create_profile.py index 904518d..26da05f 100644 --- a/location_app/app/functions/auth/create_profile.py +++ b/location_app/app/functions/auth/create_profile.py @@ -3,7 +3,6 @@ from app.functions.auth import base database_user = "app/databases/users.db" -database_locations = 'app/databases/locations.db' def create_profile(data): base.create() @@ -41,10 +40,6 @@ def check_empty(data): return "empty_bday" elif data['year'] == "0": return "empty_bday" - elif data['gender'] == "": - return "empty_gender" - elif data['height'] == "": - return "empty_height" elif data['weight'] == "": return "empty_weight" elif data['password'] == "": @@ -58,7 +53,7 @@ def make_user(data): con = sql.connect(database_user) cur = con.cursor() _date = f"{data['day']}-{data['month']}-{data['year']}" - com = f"INSERT INTO UserDatabase values('{data['username']}','{data['password']}','{data['realname']}','{data['gender']}','{_date}','{data['height']}','{data['weight']}');" + com = f"INSERT INTO UserDatabase values('{data['username']}','{data['password']}','{data['realname']}','{_date}','{data['weight']}');" print(com) cur.execute(com) con.commit() diff --git a/location_app/app/functions/auth/login.py b/location_app/app/functions/auth/login.py index 708dbce..067858e 100644 --- a/location_app/app/functions/auth/login.py +++ b/location_app/app/functions/auth/login.py @@ -2,9 +2,6 @@ import sqlite3 as sql from app.functions.auth import base -database_user = "app/databases/users.db" -database_locations = 'app/databases/locations.db' - def login(data): base.create() l_status = check_login_data(data) diff --git a/location_app/app/functions/data_tools/data_getter.py b/location_app/app/functions/data_tools/data_getter.py index a7d63ea..34dbd1c 100644 --- a/location_app/app/functions/data_tools/data_getter.py +++ b/location_app/app/functions/data_tools/data_getter.py @@ -9,7 +9,9 @@ database_locations = "app/databases/locations.db" # user def get_user_for(username): with sql.connect(database_user) as cur: - res = cur.execute(f"SELECT * FROM UserDatabase WHERE username='{username}';").fetchone() + res = cur.execute(f"SELECT * FROM UserDatabase WHERE username='{username}';").fetchone()[0] + return res + # freq @@ -26,22 +28,11 @@ def get_frequency_for(data_type, tid): frequent_data = max(set(data_list), key = data_list.count) frequency_data = str(int((data_list.count(frequent_data)/len(data_list)) * 100)) return [frequent_data, frequency_data] - -def get_filtered_data_for_admin(): - all_data = [] - tids = get_all_tids() - for tid in tids: - data_city = get_frequency_for('city', tid) - data_road = get_frequency_for('road', tid) - data_batt = get_frequency_for('battery', tid) - all_data.append([tid, data_city, data_road, data_batt]) - return all_data - + def get_filtered_data_for(tid): data_city = get_frequency_for('city', tid) data_road = get_frequency_for('road', tid) - data_batt = get_frequency_for('battery', tid) - return [data_city, data_road, data_batt] + return [data_city, data_road] # main @@ -52,12 +43,17 @@ def get_locations_for(username): res = cur.execute(f"SELECT DISTINCT * From Location ORDER BY tid, tst DESC;") else: res = cur.execute(f"SELECT DISTINCT * From Location WHERE tid='{username}' ORDER BY tst DESC;") - for tid, batt, lon, lat, city, road, _date, _time, tst, in res: - locations.append([tid, batt, lon, lat, city, road, _date, _time]) + for tid, lon, lat, city, road, _date, _time, tst, in res: + locations.append([tid, lon, lat, city, road, _date, _time]) return locations # map +def get_weight_for(username): + with sql.connect(database_user) as cur: + res = cur.execute(f"SELECT weight From UserDatabase WHERE username='{username}';").fetchone()[0] + return int(res) + def get_map_locations_for(username): locations = [] with sql.connect(database_locations) as cur: diff --git a/location_app/app/mqtt/mqtt_message_handler.py b/location_app/app/mqtt/mqtt_message_handler.py index 786cd25..12b6bd9 100644 --- a/location_app/app/mqtt/mqtt_message_handler.py +++ b/location_app/app/mqtt/mqtt_message_handler.py @@ -10,12 +10,11 @@ def getMsg(msg): cur = con.cursor() geolocator = Nominatim(user_agent="Web_app") try: - cur.execute("CREATE TABLE Location(tid VARCHAR2(2), battery INT(3), longitude NUMBER(10,6), latitude NUMBER(10,6), city VARCHAR2(20), road VARCHAR2(30), date VARCHAR2(20), time VARCHAR2(20), tst INT(15));") + cur.execute("CREATE TABLE Location(tid VARCHAR2(2), longitude NUMBER(10,6), latitude NUMBER(10,6), city VARCHAR2(20), road VARCHAR2(30), date VARCHAR2(20), time VARCHAR2(20), tst INT(15));") except: pass data = json.loads(msg.payload.decode("utf8")) tid = data["tid"] - batt = data["batt"] lat = data["lat"] lon = data["lon"] location = geolocator.reverse(f"{data['lat']},{data['lon']}") @@ -24,7 +23,7 @@ def getMsg(msg): tst = data["tst"] _time = time.strftime('%H:%M:%S', time.localtime(tst)) _date = time.strftime('%d-%m-%Y', time.localtime(tst)) - com = f"INSERT INTO Location values('{tid}','{batt}','{lon}','{lat}','{city}','{road}','{_date}','{_time}','{tst}');" + com = f"INSERT INTO Location values('{tid}','{lon}','{lat}','{city}','{road}','{_date}','{_time}','{tst}');" print(com) cur.execute(com) diff --git a/location_app/app/routes/__init__.py b/location_app/app/routes/__init__.py index 35d0364..c5e743c 100644 --- a/location_app/app/routes/__init__.py +++ b/location_app/app/routes/__init__.py @@ -3,10 +3,12 @@ from .main import main_bl from .map import map_bl from .login import login_bl from .profile import prof_bl +from .images import images_bl def init_app(app): app.register_blueprint(index_bl) app.register_blueprint(main_bl, url_prefix="/main") app.register_blueprint(map_bl, url_prefix="/map") app.register_blueprint(login_bl, url_prefix="/login") - app.register_blueprint(prof_bl, url_prefix="/profile") \ No newline at end of file + app.register_blueprint(prof_bl, url_prefix="/profile") + app.register_blueprint(images_bl, url_prefix="/images") \ No newline at end of file diff --git a/location_app/app/routes/images.py b/location_app/app/routes/images.py new file mode 100644 index 0000000..6db5c06 --- /dev/null +++ b/location_app/app/routes/images.py @@ -0,0 +1,10 @@ +from flask import Blueprint, url_for, send_file + +images_bl = Blueprint('images', __name__) + +# @images_bl.route("/", methods = ["GET", "POST"]) + + +@images_bl.route("/dot", methods = ["GET"]) +def dot(): + return send_file('static/img/dot.svg') diff --git a/location_app/app/routes/index.py b/location_app/app/routes/index.py index 4d25dd4..0b086ce 100644 --- a/location_app/app/routes/index.py +++ b/location_app/app/routes/index.py @@ -8,6 +8,4 @@ def index(): if user: return redirect(url_for('main.index')) else: - return redirect(url_for('login.index')) - - + return redirect(url_for('login.index')) \ No newline at end of file diff --git a/location_app/app/routes/map.py b/location_app/app/routes/map.py index 8c069b6..7a48c0b 100644 --- a/location_app/app/routes/map.py +++ b/location_app/app/routes/map.py @@ -7,4 +7,6 @@ map_bl = Blueprint('map', __name__) def index(): return render_template("map/index.html", locations = data_getter.get_map_locations_for(session['username']), - dates = data_getter.get_map_location_dates(session['username'])) \ No newline at end of file + dates = data_getter.get_map_location_dates(session['username']), + weight = data_getter.get_weight_for(session['username'])) + diff --git a/location_app/app/static/css/login/create.css b/location_app/app/static/css/login/create.css index 817590a..e53d19b 100644 --- a/location_app/app/static/css/login/create.css +++ b/location_app/app/static/css/login/create.css @@ -53,7 +53,7 @@ justify-content: start; align-content: center; grid-template-columns: 2fr 2fr; - grid-template-rows: 0.25fr 1.5fr 0.15fr 1.5fr 0.15fr 1.5fr 0.15fr 1.5fr 1.5fr 0.15fr 1.5fr 0.15fr 1.5fr 1.5fr 1.5fr; + grid-template-rows: 0.25fr 1.5fr 0.15fr 1.5fr 0.15fr 1.5fr 0.15fr 1.5fr 0.15fr 1.5fr 1.5fr 1.5fr; grid-template-areas: '. .' 'user user' @@ -62,9 +62,6 @@ '. .' 'dob dob' '. .' - 'gender gender' - 'height height' - '. .' 'weight weight' '. .' 'pass pass' @@ -101,48 +98,6 @@ margin-bottom: 1px; font-size: 1.5vw; } -.gender { - display: grid; - justify-content: center; - align-content: center; - grid-area: gender; - grid-template-columns: 1fr 1fr; - grid-template-rows: 1fr 1fr; - grid-template-areas: - 'gender_text gender_text' - 'male female'; -} -.gender_text { - margin-bottom: 1px; - font-size: 1.5vw; - grid-area: gender_text; -} -.male { - display: grid; - grid-template-columns: 0.2fr 1fr; - justify-content: center; - align-content: center; - margin-bottom: 1px; - grid-area: male; -} -.female { - display: grid; - grid-template-columns: 0.2fr 1fr; - justify-content: center; - align-content: center; - margin-bottom: 1px; - grid-area: female; -} -.height { - display: grid; - justify-content: center stretch; - align-content: center; - grid-area: height; -} -.height_text { - margin-bottom: 1px; - font-size: 1.5vw; -} .weight { display: grid; justify-content: center stretch; diff --git a/location_app/app/static/img/map/dot.svg b/location_app/app/static/img/map/dot.svg new file mode 100644 index 0000000..4c759cc --- /dev/null +++ b/location_app/app/static/img/map/dot.svg @@ -0,0 +1,66 @@ + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/location_app/app/static/img/map/end.svg b/location_app/app/static/img/map/end.svg new file mode 100644 index 0000000..0db7fb0 --- /dev/null +++ b/location_app/app/static/img/map/end.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/location_app/app/static/img/map/start.svg b/location_app/app/static/img/map/start.svg new file mode 100644 index 0000000..c0ed262 --- /dev/null +++ b/location_app/app/static/img/map/start.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/location_app/app/static/js/map/index.js b/location_app/app/static/js/map/index.js new file mode 100644 index 0000000..8283153 --- /dev/null +++ b/location_app/app/static/js/map/index.js @@ -0,0 +1,318 @@ +var map; +var locations; +var state; +var weight; + +// IMAGES +var normalMarker = "/static/img/map/dot.svg"; +var startMarker = "/static/img/map/start.svg"; +var endMarker = "/static/img/map/end.svg"; + +// SCALES +var startScale = 2; +var endScale = 0.7; +var fScale = 0.6; +var hScale = 1; +var lineW = 5; + +// COLORS +var normalColor = "#ff0000"; +var highStartMarker = "#ffffff"; +var highEndMarker = "#000000"; +var highLine = "#000000"; + +// TIMERS +var timers = {}; +var l_timers = {}; + +// MAP +function initialize_map(_locations, _weight) { + locations = _locations; + weight = _weight; + map = new ol.Map({ + target: "map", + layers: [ + new ol.layer.Tile({ + source: new ol.source.OSM + }) + ], + view: new ol.View() + }); + set_click_listener(); + get_map_all_locations(); +} + +function reset_map_layers() { + layers = map.getLayers(); + layers.a = [layers.a[0]]; +} + +function center_map(points = 0) { + if(points == 0) { + var dot_layers = []; + map.getLayers().forEach(function(layer) { + if(!(layer instanceof ol.layer.Group)) { + if(layer.get('type') == "dot") { + dot_layers.push(layer.getSource().getExtent()); + } + } + }); + var area = dot_layers[0]; + for(i = 0; i < dot_layers.length; i++) { + ol.extent.extend(area, dot_layers[i]); + } + map.getView().fit(area, { + size: map.getSize(), + maxZoom: 20 + }); + } else { + var area = points[0].getSource().getExtent(); + ol.extent.extend(area, points[1].getSource().getExtent()); + map.getView().fit(area, { + size: map.getSize(), + maxZoom: 21.5 + }); + } +} + +// ALL LOCATIONS +function get_map_all_locations() { + state = 1; + reset_map_layers(); + for(i = 0; i < locations.length; i++) { + var location = locations[i]; + var marker_properties = { + 'type': "dot", + 'date': location[2], + 'time': location[3] + }; + draw_marker(location[0], location[1], marker_properties); + } + center_map(); +} + +// FOR DATE +function get_map_for_date(date) { + state = 2; + reset_map_layers(); + var this_date_loc = []; + var total_distance = 0; + var total_calories = 0; + var last_distance = 0; + var last_calories = 0; + for(i = 0; i < locations.length; i++) { + if(locations[i][2] == date) { + this_date_loc.push(locations[i]); + } + } + for(i = 0; i < this_date_loc.length - 1; i++) { + connect_two_locations(this_date_loc[i], this_date_loc[i + 1], i); + total_distance += get_distance(this_date_loc[i], this_date_loc[i + 1]); + total_calories += get_calories(this_date_loc[i], this_date_loc[i + 1]); + } + this_date_loc = this_date_loc.reverse(); + for(i = 0; i < this_date_loc.length; i++) { + var location = this_date_loc[i]; + if(i > 0) { + last_distance += get_distance(this_date_loc[i - 1], this_date_loc[i]); + last_calories += get_calories(this_date_loc[i - 1], this_date_loc[i]); + } + var marker_properties = { + 'type': "dot", + 'special': "", + 'number': i, + 'x': location[0], + 'y': location[1], + 'date': location[2], + 'time': location[3], + 'total_distance': format_distance(total_distance), + 'total_calories': format_calories(total_calories), + 'last_distance': format_distance(last_distance), + 'last_calories': format_calories(last_calories) + } + if(i == 0 && this_date_loc.length > 1) { + var marker = draw_marker(location[0], location[1], marker_properties); + marker.set('special', "start"); + marker.setZIndex(1000); + marker.setStyle(get_marker_style(normalColor, startScale, startMarker)); + } else if(i == this_date_loc.length - 1 && this_date_loc.length > 1) { + var marker = draw_marker(location[0], location[1], marker_properties); + marker.set('special', "end"); + marker.setZIndex(1000); + marker.setStyle(get_marker_style(normalColor, endScale, endMarker, [0.37, 0.97])); + } else { + draw_marker(location[0], location[1], marker_properties); + } + } + center_map(); +} + +// MARKER +function draw_marker(pos1, pos2, _properties) { + var marker = new ol.layer.Vector({ + source: new ol.source.Vector({ + features: [new ol.Feature({ + geometry: new ol.geom.Point(ol.proj.fromLonLat([pos1, pos2])), + })] + }), + style: get_marker_style(normalColor, fScale, normalMarker) + }); + marker.setProperties(_properties); + map.addLayer(marker); + return marker; +} + +function get_marker_style(color, scale, img, anchor = [0.5, 0.5]) { + return new ol.style.Style({ + image: new ol.style.Icon({ + crossOrigin: "Anonymous", + scale: scale, + color: color, + anchorXUnits: "fraction", + anchorYUnits: "fraction", + anchor: anchor, + src: img + }) + }); +} + +// LINE +function connect_two_locations(loc1, loc2, num) { + var pos1 = ol.proj.fromLonLat([loc1[0], loc1[1]]); + var pos2 = ol.proj.fromLonLat([loc2[0], loc2[1]]); + var line_properties = { + 'type': "line", + 'number': num, + 'start1': loc2[0], + 'start2': loc2[1], + 'end1': loc1[0], + 'end2': loc1[1], + 'length': format_distance(get_distance(loc1, loc2)), + 'time': format_time(get_time(loc1, loc2)), + 'speed': format_speed(get_speed(loc1, loc2)), + 'calories': format_calories(get_calories(loc1, loc2)) + } + draw_line(pos1, pos2, line_properties) +} + +function draw_line(pos1, pos2, _properties) { + var line = new ol.layer.Vector({ + source: new ol.source.Vector({ + features: [new ol.Feature({ + geometry: new ol.geom.LineString([pos1, pos2]) + })] + }), + style: get_line_style(normalColor) + }); + line.setProperties(_properties); + map.addLayer(line); +} + +function get_line_style(color) { + return new ol.style.Style({ + stroke: new ol.style.Stroke({ + color: color, + width: lineW + }) + }); +} + +// CLICK LISTENER +function set_click_listener() { + map.getViewport().addEventListener("click", function(event) { + var layer = map.forEachFeatureAtPixel(map.getEventPixel(event), function(feature, layer) { + return layer; + }); + if(layer) { + if(layer.get('type') == "dot") { + get_dot_data(layer); + } else if(layer.get('type') == "line") { + get_line_data(layer); + highlight_line(layer); + var dots = get_start_end(layer); + center_map(dots); + } + } + }); +} + +function show_alert(info) { + var text = ""; + for(i = 0; i < info.length; i++) { + text += info[i] + "\n"; + } + alert(text); +} + +function get_dot_data(layer) { + if(state == 1) { + show_alert(["You were here on", + "Date: " + layer.get('date'), + "Time: " + layer.get('time')]); + } else { + if(layer.get('special') == "start") { + show_alert(["This is Start!", + "Time: " + layer.get('time'), + "Your total distance is: " + layer.get('total_distance'), + "Your total calories are: " + layer.get('total_calories')]); + } else if(layer.get('special') == "start") { + show_alert(["This is End!", + "Time: " + layer.get('time'), + "Your total distance is: " + layer.get('total_distance'), + "Your total calories are: " + layer.get('total_calories')]); + } else { + show_alert(["Time: " + layer.get('time'), + "Distance from start: " + layer.get('last_distance'), + "Calories from start: " + layer.get('last_calories'), + "Your total distance is: " + layer.get('total_distance'), + "Your total calories are: " + layer.get('total_calories')]); + } + } +} + +function get_line_data(layer) { + show_alert(["Distance: " + layer.get('length'), + "Time: " + layer.get('time'), + "Speed: " + layer.get('speed'), + "Calories: " + layer.get('calories')]); +} + +function highlight_line(line) { + line.setStyle(get_line_style(highLine)); + clearTimeout(l_timers[line.get('number')]); + l_timers[line.get('number')] = setTimeout(function() { + line.setStyle(get_line_style(normalColor)); + }, 4000); +} + +function highlight_marker(marker, color) { + marker.setStyle(get_marker_style(color, hScale, normalMarker)); + marker.setZIndex(100); + clearTimeout(timers[marker.get('number')]); + timers[marker.get('number')] = setTimeout(function() { + marker.setStyle(get_marker_style(normalColor, fScale, normalMarker)); + }, 4000); +} + +function get_start_end(layer) { + var start; + var end; + map.getLayers().forEach(function(_layer) { + if(!(_layer instanceof ol.layer.Group)) { + if(_layer.get('type') == "dot") { + if(_layer.get('x') == layer.get('start1') && _layer.get('y') == layer.get('start2')) { + start = _layer; + } else if(_layer.get('x') == layer.get('end1') && _layer.get('y') == layer.get('end2')) { + end = _layer; + } + } + } + }); + if(start.get('special') == "") { + highlight_marker(start, highStartMarker) + } + if(end.get('special') == "") { + highlight_marker(end, highEndMarker) + } + return [start, end]; +} \ No newline at end of file diff --git a/location_app/app/static/js/map/math.js b/location_app/app/static/js/map/math.js new file mode 100644 index 0000000..966d9a9 --- /dev/null +++ b/location_app/app/static/js/map/math.js @@ -0,0 +1,88 @@ +// TIME +function get_time(loc1, loc2) { + var miliseconds = Math.abs(new Date('1998/01/01 ' + loc1[3]) - + new Date('1998/01/01 ' + loc2[3])); + return (miliseconds / 1000); +} + +function format_time(seconds) { + var miliseconds = seconds * 1000; + if(seconds > 60) { + return new Date(miliseconds).getMinutes() + " minutes and " + + new Date(miliseconds).getSeconds() + " seconds"; + } else { + return new Date(miliseconds).getSeconds() + " seconds"; + } +} + +// DISTANCE +function toRad(x) { + return x * Math.PI / 180; +} + +function get_distance(loc1, loc2) { + var x1 = loc2[1] - loc1[1]; + var dLat = toRad(x1); + var x2 = loc2[0] - loc1[0]; + var dLon = toRad(x2); + var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + + Math.cos(toRad(loc1[1])) * Math.cos(toRad(loc2[1])) * + Math.sin(dLon / 2) * Math.sin(dLon / 2); + var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + var distance = 6371 * c; + return (distance * 1000); +} + +function format_distance(distance) { + if (distance > 1000) { + return (Math.round((distance / 1000) * 100) / 100) + " kilometers"; + } else { + return (Math.round(distance * 100) / 100) + " meters"; + } +} + +// SPEED +function get_speed(loc1, loc2) { + var distance = get_distance(loc1, loc2); + var time = get_time(loc1, loc2); + var speed = distance / time; + + return (speed * 3.6); +} + +function format_speed(speed) { + return (Math.round(speed * 100) / 100) + " km/h"; +} + +// CALORIES +function get_MET(speed) { + if ( 1 <= speed && speed < 3) { + return 2; + } else if ( 3 <= speed && speed < 5) { + return 2.5; + } else if ( 5 <= speed && speed < 8) { + return 5; + } else if ( 8 <= speed && speed < 10) { + return 8; + } else if ( 10 <= speed && speed < 13) { + return 11; + } else if ( 13 <= speed && speed < 16) { + return 13.5; + } else if ( 16 <= speed && speed < 35){ + return 16; + } else { + return 1; + } +} + +function get_calories(loc1, loc2) { + var speed = get_speed(loc1, loc2); + var time = get_time(loc1, loc2); + var met = get_MET(speed); + + return (((met * 3.5 * weight) / 200) * (time/60)); +} + +function format_calories(calories) { + return (Math.round(calories * 100) / 100) + " calories"; +} \ No newline at end of file diff --git a/location_app/app/static/js/map/test.js b/location_app/app/static/js/map/test.js deleted file mode 100644 index 91e288a..0000000 --- a/location_app/app/static/js/map/test.js +++ /dev/null @@ -1,118 +0,0 @@ -var map; -var locations; -var dates; -var mapLat = 52.407633; -var mapLng = -1.496947; -var mapDefaultZoom = 15; -var mapJourneyZoom = 20; - -function initialize_map(loc, dat) { - locations = loc; - dates = dat; - map = new ol.Map({ - target: "map", - layers: [ - new ol.layer.Tile({ - source: new ol.source.OSM - }) - ], - view: new ol.View({ - center: ol.proj.fromLonLat([mapLng, mapLat]), - zoom: mapDefaultZoom - }) - }); - get_map_all_locations(); -} - -function reset_map_layers() { - layers = map.getLayers(); - layers.a = [layers.a[0]]; -} - -function get_map_all_locations() { - reset_map_layers(); - for(i = 0; i < locations.length; i++) { - add_map_point(locations[i]); - } - var new_center = get_average(locations); - map.getView().setCenter(ol.proj.fromLonLat([new_center[0], new_center[1]])); - map.getView().setZoom(mapDefaultZoom); -} - -function get_map_for_date(date) { - reset_map_layers(); - var this_date_loc = []; - for(i = 0; i < locations.length; i++) { - if(locations[i][2] == date) { - this_date_loc.push(locations[i]); - } - } - for(i = 0; i < this_date_loc.length - 1; i++) { - add_map_lines(this_date_loc[i], this_date_loc[i + 1]); - } - for(i = 0; i < this_date_loc.length; i++) { - if (i == 0 && this_date_loc.length > 1) { - add_map_point(this_date_loc[i], '#0000ff'); - } else if (i == this_date_loc.length - 1 && this_date_loc.length > 1) { - add_map_point(this_date_loc[i], '#00ff00'); - } else { - add_map_point(this_date_loc[i]); - } - } - var new_center = get_average(this_date_loc); - map.getView().setCenter(ol.proj.fromLonLat([new_center[0], new_center[1]])); - map.getView().setZoom(mapJourneyZoom); -} - -function get_average(array_in) { - var center = [0, 0]; - for(i = 0; i < array_in.length; i++) { - center[0] += array_in[i][0]; - center[1] += array_in[i][1]; - } - return [center[0] / array_in.length, center[1] / array_in.length] -} - -function add_map_point(location, color = '#ff0000') { - var vectorLayer = new ol.layer.Vector({ - source: new ol.source.Vector({ - features: [new ol.Feature({ - geometry: new ol.geom.Point(ol.proj.fromLonLat([location[0], location[1]])), - })] - }), - style: new ol.style.Style({ - image: new ol.style.Icon({ - crossOrigin: "Anonymous", - scale: 0.5, - color: color, - anchorXUnits: "fraction", - anchorYUnits: "fraction", - src: "https://upload.wikimedia.org/wikipedia/commons/7/7b/WhiteDot.svg" - }) - }) - }); - map.addLayer(vectorLayer); -} - -function add_map_lines(loc1, loc2) { - var pos1 = ol.proj.fromLonLat([loc1[0], loc1[1]]); - var pos2 = ol.proj.fromLonLat([loc2[0], loc2[1]]); - var lineStyle = [ - new ol.style.Style({ - stroke: new ol.style.Stroke({ - color: '#ff0000', - width: 2 - }) - }) - ]; - var myLine = new ol.layer.Vector({ - source: new ol.source.Vector({ - features: [new ol.Feature({ - geometry: new ol.geom.LineString([pos1, pos2]), - name: 'Line', - })] - }) - }); - myLine.setStyle(lineStyle); - map.addLayer(myLine); -} \ No newline at end of file diff --git a/location_app/app/templates/login/create.html b/location_app/app/templates/login/create.html index 78762e2..e343f4b 100644 --- a/location_app/app/templates/login/create.html +++ b/location_app/app/templates/login/create.html @@ -71,27 +71,6 @@

Empty Date

{% endif %} -
-

Gender:


-
- -

Male

-
-
- -

Female

-
- {% if status == 'empty_gender' %} -

Empty Height

- {% endif %} -
-
-

Height (cm):


- - {% if status == 'empty_height' %} -

Empty Height

- {% endif %} -

Weight (kg):


diff --git a/location_app/app/templates/login/forgot.html b/location_app/app/templates/login/forgot.html index b66e52f..faaa587 100644 --- a/location_app/app/templates/login/forgot.html +++ b/location_app/app/templates/login/forgot.html @@ -4,8 +4,7 @@ {% block title %} Forgot Password {% endblock %} -{% block basejs %} -{% endblock %} +{% block basejs %} {% endblock %} {% block basecss %} @@ -26,7 +25,8 @@
-

ID:


+

ID:

+
{% if status == 'no_id' %}

Wrong ID

@@ -35,7 +35,8 @@ {% endif %}
-

Birthday:


+

Birthday:

+
{% if status == 'empty_pass' %}

Empty Password

@@ -73,7 +75,7 @@ {% if status == 'empty_rpass' %}

Empty Repeat Password

- {% if status == 'pass_no_match' %} + {% elif status == 'pass_no_match' %}

Passwords don't match

{% endif %}
diff --git a/location_app/app/templates/main/index.html b/location_app/app/templates/main/index.html index 7dcfadc..b99edb2 100644 --- a/location_app/app/templates/main/index.html +++ b/location_app/app/templates/main/index.html @@ -38,7 +38,6 @@ Your Locations ID - Battery Longitude Latitude City @@ -49,13 +48,12 @@ {% for item in locations %} {{ item[0] }} - {{ item[1] }} % + {{ item[1] }} {{ item[2] }} {{ item[3] }} {{ item[4] }} {{ item[5] }} {{ item[6] }} - {{ item[7] }} {% endfor %} diff --git a/location_app/app/templates/map/index.html b/location_app/app/templates/map/index.html index 1dcccad..f1e2333 100644 --- a/location_app/app/templates/map/index.html +++ b/location_app/app/templates/map/index.html @@ -5,8 +5,10 @@ {% block js %} - - + + + + {% endblock %} @@ -14,6 +16,7 @@ {% block css %} + {% endblock %} @@ -43,7 +46,7 @@ {% block body %}