def index(path): """ Wildcard view api to allow access to a specified page if the page exists Args: path (str): path to different html Returns: view: flask view for the requested HTML """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) print(data) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/' + path, data=data) except: return "404 Not Found"
def predictions_dashboard(project_id): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None model_info = None data = Project.from_user(current_user.user_id) if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/prediction_dashboard.html', data=data, project_specific_data=project_specific_data, model_info=model_info) except: return render_template('pages/error-404.html')
def start_train(project_id): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) project_specific_data = [] html = None titles = None if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) if project_specific_data[0]['model_available']: return jsonify(result='trained') q.enqueue(DLModel.train_model, project_specific_data[0]['dataset'][0]['name'], int(project_id), app.config['UPLOAD_FOLDER']) Database.update_one(collection='projects', query=[{ 'project_id': int(project_id) }, { "$set": { "in_training": True } }]) return jsonify(result='done') else: return jsonify(result='error')
def explore_data(project_id, dataset_id): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) table_data, titles, numerical_vals = Analysis.get_coloums_stat( app.config['UPLOAD_FOLDER'] + 'dataset/' + dataset_id) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/explore_data.html', data=data, project_specific_data=project_specific_data, numerical_vals=numerical_vals, table_data=table_data, titles=titles, active_dataset=dataset_id) except: return render_template('pages/error-404.html')
def start_train(project_id): """ STRICT API To allow ADMIN user to force sart training for the Deep Leanring Model Allows an ADMIN user to start traning the user Deep LEarning model customer's activities. \n\n API/URL must be accessed with GET request and supply project_id the URL\n method: GET\n Args: project_id (str): ID of the poject/Customer need to be sent in url. It is made to do so via Front end href Returns: response: JSON object On Success \n response = { 'result': 'done' } \n On Fail:\n response = { 'result': 'error' } \n """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) project_specific_data = [] html = None titles = None if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) if project_specific_data[0]['model_available']: return jsonify(result='trained') q.enqueue(DLModel.train_model, project_specific_data[0]['dataset'][0]['name'], int(project_id), app.config['UPLOAD_FOLDER']) Database.update_one(collection='projects', query=[{ 'project_id': int(project_id) }, { "$set": { "in_training": True } }]) return jsonify(result='done') else: return jsonify(result='error')
def project_dashboard(project_id): """ Admin Dashboard \n ALlows ADMIN to access project/CUSTOMER user ALlows ADMIN to access project/CUSTOMER user dashboard with all the admin tools to vefiy user pipeline this allows admin to oversee if the user data is present or not Allow to see the status of user Deep Learning model.\n\n method: GET\n API/URL must be accessed with GET request and supply project_id in the URL\n Args: project_id (str): ID of the poject need to be sent in url. It is made to do so via Front end href Returns: view: a url VIEW the project's/CUSTOMER's required params such as Dataset, dataset voliation if present, Deep leanring model status, Deep learning model metrics, predication metreics. OR if the user is not logged in or CUSTOMER user does not exists then 404 redirect """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) project_specific_data = [] html = None titles = None model_info = None if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) print(project_specific_data) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/project_dashboard.html', data=data, project_specific_data=project_specific_data, model_info=model_info) except: return render_template('pages/error-404.html')
def create_project(): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) data = Project.from_user(current_user.user_id) all_data = [] html = None project_id = None titles = None if request.method == 'POST': f_1 = request.files['file_1'] f_2 = request.files['file_2'] filename_one = str(uuid.uuid4())[:8] + "." + f_1.filename.rsplit( '.', 1)[1].lower() if not f_2: f_2 = f_1 filename_two = str(uuid.uuid4())[:8] + "." + f_2.filename.rsplit( '.', 1)[1].lower() f_1.save(app.config['UPLOAD_FOLDER'] + "dataset/" + secure_filename(filename_one)) f_2.save(app.config['UPLOAD_FOLDER'] + "dataset/" + secure_filename(filename_two)) dataset = [{ 'name': filename_one, 'type': 'Forecasting Timeseries Data', 'file_attributes': [0, 0], 'datasetID': filename_one, 'status': 'Active' }, { 'name': filename_two, 'type': 'Item Attributes', 'file_attributes': [0, 0], 'datasetID': filename_two, 'status': 'Active' }] pname = request.form['pname'] ptype = request.form['ptype'] user_id = current_user.user_id project_id = int(str(uuid.uuid4().int)[:6]) date = str(datetime.datetime.utcnow()) #project_id, user_id, pname, ptype, dataset, date new_project = Project(project_id, user_id, pname, ptype, dataset, date) new_project.save_to_mongo() return redirect(url_for('project_dashboard', project_id=project_id))
def predictions_dashboard(project_id): """ Predictions Dashboard \n To allow ADMIN user see all necessary metrics for the project/CUSTOMER user Allows an ADMIN user visualize the Deep Learning model's performance, along side customer's activities.\n\n method: GET\n API/URL must be accessed with GET request and supply project_id in the URL\n Args: project_id (str): ID of the poject need to be sent in url. It is made to do so via Front end href Returns: view: a url VIEW the project's/CUSTOMER's all required prediction values and visulization data give user login status. If project CUSTOMER not found then redirect 404. """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None model_info = None data = Project.from_user(current_user.user_id) if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/prediction_dashboard.html', data=data, project_specific_data=project_specific_data, model_info=model_info) except: return render_template('pages/error-404.html')
def dataset_raw_data(project_id, dataset_id): """ RAW Data exploaration\n Allows an ADMIN user to explore user dataset through its dashboard and see all the raw not pruned data user login status. If dataset not found then redirect 404.\n\n method: GET\n API/URL must be accessed with GET request and supply project_id and dataset_id in the URL\n Args: project_id (str): ID of the poject need to be sent in url. It is made to do so via Front end href dataset_id (str): ID of the dataset need to be sent in url. It is made to do so via Frontend href Returns: view: A flask view for the raw data html """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) print(project_specific_data) table_html, titles = Analysis.get_data_head(app.config['UPLOAD_FOLDER'] + 'dataset/' + dataset_id) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/raw_data.html', data=data, project_specific_data=project_specific_data, tables=table_html, titles=titles, active_dataset=dataset_id) except: return render_template('pages/error-404.html')
def index(path): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) print(data) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/' + path, data=data) except: return "404 Not Found"
def dataset_schema(project_id): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) print(project_specific_data) try: # try to match the pages defined in -> pages/<input file> return render_template( 'pages/dataset_schema.html', data=data, project_specific_data=project_specific_data) except: return render_template( 'pages/error-404.html' )
def customer_dashboard(project_id): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) project_specific_data = [] html = None titles = None model_info = None if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) print(project_specific_data) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> responseObject = { "data": data, "project_specific_data": project_specific_data, "model_info": model_info } return make_response(jsonify(responseObject)), 201 except: responseObject = { 'status': 'fail', 'message': 'Some error occurred with database. Please try again.' } return make_response(jsonify(responseObject)), 201
def create_project_sample(): if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) data = Project.from_user(current_user.user_id) if request.method == 'POST': dataset = [ { 'name': 'sample.csv', 'type': 'Forecasting Timeseries Data', 'file_attributes': [0, 0], 'datasetID': 'sample.csv', 'status': 'Active' }, { 'name': 'sample.csv', 'type': 'Item Attributes', 'file_attributes': [0, 0], 'datasetID': 'sample1.csv', 'status': 'Active' }, ] pname = "Sample Project" #if pname is None or len(pname) == 0: # pname = "Sample" ptype = request.form['ptype'] user_id = current_user.user_id project_id = int(str(uuid.uuid4().int)[:6]) date = str(datetime.datetime.utcnow()) #project_id, user_id, pname, ptype, dataset, date new_project = Project(project_id, user_id, pname, ptype, dataset, date) new_project.save_to_mongo() return redirect(url_for('project_dashboard', project_id=project_id))
def dataset_schema(project_id): """ Data Schema mapping\n To allow ADMIN user to set data schema for AUTOML Allows an ADMIN user to change/set data schema for AUTOML\n\n method: GET\n API/URL must be accessed with GET request and supply project_id in the URL\n Args: project_id (str): ID of the poject need to be sent in url. It is made to do so via Front end href Returns: view: a url VIEW the project's data schema mapping after verfying user login status. If project not found then redirect 404. """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) print(project_specific_data) try: # try to match the pages defined in -> pages/<input file> return render_template('pages/dataset_schema.html', data=data, project_specific_data=project_specific_data) except: return render_template('pages/error-404.html')
def customer_dashboard(project_id): """ STRICT api for mobile team and customer web Ui team to use Retunrs all CUSTOEMR deeplearning model satas. Data set for the CUSTOMER USER if any error occurs then JSON will contain error message. \n\n API/URL must be accessed with GET request and supply project_id the URL\n method: GET\n Args: project_id (str): ID of the poject/Customer need to be sent in url. It is made to do so via Front end href Returns: response: JSON object On Success \n response = { "data":data, "project_specific_data":project_specific_data, "model_info":model_info } \n On Fail:\n response = { 'status': 'fail', 'message': 'Some error occurred with database. Please try again.' } \n """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) content = None data = None data = Project.from_user(current_user.user_id) project_specific_data = [] html = None titles = None model_info = None if Project.check_auth(current_user.user_id, int(project_id)): project_specific_data = Project.get_one(current_user.user_id, int(project_id)) print(project_specific_data) if project_specific_data[0]['model_available']: model_info = Database.find_one( collection="models", query={"project_id": project_specific_data[0]['project_id']}) print(model_info) try: # try to match the pages defined in -> pages/<input file> responseObject = { "data": data, "project_specific_data": project_specific_data, "model_info": model_info } return make_response(jsonify(responseObject)), 201 except: responseObject = { 'status': 'fail', 'message': 'Some error occurred with database. Please try again.' } return make_response(jsonify(responseObject)), 201
def create_project(): """ Create customer user via ADMIN dashboard Allows an ADMIN user to create customer through its dashboard and set all DATA required MANUALLY. It created the user and saves all the files required in necessary order.\n\n method: POST\n POST: API usage, acts a api to craete customer user\n params should be in a FLASK FORM json format (Form data).\n\n Args: form_data: data retrived from Flask form from the frontend file_1: Data set for the user specifying feature file needed to for time series forecasting file_2: optional file for attributes Returns: redirect: url for the newely creadted user or redirects to root. form_data = { 'name': type=str 'lname': type=str) 'gender': type=str 'phone': type=str 'address': type=str 'city': type=str 'zipcode': type=str 'state': type=str 'username': type=str 'password': type=str 'email': type=str } file_1 = file upload from CSV file_2 = file upload from CSV optional """ if not current_user.is_authenticated: print('not logged in') return redirect(url_for('login')) data = Project.from_user(current_user.user_id) all_data = [] html = None project_id = None titles = None if request.method == 'POST': f_1 = request.files['file_1'] f_2 = request.files['file_2'] filename_one = str(uuid.uuid4())[:8] + "." + f_1.filename.rsplit( '.', 1)[1].lower() if not f_2: f_2 = f_1 filename_two = str(uuid.uuid4())[:8] + "." + f_2.filename.rsplit( '.', 1)[1].lower() f_1.save(app.config['UPLOAD_FOLDER'] + "dataset/" + secure_filename(filename_one)) f_2.save(app.config['UPLOAD_FOLDER'] + "dataset/" + secure_filename(filename_two)) dataset = [{ 'name': filename_one, 'type': 'Forecasting Timeseries Data', 'file_attributes': [0, 0], 'datasetID': filename_one, 'status': 'Active' }, { 'name': filename_two, 'type': 'Item Attributes', 'file_attributes': [0, 0], 'datasetID': filename_two, 'status': 'Active' }] pname = request.form['pname'] ptype = request.form['ptype'] user_id = current_user.user_id project_id = int(str(uuid.uuid4().int)[:6]) date = str(datetime.datetime.utcnow()) #project_id, user_id, pname, ptype, dataset, date new_project = Project(project_id, user_id, pname, ptype, dataset, date) new_project.save_to_mongo() return redirect(url_for('project_dashboard', project_id=project_id))