Skip to content

Commit

Permalink
Added upload template and upload/parsing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Hanif committed Nov 16, 2019
1 parent 7b90e1f commit 4829e31
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
12 changes: 12 additions & 0 deletions data/sample_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
query_number, metric_type (NDCG; MAP; etc), score (float)
1, NDCG, 0.078
2, MAP, 1
3, MAP, 2
4, MAP, 3
5, MAP, 4
6, MAP, 5
7, MAP, 6
8, MAP, 7
9, MAP, 8
10, MAP, 9
11, MAP, 10.0
54 changes: 41 additions & 13 deletions src/server.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,55 @@
from flask import Flask
import psycopg2
from flask import Flask, flash, request, redirect, url_for
from werkzeug.utils import secure_filename
import os
import pandas as pd
import redis
import io

app = Flask(__name__)

ALLOWED_EXTENSIONS = {'txt', 'csv'}

POSTGRES_USER = "818_user"
POSTGRES_PW = "818"
POSTGRES_URL = "127.0.0.1:5432"
POSTGRES_DB = "project"

def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@app.route('/upload', methods=['GET', 'POST'])
def upload():
if flask.request.method == 'POST':
return 'Submitted experiment.'
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file_contents = file.read()
data = file_contents.decode("utf-8")
df = pd.read_csv(io.StringIO(data), delimiter=',', header='infer')

print(df)


return '''<form method="POST">
Data: <input type="text" name="data"><br>
<input type="submit" value="Submit"><br>
</form>'''
return redirect(url_for('upload', filename=filename))
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
'''

@app.route('/compare/<path:experiment_one>/<path:experiment_two>')
def compare():
Expand All @@ -32,9 +64,5 @@ def hello():
return 'Hello!'

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
# Connect to an existing database
conn = psycopg2.connect("dbname=test user=postgres")

# Open a cursor to perform database operations
cur = conn.cursor()
app.run(debug=True, host='0.0.0.0')

0 comments on commit 4829e31

Please sign in to comment.