def view_fd(): if session.get('u-type') is None: return render_template('error_page.html') # Fetching from Local Server fd_obj = fd.FdDAO() fd_names = fd_obj.fetch_all_fd() #Fetching from Cloud Server import boto3 import botocore s3 = boto3.client('s3') dynamoDB = boto3.resource('dynamodb') dynamoTable = dynamoDB.Table('feedback-form-data') response = dynamoTable.scan() items = response['Items'] BUCKET_NAME = 'feedback-data-try' s3 = boto3.resource('s3') KEY=[] fd_cloud_names = items for val in items: KEY.append('static/DBAlpha/FeedbackDB/Images/'+str(val['fd_img'])) try: s3.Bucket(BUCKET_NAME).download_file('static/DBAlpha/FeedbackDB/Images/'+str(val['fd_img']), 'static/DBAlpha/FeedbackDB/Images/Cloud/'+str(val['fd_img'])) except botocore.exceptions.ClientError as e: if e.response['Error']['Code'] == "404": print("The object does not exist.") else: raise # Rendering the template with both local and cloud feedback dataset details return render_template('viewFeedbackDatasets.html',fd_names = fd_names, fd_cloud_names = fd_cloud_names)
def add_fd_confirm(): if session.get('u-type') is None: return render_template('error_page.html') if request.method == "POST": fd_name = request.form['fd-name'] thumb_img = request.files['thumb-nail'] fd_file = request.files['fd-file'] thumb_img_name = secure_filename(thumb_img.filename) fd_file_name = secure_filename(fd_file.filename) desc = request.form['fd-desc'] td_id = request.form['td-id'] fd_obj = fd.FdDAO() from datetime import date,datetime today = date.today() text_to_append = str(datetime.now())[:-7].replace(":","").replace(" ","").replace("-","") file_name1 = os.path.splitext(thumb_img_name) thumb_img_name ="IMG" + str(text_to_append) +file_name1[1] file_name1 = os.path.splitext(fd_file_name) fd_file_name = "TD"+ str(text_to_append) +file_name1[1] if request.form['cloud_local'] == 'local': thumb_img.save(os.path.join(app.config['UPLOAD_FEEDBACK_IMAGES'], thumb_img_name)) fd_file.save(os.path.join(app.config['UPLOAD_FEEDBACK_FILES'], fd_file_name)) status = fd_obj.setData(fd_name, thumb_img_name,str(td_id), fd_file_name, desc, str(today),"sample.json") elif request.form['cloud_local'] == 'cloud': thumb_img.save(os.path.join(app.config['UPLOAD_CLOUD_FEEDBACK_IMAGES'], thumb_img_name)) fd_file.save(os.path.join(app.config['UPLOAD_CLOUD_FEEDBACK_FILES'], fd_file_name)) import boto3 s3 = boto3.client('s3') with open(os.path.join(app.config['UPLOAD_CLOUD_FEEDBACK_FILES'], fd_file_name), "rb") as f: s3.upload_fileobj(f, "feedback-data-try", 'static/DBAlpha/FeedbackDB/Files/'+str(fd_file_name)) with open(os.path.join(app.config['UPLOAD_CLOUD_FEEDBACK_IMAGES'], thumb_img_name), "rb") as f: s3.upload_fileobj(f, "feedback-data-try", 'static/DBAlpha/FeedbackDB/Images/'+str(thumb_img_name)) if os.path.exists(os.path.join(app.config['UPLOAD_CLOUD_FEEDBACK_FILES'], fd_file_name)): os.remove(os.path.join(app.config['UPLOAD_CLOUD_FEEDBACK_FILES'], fd_file_name)) else: print("The file does not exist") if os.path.exists(os.path.join(app.config['UPLOAD_CLOUD_FEEDBACK_IMAGES'], thumb_img_name)): os.remove(os.path.join(app.config['UPLOAD_CLOUD_FEEDBACK_IMAGES'], thumb_img_name)) else: print("The file does not exist") dynamoDB = boto3.resource('dynamodb') dynamoTable = dynamoDB.Table('feedback-form-data') time_field = str(datetime.now()).replace(":","").replace(" ","").replace("-","") dynamoTable.put_item( Item = { "date":str(time_field), "fd_desc":desc, "fd_file":fd_file_name, "fd_img":thumb_img_name, "fd_name":fd_name, "result_page":"sample.json", "td_id":str(td_id) } ) status = 1 return render_template("confirmTD.html", status = status)
def downloadProgressTimelineAnalysisCSV(fd_id): if session.get('u-type') is None: return render_template('error_page.html') if fd_id == str(-1): fd_file = "WebAPI" elif len(fd_id)>14: fd_file = main_cloud.get_file_name_by_id(fd_id) fd_file = re.sub(".json", "", fd_file) else: fd_dao = fd.FdDAO() fd_file = fd_dao.getFileNamebyID(fd_id) fd_file = re.sub(".json", "", fd_file) file_name = fd_file+'_Progress_Timeline.csv' return send_file(str(DOWNLOAD_RESULT_FILE)+str(file_name),as_attachment=True)
def downloadOverallAnalysisXLSX(fd_id): if session.get('u-type') is None: return render_template('error_page.html') if fd_id == str(-1): fd_file = "WebAPI" elif len(fd_id)>14: fd_file = main_cloud.get_file_name_by_id(fd_id) fd_file = re.sub(".json", "", fd_file) else: fd_dao = fd.FdDAO() fd_file = fd_dao.getFileNamebyID(fd_id) fd_file = re.sub(".json", "", fd_file) file_name = fd_file+'_Individual_Comment_Ratings.xlsx' return send_file(str(DOWNLOAD_RESULT_FILE)+str(file_name),as_attachment=True)
def edit_fd_data(): if session.get('u-type') is None: return render_template('error_page.html') if request.method =="POST": fd_id = request.form['fd-id'] fd_dao = fd.FdDAO() fd_obj = fd.FdObj() fd_obj = fd_dao.getData(fd_id) req_type = request.form['submit'] if req_type =="modify": td_dao = td.TdDAO() training_data_dict = td_dao.fetch_all_td() td_obj = td.TdObj() td_obj = td_dao.getData(fd_obj.tid) return render_template("editFeedbackDataset.html", p = fd_obj, td_id = td_obj.id, dict_training_data = training_data_dict, storage_type= str("local")) elif req_type =="result-page": td_dao = td.TdDAO() model_file = td_dao.getFileNamebyID(fd_obj.tid) model_file = re.sub(".json", "", model_file) aspect_json, overall_rate, progress_json, suggestions_json = full_analysis(file_name = fd_obj.file, model_file = model_file, no_entities = 2, lang="") return render_template("results.html", aspect_json = aspect_json, overall_rate = overall_rate, progress_json = progress_json, suggestions_json = suggestions_json, fd_id = fd_id)
def edit_fd_data_Confirm(): if session.get('u-type') is None: return render_template('error_page.html') if request.method == "POST": storage_type = request.form['storage-type'] req_type = request.form['submit'] fd_obj = fd.FdDAO() if storage_type == "local": if req_type == "update": fd_id = request.form['fd-id'] fd_name = request.form['fd-name'] fd_desc = request.form['fd-desc'] fd_td = request.form['fd-td'] status = (fd_obj.updateName(fd_id, fd_name)) and (fd_obj.updateDesc(fd_id, fd_desc)) and (fd_obj.updateTrainingData(fd_id, fd_td)) elif req_type == "remove": fd_id = request.form['fd-id'] status = fd_obj.delete_dataset(fd_id, UPLOAD_FEEDBACK_FILES+str(request.form['fd-file']), UPLOAD_FEEDBACK_IMAGES+str(request.form['fd-img']), DOWNLOAD_RESULT_FILE, request.form['fd-file']) print("Dataset Deleted Status: ", status) elif storage_type == "cloud": fd_id = request.form['fd-id'] if req_type == "update": fd_name = request.form['fd-name'] fd_desc = request.form['fd-desc'] fd_td = request.form['fd-td'] import boto3 dynamoDB = boto3.resource('dynamodb') dynamoTable = dynamoDB.Table('feedback-form-data') dynamoTable.update_item( Key = { 'date':fd_id }, UpdateExpression = 'SET fd_name = :name, fd_desc = :desc, td_id = :td', ExpressionAttributeValues = { ':name': fd_name, ':desc': fd_desc, ':td': fd_td }, ) elif req_type== "remove": fd_img = request.form['fd-img'] fd_file = request.form['fd-file'] import boto3 dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('feedback-form-data') status = fd_obj.delete_cloud_files(UPLOAD_FEEDBACK_FILES+str(request.form['fd-file']), UPLOAD_CLOUD_FEEDBACK_IMAGES+str(request.form['fd-img']), DOWNLOAD_RESULT_FILE, request.form['fd-file']) print("Dataset Deleted Status: ", status) table.delete_item( Key={'date': fd_id}) client = boto3.client('s3') responseDeleteFile = client.delete_object( Bucket='feedback-data-try', Key='static/DBAlpha/FeedbackDB/Files/'+fd_file ) responseDeleteImage = client.delete_object( Bucket='feedback-data-try', Key='static/DBAlpha/FeedbackDB/Images/'+fd_img ) print("File Deleted Response: ",responseDeleteFile) print("Image Deleted Response: ", responseDeleteImage) # Fetching all records to present fd_names = fd_obj.fetch_all_fd() import boto3 import botocore s3 = boto3.client('s3') dynamoDB = boto3.resource('dynamodb') dynamoTable = dynamoDB.Table('feedback-form-data') response = dynamoTable.scan() items = response['Items'] BUCKET_NAME = 'feedback-data-try' # Bucket name s3 = boto3.resource('s3') KEY=[] fd_cloud_names = items for val in items: KEY.append('static/DBAlpha/FeedbackDB/Images/'+str(val['fd_img'])) try: s3.Bucket(BUCKET_NAME).download_file('static/DBAlpha/FeedbackDB/Images/'+str(val['fd_img']), 'static/DBAlpha/FeedbackDB/Images/Cloud/'+str(val['fd_img'])) except botocore.exceptions.ClientError as e: if e.response['Error']['Code'] == "404": print("The object does not exist.") else: raise # Rendering the view feedbak data template return render_template('viewFeedbackDatasets.html',fd_names = fd_names, fd_cloud_names = fd_cloud_names)