Skip to content
Permalink
Browse files
map js
  • Loading branch information
memica committed Mar 10, 2020
1 parent a0cbc85 commit eb31da76013c9a1058dcb6641738570bf2efd22a
Show file tree
Hide file tree
Showing 22 changed files with 526 additions and 235 deletions.
Binary file not shown.
@@ -8,7 +8,7 @@ database_locations = 'app/databases/locations.db'
def create():
with sql.connect(database_user) as cur:
try:
cur.execute("CREATE TABLE UserDatabase(username VARCHAR2(20), password VARCHAR2(20), realname VARCHAR2(20), gender VARCHAR2(20), dob VARCHAR2(20), height VARCHAR2(20), weight VARCHAR2(20));")
cur.execute("CREATE TABLE UserDatabase(username VARCHAR2(20), password VARCHAR2(20), realname VARCHAR2(20), dob VARCHAR2(20), weight VARCHAR2(20));")
except:
pass

@@ -65,13 +65,13 @@ def check_date(day, month, year):
if int(year) > 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))

@@ -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()
@@ -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()
@@ -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)
@@ -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:
@@ -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)

@@ -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")
app.register_blueprint(prof_bl, url_prefix="/profile")
app.register_blueprint(images_bl, url_prefix="/images")
@@ -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')
@@ -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'))
@@ -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']))
dates = data_getter.get_map_location_dates(session['username']),
weight = data_getter.get_weight_for(session['username']))

@@ -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;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eb31da7

Please sign in to comment.