Skip to content
Permalink
Browse files
averages added
  • Loading branch information
memica committed Mar 13, 2020
1 parent eb31da7 commit 51ff40596015cd2f61e9f2dfce24e707ed92740e
Show file tree
Hide file tree
Showing 41 changed files with 614 additions and 171 deletions.
BIN +21.8 KB image.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,18 +1,19 @@
import sqlite3 as sql
from datetime import datetime

"""Validation for fields"""

database_user = "app/databases/users.db"
database_user = "app/databases/users.db" # Taking the databases
database_locations = 'app/databases/locations.db'

def create():
with sql.connect(database_user) as cur:
try:
try: # Tries the sql table
cur.execute("CREATE TABLE UserDatabase(username VARCHAR2(20), password VARCHAR2(20), realname VARCHAR2(20), dob VARCHAR2(20), weight VARCHAR2(20));")
except:
pass

def user_exists(username):
def user_exists(username): # Checks for username
with sql.connect(database_user) as cur:
com = f"SELECT count(*) FROM UserDatabase WHERE username='{username}';"
print(com)
@@ -22,7 +23,7 @@ def user_exists(username):
else:
return True

def tid_exists(username):
def tid_exists(username): # Checks for tid
with sql.connect(database_locations) as cur:
com = f"SELECT count(*) FROM Location WHERE tid='{username}';"
print(com)
@@ -32,7 +33,7 @@ def tid_exists(username):
else:
return True

def compare(username, value_in, value_type):
def compare(username, value_in, value_type): # Comparing
with sql.connect(database_user) as cur:
com = f"SELECT {value_type} FROM UserDatabase WHERE username='{username}';"
print(com)
@@ -43,14 +44,14 @@ def compare(username, value_in, value_type):
else:
return False

def check_month(month, day):
def check_month(month, day): # Checks the month and day
if month in [1, 3, 5, 7, 8, 10, 12]:
if (day > 0 and day <= 31):
return True
else:
return False
elif month == 2:
if (day > 0 and day <= 28):
if (day > 0 and day <= 28): # Checking February
return True
else:
return False
@@ -60,7 +61,7 @@ def check_month(month, day):
else:
return False

def check_date(day, month, year):
def check_date(day, month, year): # Checks full date
today = datetime.today().strftime('%Y-%m-%d').split("-")
if int(year) > int(today[0]):
return False
@@ -1,17 +1,17 @@
import sqlite3 as sql
from app.functions.auth import base
from app.functions.auth import base # Imports base for later use


database_user = "app/databases/users.db"

def change_password(data):
def change_password(data): # Changing password
base.create()
_status = check_pass_data(data)
if _status == "success":
new_password(data)
return _status

def check_pass_data(data):
def check_pass_data(data): # Checking password data
_status = check_empty(data)
if _status == "ok":
if base.tid_exists(data['username']):
@@ -26,7 +26,7 @@ def check_pass_data(data):
return _status


def check_empty(data):
def check_empty(data): # Checks the entry to see if empty
if data['username'] == "":
return "empty_id"
elif data['day'] == "0":
@@ -42,7 +42,7 @@ def check_empty(data):
else:
return "ok"

def new_password(data):
def new_password(data): # Updates database with new password
con = sql.connect(database_user)
cur = con.cursor()
com = f"UPDATE UserDatabase SET password='{data['password']}' WHERE username='{data['username']}';"
@@ -1,17 +1,17 @@
import sqlite3 as sql
import sqlite3 as sql # Imports sql for use within database
from app.functions.auth import base


database_user = "app/databases/users.db"

def create_profile(data):
def create_profile(data): # Creating new data for a new user
base.create()
_status = check_prof_data(data)
if _status == "success":
make_user(data)
return _status

def check_prof_data(data):
def check_prof_data(data): # Checking new
print(data)
_status = check_empty(data)
if _status == "ok":
@@ -2,15 +2,15 @@ import sqlite3 as sql
import time


database_user = "app/databases/users.db"
database_user = "app/databases/users.db" # Grabs the database
database_locations = "app/databases/locations.db"


# user
def get_user_for(username):
def get_user_for(username):
with sql.connect(database_user) as cur:
res = cur.execute(f"SELECT * FROM UserDatabase WHERE username='{username}';").fetchone()[0]
return res
res = cur.execute(f"SELECT username, realname, dob, weight FROM UserDatabase WHERE username='{username}';").fetchone()
return [res, get_filtered_data_for(username)] # Returns required data



@@ -1,12 +1,12 @@
from flask_mqtt import Mqtt
from flask_mqtt import Mqtt # MQTT using flask
from app.mqtt import mqtt_message_handler

def init_app(app):
mqtt = Mqtt(app)

@mqtt.on_connect()
def handle_connect(client, userdata, flags, rc):
mqtt.subscribe('owntracks/4009user/#')
mqtt.subscribe('owntracks/4009user/#') #owntracks subscribing to mqtt

