def introduction(): if g.user == None: return redirect(url_for('login')) if request.method == 'GET': example_index = request.args.get('example', default=0, type=int) create_table_from_csv(example_index) json_object = get_db_data_json(example_index) json_dataset = yaml.safe_load(json_object)["records"] dataset_stat = dataset_pre_analysis(json_dataset) dataset_face = dataset_preprocess(json_dataset, dataset_stat) db.session.add( User_Action('user made dataset selection {}'.format(example_index), session['user_id'])) db.session.add(User_Action('user at intro page', session['user_id'])) #log data db.session.commit() return render_template( 'introduction.html', json_data=json_object, dataset_face=dataset_face, example=str(example_index), title='Introduction') #render next page with passing json object else: return 'Invalid Data'
def index(): if g.user == None: return redirect(url_for('login')) if request.method == "GET": #handle asynchronous request db.session.add(User_Action('user at home page', session['user_id'])) #log data db.session.commit() return render_template('index.html', title='SmileyCluster') else: return 'Invalid Data'
def feedback(): if g.user == None: return redirect(url_for('login')) if request.method == "POST": #handle asynchronous request for log data req = request.get_json() db.session.add( User_Action( 'user feedback: {}, {}'.format(req['page'], req['val']), session['user_id'])) db.session.commit() res = make_response(jsonify(req), 200) return res else: return 'Invalid Data'
def stem(): if g.user == None: return redirect(url_for('login')) if request.method == 'GET': example_index = request.args.get('example', default=0, type=int) db.session.add(User_Action('user at stem page', session['user_id'])) #log data db.session.commit() return render_template('stem.html', example=str(example_index), title='What we found') else: return 'Invalid Data'
def mapping_record(): if g.user == None: return redirect(url_for('login')) if request.method == "POST": #handle asynchronous request for log data req = request.get_json() print('------------') print(req) db.session.add( User_Action('user final mapping {}'.format(req['val']), session['user_id'])) db.session.commit() res = make_response(jsonify(req), 200) return res else: return 'Invalid Data'
def cluster(): if g.user == None: return redirect(url_for('login')) if request.method == 'GET': example_index = request.args.get('example', default=0, type=int) k_value = request.args.get('k', default=2, type=int) unmapped = request.args.getlist('unmapped') unmapped_list = [str(x) for x in unmapped] unmapped_list = unmapped_list[0].split(',') # print('--------') # print(k_value) json_object = get_db_data_json(example_index) json_dataset = yaml.safe_load(json_object)["records"] dataset_stat = dataset_pre_analysis(json_dataset) dataset_face = dataset_preprocess(json_dataset, dataset_stat) # dataset_array, centroids, labels = clustering(k_value, json_dataset) dataset_array, centroids, labels = clustering(k_value, dataset_face, unmapped_list) if example_index == 2 and k_value == 4: f = open('example2.json', ) data = json.load(f) json_cluster = json.dumps(data) # print('--------') f.close() else: json_cluster = json4cluster(dataset_array, centroids, labels, example_index, dataset_face) # with open('cluster.json', 'w') as outfile: # json.dump(json_cluster , outfile) db.session.add( User_Action( 'user at cluster page with k value {} and unmapped features {}' .format(k_value, unmapped_list), session['user_id'])) #log data db.session.commit() return render_template('cluster2.html', example=str(example_index), json_data=json_object, dataset_face=dataset_face, centroids=centroids, k=k_value, json_cluster=json_cluster, title='Automatic Clustering') else: return 'Invalid Data'
def login(): valid_user = False if request.method == 'POST': session.pop('user_id', None) user_id = request.form['user_id'] user_exists = db.session.query( db.exists().where(User.id == user_id)).scalar() if user_exists: #user logged in session['user_id'] = user_id db.session.add(User_Action('successfully logged in', user_id)) #log data db.session.commit() return redirect(url_for('index')) return render_template('login.html', valid=user_exists) return render_template('login.html', valid=True)
def compare(): if g.user == None: return redirect(url_for('login')) if request.method == 'GET': example_index = request.args.get('example', default=0, type=int) json_object = get_db_data_json(example_index) json_dataset = yaml.safe_load(json_object)["records"] dataset_stat = dataset_pre_analysis(json_dataset) dataset_face = dataset_preprocess(json_dataset, dataset_stat) db.session.add(User_Action('user at compare page', session['user_id'])) #log data db.session.commit() return render_template('compare.html', example=str(example_index), json_data=json_object, dataset_face=dataset_face, title='Smilarity Comparison') else: return 'Invalid Data'
def feature_map(): if g.user == None: return redirect(url_for('login')) if request.method == 'GET': example_index = request.args.get('example', default=0, type=int) create_table_from_csv(example_index) json_object = get_db_data_json(example_index) json_dataset = yaml.safe_load(json_object)["records"] dataset_stat = dataset_pre_analysis(json_dataset) dataset_face = dataset_preprocess(json_dataset, dataset_stat) db.session.add( User_Action('user at feature mapping page', session['user_id'])) #log data db.session.commit() return render_template('feature_map.html', json_data=json_object, dataset_face=dataset_face, example=str(example_index), title='Make Your Emoji') else: return 'Invalid Data'
def logout(): db.session.add(User_Action('user logged out', session['user_id'])) #log data db.session.commit() session.pop('user_id', None) return redirect(url_for('login'))