def renderMap(): """ Management mosquitoes rendering from database using using Google Maps API :return: map.html """ mosquitos = SQLiteEngine.get_all_mosquitos() return render_template("pages/map.html", mosquitos=mosquitos)
def postForm(): """ Pass information from formular to back-end and send results to response for front answer :return: response.html or error page """ try: # preparing variables to return in template to user predictions = [] mosquito = None cropped_pic = None framed_pic = None file = None # request informations try: form = request.form file = request.files["fileToUpload"] except Exception: raise Errors.FormError() print(form) # extracting objects user = User(form["name"], form["email"]) latitude = form['latitude'] longitude = form['longitude'] date = check_fix_date(form['date']) mosquito = Mosquito(user, file.filename, latitude, longitude, form["comment"], date) user_pic_path = "./dataset/to_be_validated/" + mosquito.filename safe_name = ''.join(c for c in mosquito.filename if c not in '(){}<>') generated_pic_path = "./static/tmp/" + safe_name # saving file if not os.path.exists("./dataset/to_be_validated"): os.makedirs("./dataset/to_be_validated") file.save(user_pic_path) print(date) print(user_pic_path) print(generated_pic_path) # making preproc preprocessing = Preprocessing(user_pic_path) cropped_pic = preprocessing.save_crop_img( generated_pic_path.replace(".jpg", "_crop.jpg").replace( ".png", "_crop.png")) framed_pic = preprocessing.save_framed_img( generated_pic_path.replace(".jpg", "_framed.jpg").replace( ".png", "_framed.png")) # making predictions predictions = command_classification.label_automatic(cropped_pic) print("predictions", predictions) best_prediction = 0 predicted_label = None for species in predictions: if float(species[1]) > best_prediction: best_prediction = float(species[1]) predicted_label = species[0] mosquito.label = predicted_label print("store_mosquito") SQLiteEngine.store_mosquito(mosquito) print("cropped_pic", cropped_pic, "framed_pic", framed_pic) return render_template("pages/response.html", cropped_pic=cropped_pic, framed_pic=framed_pic, prediction=predictions, mosquito=mosquito) except Exception as error: traceback.print_exc() # we return the error page if isinstance(error, Errors.InsectNotFound): return render_template( "pages/errors/mosquito_not_found_error.html") elif isinstance(error, Errors.FormError): return render_template("pages/errors/form_error.html") elif isinstance(error, Errors.APIQuotaExceeded): return render_template("pages/errors/api_quota_exceeded.html") else: return render_template("pages/errors/generic_error.html")
def create_db(): SQLiteEngine.create_database()
from flask_sslify import SSLify from db_model.SQLiteEngine import SQLiteEngine from db_model.Mosquito import Mosquito from db_model.User import User from classification.preprocessing import Preprocessing import classification.command_classification as command_classification from utilities.LRU import LRU import utilities.Errors as Errors import traceback import datetime app = Flask(__name__) LRUCache = LRU() LRUCache.start() SQLiteEngine.create_database() KEY_PATH = "privkey.pem" CRT_PATH = "fullchain.pem" def check_fix_date(date): """ Checks if the given date is coherent and not in the future Else returning current time :param date: (str aaaa-mm-dd) :return ret (string): fixed date with format aaaa-mm-dd """ # default, using today's date now = datetime.datetime.now() ret = '-'.join([str(now.year), str(now.month), str(now.day)])
def get_user_id(): email = '*****@*****.**' print(SQLiteEngine.get_user_id(email))
def get_all_mosquitos(): print(SQLiteEngine.get_all_mosquitos())
def is_User_in_DB(): email = input('enter email') print(SQLiteEngine.is_user_in_db(email))
def drop_db(): SQLiteEngine.drop_database()
def store_mosquito(): user = u.User('Marc', 'MArc\@plus.com') mosquito = m.Mosquito(user, 'file', '') mosquito.label = 'Hello' print(mosquito) SQLiteEngine.store_mosquito(23, mosquito)
def store_species(): name = input('enter species name : ') SQLiteEngine.store_species(name)
def store_user(): user = u.User('Marc', 'MArc\@plus.com') SQLiteEngine.store_user(user)