@mqtt.on_message()
def handle_mqtt_message(client, userdata, msg):
@@ -1,33 +1,33 @@
from geopy.geocoders import Nominatim
from geopy.geocoders import Nominatim # Imports nominatim API
import sqlite3 as sql
import json, os, time


database_locations = 'app/databases/locations.db'

def getMsg(msg):
con = sql.connect(database_locations)
con = sql.connect(database_locations) # connecys to db, amkes cursor
cur = con.cursor()
geolocator = Nominatim(user_agent="Web_app")
try:
geolocator = Nominatim(user_agent="Web_app") # starts nominatim
try: # Tries SQL to create table
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"))
data = json.loads(msg.payload.decode("utf8"))
tid = data["tid"]
lat = data["lat"]
lon = data["lon"]
location = geolocator.reverse(f"{data['lat']},{data['lon']}")
city = location.raw["address"]["city"]
city = location.raw["address"]["city"] # Puts data into small array to be used later
road = location.raw["address"]["road"]
tst = data["tst"]
_time = time.strftime('%H:%M:%S', time.localtime(tst))
_time = time.strftime('%H:%M:%S', time.localtime(tst))#sets time format
_date = time.strftime('%d-%m-%Y', time.localtime(tst))
com = f"INSERT INTO Location values('{tid}','{lon}','{lat}','{city}','{road}','{_date}','{_time}','{tst}');"
print(com)
cur.execute(com)

con.commit()
con.commit() # commits changes to db
cur.close()
con.close()
con.close()# # closes connection

@@ -3,12 +3,14 @@ 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
from .average import average_bl
from .picture import picture_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(images_bl, url_prefix="/images")
app.register_blueprint(average_bl, url_prefix="/average")
app.register_blueprint(picture_bl, url_prefix="/picture")
@@ -0,0 +1,10 @@
from flask import Blueprint, render_template, request, url_for, escape, redirect, session
from app.functions.data_tools import data_getter

average_bl = Blueprint('average', __name__)


@average_bl.route("/", methods = ["GET"])
def index():
return render_template("average/index.html",
locations = data_getter.get_locations_for(session['username']))

This file was deleted.

@@ -5,7 +5,8 @@ main_bl = Blueprint('main', __name__)

@main_bl.route("/")
def index():
return render_template("main/index.html", locations = data_getter.get_locations_for(session['username']))
return render_template("main/index.html",
locations = data_getter.get_locations_for(session['username']))

@main_bl.route("/logout")
def logout():
@@ -0,0 +1,11 @@
from flask import Blueprint, render_template, request, url_for, escape, redirect, session
from app.functions.data_tools import data_getter

picture_bl = Blueprint('picture', __name__)


@picture_bl.route("/", methods = ["GET"])
def index():
return render_template("picture/index.html",
user = session['username'])

@@ -5,4 +5,7 @@ prof_bl = Blueprint('prof', __name__)

@prof_bl.route("/", methods = ["GET", "POST"])
def index():
return render_template("profile/index.html")
return render_template("profile/index.html",
user = data_getter.get_user_for(session['username']),
locations = data_getter.get_map_locations_for(session['username']),
dates = data_getter.get_map_location_dates(session['username']))
Empty file.
@@ -3,10 +3,11 @@
padding: 0;
}
body {
background-image: url('../img/earth.jpg');
background-repeat: no-repeat;
/* background-image: url('../img/earth.jpg'); */
background-color: #3EA4E8;
/* background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
background-size: cover; */
font-family: Gill Sans, sans-serif;
font-variant: small-caps;
display: grid;
@@ -2,42 +2,35 @@
background-color: white;
grid-area: container;
display: grid;
grid-template-columns: 1fr 4fr 4fr 4fr 4fr 1fr;
grid-template-columns: 1fr 16fr 1fr;
grid-template-rows: 1.5fr auto 1.5fr 5fr 1.5fr auto 1.5fr;
grid-template-areas:
'. . . . . .'
'. title title title title .'
'. . . . . .'
'. b_1 b_2 b_3 b_4 .'
'. . . . . .'
'. c_main c_main c_main c_main .'
'. . . . . .';
'. . .'
'. title .'
'. . .'
'. btnss .'
'. . .'
'. c_main .'
'. . .';
}
.title {
grid-area: title;
display: grid;
}
.btnss {
grid-area: btnss;
grid-template-columns: 1fr 0.2fr 1fr 0.2fr 1fr 0.2fr 1fr;
grid-template-rows: 1fr;
display: grid;
grid-template-areas:
'b_1 . b_2 . b_3 . b_4'
}
.title_text {
margin: 20px;
justify-self: center;
align-self: center;
font-size: 7vw;
}
.button_main {
text-align: center;
display: grid;
}
.main_button {
justify-self: center;
align-self: center;
width: 80%;
font-size: 2vw;
border-radius: 10em;
padding: 0.5vh;
}
.danger {
background-color: #ff5252;
}
.button_profile {
grid-area: b_1;
}

0 comments on commit 51ff405

Please sign in to comment.