aboutsummaryrefslogtreecommitdiffstats
path: root/Web/Server
diff options
context:
space:
mode:
authorRaspberry Pi <raspberrypi@umn.edu>2019-11-21 16:15:35 -0600
committerRaspberry Pi <raspberrypi@umn.edu>2019-11-21 16:15:35 -0600
commit85b09cd608f0c0a4c7e7c84555f8d053d324e64c (patch)
tree15ea472af07615c756e53582958e54ae37ff8b2b /Web/Server
parentRework directory structure. Modify result file printing to match requirements... (diff)
parentrequirements (diff)
downloadee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar
ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.gz
ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.bz2
ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.lz
ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.xz
ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.zst
ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.zip
Merge branch 'master' of https://github.umn.edu/damic014/ee4950-inverted-pendulum
Diffstat (limited to '')
-rw-r--r--Web/Server/Results/PLACEHOLDER0
-rw-r--r--Web/Server/Server.py82
-rw-r--r--Web/Server/static/Server.css0
-rw-r--r--Web/Server/static/Server.js10
-rw-r--r--Web/Server/templates/index.html43
5 files changed, 135 insertions, 0 deletions
diff --git a/Web/Server/Results/PLACEHOLDER b/Web/Server/Results/PLACEHOLDER
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Web/Server/Results/PLACEHOLDER
diff --git a/Web/Server/Server.py b/Web/Server/Server.py
new file mode 100644
index 0000000..a936b96
--- /dev/null
+++ b/Web/Server/Server.py
@@ -0,0 +1,82 @@
+import os
+try: #python3
+ from urllib.request import urlopen
+except: #python2
+ from urllib2 import urlopen
+from flask import Flask, flash, request, redirect, render_template, Response
+from werkzeug.utils import secure_filename
+import requests
+import json
+
+app = Flask(__name__)
+app.secret_key = "ski u mah"
+app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
+
+ALLOWED_EXTENSIONS = set(['py'])
+
+PI_URL = 'http://localhost:8000'
+
+# UNCOMMENT IF RUNNING PI.PY ON PI
+#PI_URL = 'http://192.168.1.10:8000'
+
+RESULTS_DESTINATION = "Results/results.csv"
+
+def allowed_file(filename):
+ return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
+
+@app.route('/')
+def home():
+ return render_template('index.html')
+
+@app.route('/upload', methods=['POST'])
+def upload_file():
+ 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)
+
+ # Grab the file
+ file = request.files['file']
+ if file.filename == '':
+ flash('No file selected for uploading')
+ return redirect(request.url)
+
+ # Send the file content as a post to the PI
+ if file and allowed_file(file.filename):
+
+ dictToSend = {'filename':file.filename, 'file_content':file.read()}
+ file.close
+ print('Running test')
+ response = requests.post(PI_URL + '/tests/endpoint', json=dictToSend)
+
+ results_filename = json.loads(response.text)[u'results_filename']
+ results_content = json.loads(response.text)[u'results_content']
+ flash('Results file:' + results_filename)
+ flash('Response from server:' + results_content)
+
+ results = open(RESULTS_DESTINATION, "w")
+ results.write(results_content)
+ results.close()
+
+ return render_template('index.html', results = 'True')
+ else:
+ flash('Allowed file types are .py')
+ return redirect(request.url)
+
+@app.route('/results', methods=['GET'])
+def download():
+ # Grab content from results file
+ with open(RESULTS_DESTINATION, 'r') as results:
+ results_content = results.read()
+ results.close()
+
+ # Put content as a download file
+ return Response(
+ results_content,
+ mimetype="text/csv",
+ headers={"Content-disposition":
+ "attachment; filename=results.csv"})
+
+if __name__ == "__main__":
+ app.run(host="localhost", port=5000) \ No newline at end of file
diff --git a/Web/Server/static/Server.css b/Web/Server/static/Server.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Web/Server/static/Server.css
diff --git a/Web/Server/static/Server.js b/Web/Server/static/Server.js
new file mode 100644
index 0000000..30274f2
--- /dev/null
+++ b/Web/Server/static/Server.js
@@ -0,0 +1,10 @@
+function showLoad(){
+ var paragraph = document.getElementById("message");
+ var text = document.createTextNode("RUNNING TEST");
+ paragraph.appendChild(text);
+
+ var div = document.getElementById("upload");
+ if (div.style.display !== 'none') {
+ div.style.display = 'none';
+ }
+} \ No newline at end of file
diff --git a/Web/Server/templates/index.html b/Web/Server/templates/index.html
new file mode 100644
index 0000000..70a282b
--- /dev/null
+++ b/Web/Server/templates/index.html
@@ -0,0 +1,43 @@
+<html>
+ <head>
+ <link rel="stylesheet" href="/static/Server.css">
+ <script type="text/javascript" src="/static/Server.js"></script>
+ </head>
+ <body>
+ <title>ANDI'S PIE</title>
+ <div id="upload">
+ <h2>Select a file to upload</h2>
+ <p>
+ {% with messages = get_flashed_messages() %}
+ {% if messages %}
+ <ul class=flashes>
+ {% for message in messages %}
+ <li>{{ message }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ {% endwith %}
+ </p>
+
+ <form method="post" action="/upload" enctype="multipart/form-data">
+ <dl>
+ <p>
+ <input type="file" name="file" autocomplete="off" required>
+ </p>
+ </dl>
+ <p>
+ <input type="submit" value="Submit" onclick="showLoad()">
+ </p>
+ </form>
+ </div>
+
+ <div id="message"></div>
+
+ {% if results %}
+ <form method="get" action="/results">
+ <button type="submit">Download!</button>
+ </form>
+ {% endif %}
+
+ </body>
+</html> \ No newline at end of file