[chronojump-server] Added chronojump-flask



commit 5637e184d9af44e8aed21f02d0e29baaea1e4bc2
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 1 21:38:09 2017 +0200

    Added chronojump-flask

 chronojump-flask/chronojump_server.py             |  117 ++++++++++++++++++
 chronojump-flask/static/styles/input.css          |  127 +++++++++++++++++++
 chronojump-flask/static/styles/tables.css         |   70 +++++++++++
 chronojump-flask/templates/index.html             |   31 +++++
 chronojump-flask/templates/player_add.html        |   34 +++++
 chronojump-flask/templates/player_add_result.html |   17 +++
 chronojump-flask/templates/player_list.html       |   45 +++++++
 chronojump-flask/templates/sets.html              |  136 +++++++++++++++++++++
 tables.txt                                        |   13 ++
 9 files changed, 590 insertions(+), 0 deletions(-)
---
diff --git a/chronojump-flask/chronojump_server.py b/chronojump-flask/chronojump_server.py
new file mode 100644
index 0000000..998fdf6
--- /dev/null
+++ b/chronojump-flask/chronojump_server.py
@@ -0,0 +1,117 @@
+from flask import Flask, render_template, request, jsonify
+from flaskext.mysql import MySQL
+
+
+mysql = MySQL()
+app = Flask(__name__)
+app.config['MYSQL_DATABASE_USER'] = 'root'
+app.config['MYSQL_DATABASE_PASSWORD'] = '' #TODO change this
+app.config['MYSQL_DATABASE_DB'] = 'chronojump'
+app.config['MYSQL_DATABASE_HOST'] = 'localhost'
+mysql.init_app(app)
+
+
+def getHeader(pageTitle):
+    headerPre="<div id=\"textbox\"><p class=\"topalignleft\"><b>";
+    headerPost="</b></p><p class=\"topalignright\"><a href=\"/\">Inici</a></p></div><div style=\"clear: 
both;\"></div>";
+    return headerPre + pageTitle + headerPost;
+
+@app.route('/')
+def main():
+    return render_template('index.html')
+
+
+#call:
+#http://192.168.200.1:5000/sets
+@app.route("/sets")
+def Sets():
+    date = request.args.get('date') #days
+    personId = request.args.get('pId')
+    machineId = request.args.get('mId')
+    cursor = mysql.connect().cursor()
+
+    if date is None or date == "" or date == "Any":
+        dateStr = ""
+    else:
+        dateStr = " AND FLOOR(TO_DAYS(NOW()) - TO_DAYS(dt)) <= " + date
+
+    if machineId is None or machineId == "" or machineId == "All":
+        machineStr = ""
+    else:
+        machineStr = " AND machineId = " + machineId;
+    
+    if personId is None or personId == "" or personId == "All":
+        personStr = "";
+    else:
+        personStr = " AND person.uniqueID = " + personId;
+
+    cursor.execute("SELECT encoderData.dt, person.name, encoderData.machineId, encoderData.exerciseName, 
encoderData.meanPowerBestRep, encoderData.repsAbove50pBest" +
+                " FROM encoderData, person WHERE encoderData.personId = person.uniqueID " + personStr + 
dateStr + machineStr);
+    sets = cursor.fetchall()
+        
+    cursor.execute("SELECT encoderData.personId, person.name FROM encoderData, " + 
+            "person WHERE encoderData.personId = person.uniqueID GROUP BY person.uniqueId");
+    persons = cursor.fetchall()
+
+    return render_template('sets.html', header=getHeader("S&egrave;ries d'encoder"), date=date, 
pId=personId, mId=machineId, sets=sets, persons=persons)
+
+@app.route('/player_list')
+def list():
+    cursor = mysql.connect().cursor()
+    cursor.execute("select * from person")
+
+    rows = cursor.fetchall(); 
+    return render_template("player_list.html", header = getHeader("Llistat de jugadors"), rows = rows)
+
+@app.route('/player_add')
+def player_add():
+        name = request.args.get('name')
+        weight = request.args.get('weight')
+        rfid0 = request.args.get('rfid0')
+        rfid1 = request.args.get('rfid1')
+        rfid2 = request.args.get('rfid2')
+        rfid3 = request.args.get('rfid3')
+        return render_template('player_add.html', header = getHeader("Afegir jugador"),
+                name=name, weight=weight, rfid0=rfid0, rfid1=rfid1, rfid2=rfid2, rfid3=rfid3)
+
+@app.route('/player_add_submit',methods = ['POST', 'GET'])
+def player_add_submit():
+    if request.method == 'POST':
+        msg = ""
+            
+        name = request.form['name']
+        weight = request.form['weight']
+        rfid0 = request.form['rfid0']
+        rfid1 = request.form['rfid1']
+        rfid2 = request.form['rfid2']
+        rfid3 = request.form['rfid3']
+
+        if name is None or name == "":
+            return render_template("player_add_result.html", header = getHeader("Afegir jugador"),
+                    added=False, msg = "Falta el nom del jugador", name=name, weight=weight, rfid0=rfid0, 
rfid1=rfid1, rfid2=rfid2, rfid3=rfid3)
+
+
+        rfid = rfid0 + "," + rfid1 + "," + rfid2 + "," + rfid3
+
+        db = mysql.connect()
+        cursor = db.cursor()
+        
+        cursor.execute("SELECT * FROM person WHERE name = '" + name + "'");
+        rows = cursor.fetchall()
+        if rows:
+            msg = "Error, ja existeix: " + name
+            added = False;
+        else:
+            cursor.execute("INSERT INTO person (name,weight,rfid) VALUES (" +
+                    "'" + name + "', " + str(weight) + ", '" + rfid + "')")
+            db.commit()
+            msg = "Afegit " + name
+            added = True;
+
+        return render_template("player_add_result.html", header = getHeader("Afegir jugador"),
+                added=added, msg = msg, name=name, weight=weight, rfid0=rfid0, rfid1=rfid1, rfid2=rfid2, 
rfid3=rfid3)
+
+
+if __name__ == "__main__":
+    app.run()
+
diff --git a/chronojump-flask/static/styles/input.css b/chronojump-flask/static/styles/input.css
new file mode 100644
index 0000000..db8c178
--- /dev/null
+++ b/chronojump-flask/static/styles/input.css
@@ -0,0 +1,127 @@
+.topalignleft {
+       font-size: 20px;
+       float: left;
+}
+.topalignright {
+       font-size: 20px;
+       width: 1000px;
+       float: right;
+}
+
+.alignleft {
+       float: left;
+}
+.alignright {
+       width: 1000px;
+       float: right;
+}
+
+ul.main {
+       /*list-style: none; 
+       margin-left: 0;
+       padding-left: 1em;
+       text-indent: -1em;
+       */
+       font-size: 20px;
+       line-height:40px;
+}
+
+section.border button {
+       color: #6496c8;
+       background: rgba(0,0,0,0);
+       border: solid 5px #6496c8;
+       font-size: 24px;
+}
+section.border button:hover,
+section.border button.hover {
+       border-color: #346392;
+       color: #346392;
+}
+section.border button:active,
+section.border button.active {
+       border-color: #27496d;
+       color: #27496d;
+}
+
+
+/*
+ * http://viralpatel.net/blogs/css-radio-button-checkbox-background/
+ */
+
+div + p {
+       color: red;
+}
+
+/*
+ *   Hide radio button (the round disc)
+ *     we will use just the label to create pushbutton effect
+ *     */
+input[type=radio] {
+       display:none; 
+       margin:10px;
+}
+
+/*
+ *   Change the look'n'feel of labels (which are adjacent to radiobuttons).
+ *     Add some margin, padding to label
+ *     */
+input[type=radio] + label {
+       display:inline-block;
+       margin:-2px;
+       padding: 6px 12px;
+       background-color: #e7e7e7;
+       border-color: #ddd;
+}
+/*
+ *  Change background color for label next to checked radio button
+ *   to make it look like highlighted button
+ *   */
+input[type=radio]:checked + label { 
+       background-image: none;
+       background-color:#0e1e46;
+       color:white;
+}
+
+input[type=submit] { 
+       display:inline-block;
+       margin:-2px;
+       padding: 6px 12px;
+       background-image: none;
+       background-color:#0e1e46;
+       color:white;
+}
+
+/* don't allow to select */
+.noselect {
+       -webkit-touch-callout: none; /* iOS Safari */
+       -webkit-user-select: none; /* Safari */
+       -khtml-user-select: none; /* Konqueror HTML */
+       -moz-user-select: none; /* Firefox */
+       -ms-user-select: none; /* Internet Explorer/Edge */
+       user-select: none; /* Non-prefixed version, currently supported by Chrome and Opera */
+}
+
+/* hide input spinbox */
+input::-webkit-outer-spin-button,
+input::-webkit-inner-spin-button {
+       /* display: none; <- Crashes Chrome on hover */
+       -webkit-appearance: none;
+       margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
+}
+
+input[type="number"] {
+       width:50px;
+}
+
+.styled-select {
+       /*background: url(http://i62.tinypic.com/15xvbd5.png) no-repeat 96% 0;*/
+       height: 29px;
+       overflow: hidden;
+       /* width: 240px; */
+}
+.styled-select.slate select {
+       border: 1px solid #ccc;
+       font-size: 20px;
+       height: 30px;
+       /* width: 268px; */
+}
diff --git a/chronojump-flask/static/styles/tables.css b/chronojump-flask/static/styles/tables.css
new file mode 100644
index 0000000..f299042
--- /dev/null
+++ b/chronojump-flask/static/styles/tables.css
@@ -0,0 +1,70 @@
+/* ------------------
+
+ styling for the tables 
+
+   ------------------   */
+
+
+body
+
+{
+       line-height: 1.2em;
+}
+
+
+
+#newspaper-a
+
+{
+
+       font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
+
+       font-size: 12px;
+
+       /*margin: 45px;*/
+
+       width: 1000px;
+
+       text-align: left;
+
+       border-collapse: collapse;
+
+       border: 1px solid #0e1e46;
+
+}
+
+#newspaper-a th
+
+{
+
+       padding: 12px 17px 12px 17px;
+
+       font-weight: normal;
+
+       font-size: 14px;
+
+       color: #0e1e46;
+
+       border-bottom: 1px dashed #0e1e46;
+
+}
+
+#newspaper-a td
+
+{
+
+       padding: 7px 17px 7px 17px;
+
+       color: #669;
+
+}
+
+#newspaper-a tbody tr:hover td
+
+{
+
+       color: #339;
+
+       background: #d0dafd;
+
+}
diff --git a/chronojump-flask/templates/index.html b/chronojump-flask/templates/index.html
new file mode 100644
index 0000000..0be39e3
--- /dev/null
+++ b/chronojump-flask/templates/index.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html lang="ca">
+  <head>
+    <title>Chronojump encoder</title>
+    <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/tables.css') }}">
+    <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/input.css') }}">
+  </head>
+
+  <body>
+         <h2>Chronojump encoder</h2>
+
+         <br></br>
+         <section class="border">
+                 <a href="sets"><button>Veure sèries d'encoder</button></a>
+                 &nbsp;&nbsp;&nbsp;<a href="player_list"><button>Llistat jugadors</button></a>
+                 &nbsp;&nbsp;&nbsp;<a href="player_add"><button>Afegir jugador</button></a>
+                 &nbsp;&nbsp;&nbsp;<a href="rfid_lost"><button>RFID perduda</button></a>
+         </section>
+         
+         <!--
+         <ul class="main">
+                 <li><a href="sets">Veure sèries d'encoder</a></li>
+                 <li><a href="player_list">Llistat jugadors</a></li>
+                 <li><a href="player_add">Afegir jugador</a></li>
+                 <li><a href="rfid_lost">RFID perduda</a></li>
+         </ul>
+         -->
+
+  </body>
+</html>
+
diff --git a/chronojump-flask/templates/player_add.html b/chronojump-flask/templates/player_add.html
new file mode 100644
index 0000000..1865edb
--- /dev/null
+++ b/chronojump-flask/templates/player_add.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html lang="ca">
+  <head>
+    <title>Chronojump encoder - afegir jugador</title>
+    <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/tables.css') }}">
+    <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/input.css') }}">
+  </head>
+
+  <body>
+         {{ header|safe }}
+               
+         {% if (not name or name==None) %}
+         {% set name = "" %}
+         {% endif %}
+         <form action = "{{ url_for('player_add_submit') }}" method = "POST">
+                 Nom complet<br>
+                 <input type = "text" name = "name" value="{{name}}"/></br>
+
+                 <br>Pes (Kg)<br>
+                 <input type="number" name="weight" step="0.1" min=50 value="{{weight}}"></br>
+
+                 <br>RFID<br>
+                 <input type="number" name="rfid0" step="1" min=0 max=256 value="{{rfid0}}">
+                 <input type="number" name="rfid1" step="1" min=0 max=256 value="{{rfid1}}">
+                 <input type="number" name="rfid2" step="1" min=0 max=256 value="{{rfid2}}">
+                 <input type="number" name="rfid3" step="1" min=0 max=256 value="{{rfid3}}">
+                 </br>
+
+                 <br>
+                 <input type = "submit" value = "Afegeix" /><br>
+         </form>
+  </body>
+</html>
+
diff --git a/chronojump-flask/templates/player_add_result.html 
b/chronojump-flask/templates/player_add_result.html
new file mode 100644
index 0000000..2cf83cf
--- /dev/null
+++ b/chronojump-flask/templates/player_add_result.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="ca">
+  <head>
+    <title>Chronojump encoder - afegir jugador</title>
+    <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/tables.css') }}">
+    <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/input.css') }}">
+  </head>
+
+  <body>
+         {{ header|safe }}
+         <br><br>Resultat : {{ msg }}
+         {% if not added %}
+         <a 
href="player_add?name={{name}}&weight={{weight}}&rfid0={{rfid0}}&rfid1={{rfid1}}&rfid2={{rfid2}}&rfid3={{rfid3}}">Tornar</a>
+         {% endif %}
+  </body>
+</html>
+
diff --git a/chronojump-flask/templates/player_list.html b/chronojump-flask/templates/player_list.html
new file mode 100644
index 0000000..4b49dc9
--- /dev/null
+++ b/chronojump-flask/templates/player_list.html
@@ -0,0 +1,45 @@
+<!doctype html>
+<html lang="ca">
+       <head>
+               <title>Chronojump encoder - Veure resultats</title>
+               <link rel= "stylesheet" type= "text/css" href= "{{ 
url_for('static',filename='styles/tables.css') }}">
+               <link rel= "stylesheet" type= "text/css" href= "{{ 
url_for('static',filename='styles/input.css') }}">
+       </head>
+       <body>
+               {{ header|safe }}
+
+               <!--
+               <form action=sets>
+                       <input type="radio" id="pIdAll" name="pId" value="All">
+                       <label for="pIdAll">Tots</label>
+                       
+                       {% for row in rows %}
+                       &nbsp;&nbsp;&nbsp;&nbsp;
+                       <input type="radio" id="{{row[0]}}" name="pId" value="{{row[0]}}">
+                       <label for="{{row[0]}}">{{row[1]}}</label>
+                       {% endfor %}
+
+                       <br></br><br></br><input type="submit" value="Selecciona">
+                       </p>
+               </form>
+               -->
+               
+               <table id="newspaper-a">
+                       <thead>
+                               <th>id</th>
+                               <th>Nom</th>
+                               <th>Pes</th>
+                               <th>RFID</th>
+                       </thead>
+
+                       {% for row in rows %}
+                       <tr>
+                               <td>{{row[0]}}</td>
+                               <td>{{row[1]}}</td>     
+                               <td>{{row[2]}}</td>
+                               <td>{{row[3]}}</td>     
+                       </tr>
+                       {% endfor %}
+               </table>
+       </body>
+</html>
diff --git a/chronojump-flask/templates/sets.html b/chronojump-flask/templates/sets.html
new file mode 100644
index 0000000..b2101e1
--- /dev/null
+++ b/chronojump-flask/templates/sets.html
@@ -0,0 +1,136 @@
+<!doctype html>
+<html lang="ca">
+       <head>
+               <title>Chronojump encoder - Veure sèries</title>
+               <link rel= "stylesheet" type= "text/css" href= "{{ 
url_for('static',filename='styles/tables.css') }}">
+               <link rel= "stylesheet" type= "text/css" href= "{{ 
url_for('static',filename='styles/input.css') }}">
+       </head>
+       <body>
+
+               {% if (not date or date == "") %}
+               {% set date = "Any" %}
+               {% endif %}
+
+               {% if (not pId or pId == "") %}
+               {% set pId = "All" %}
+               {% endif %}
+
+               {% if (not mId or mId == "") %}
+               {% set mId = "All" %}
+               {% endif %}
+               
+               {% if (not persons or persons == "") %}
+               {% set persons = "" %}
+               {% endif %}
+
+
+               {{ header|safe }}
+
+               <form action=sets>
+<div id="textbox"><p class="alignleft">
+
+                       Jugador:
+
+                       <span class="styled-select slate">
+                               <select name="pId">
+                                       {% if pId == "All" %}
+                                       <option value="All" selected="selected">Tots</option>
+                                       {% else %}
+                                       <option value="All">Tots</option>
+                                       {% endif %}
+
+                                       {% for row in persons %}
+                                               {% if pId|string() == row[0]|string() %}
+                                               <option value="{{row[0]}}" 
selected="selected">{{row[1]}}</option>        
+                                               {% else %}
+                                               <option value="{{row[0]}}">{{row[1]}}</option>        
+                                               {% endif %}
+                                       {% endfor %}
+                               </select>
+                       </span>
+                                               
+                       &nbsp;&nbsp;&nbsp;Data: 
+
+                       <span class="noselect"> <!-- make values not selectable (highlight by cursor) -->
+                       {% if date == "7" %}
+                       <input type="radio" id="date7" name="date" value="7" checked="checked">
+                       {% else %}
+                       <input type="radio" id="date7" name="date" value="7">
+                       {% endif %}
+                       <label for="date7">7d</label>
+
+                       {% if date == "14" %}
+                       <input type="radio" id="date14" name="date" value="14" checked="checked">
+                       {% else %}
+                       <input type="radio" id="date14" name="date" value="14">
+                       {% endif %}
+                       <label for="date14">14d</label>
+
+                       {% if date == "Any" %}
+                       <input type="radio" id="dateAny" name="date" value="Any" checked="checked">
+                       {% else %}
+                       <input type="radio" id="dateAny" name="date" value="Any">
+                       {% endif %}
+                       <label for="dateAny">Sempre</label>
+                       </span>
+
+
+                       &nbsp;&nbsp;&nbsp;Màquina: 
+
+                       <span class="noselect"> <!-- make values not selectable (highlight by cursor) -->
+                       {% if mId == "All" %}
+                       <input type="radio" id="mIdAll" name="mId" value="All" checked="checked">
+                       {% else %}
+                       <input type="radio" id="mIdAll" name="mId" value="All">
+                       {% endif %}
+                       <label for="mIdAll">Totes</label>
+
+                       {% if mId == "1" %}
+                       <input type="radio" id="mId1" name="mId" value="1" checked="checked">
+                       {% else %}
+                       <input type="radio" id="mId1" name="mId" value="1">
+                       {% endif %}
+                       <label for="mId1">1</label>
+
+                       {% if mId == "2" %}
+                       <input type="radio" id="mId2" name="mId" value="2" checked="checked">
+                       {% else %}
+                       <input type="radio" id="mId2" name="mId" value="2">
+                       {% endif %}
+                       <label for="mId2">2</label>
+                       </span>
+
+</p>
+ <p class="alignright"><input type="submit" value="Canvia"></p></div>
+<div style="clear: both;"></div>
+               </form>
+
+               <!-- https://www.smashingmagazine.com/2008/08/top-10-css-table-designs/#7-newspaper -->
+               <table id="newspaper-a">
+                       <thead>
+                               <th>Data</th>
+                               {% if pId == "All" %}
+                                       <th>Jugador</th>
+                               {% endif %}
+                               <th>Màquina</th>
+                               <th>Exercici</th>
+                               <th>Potencia mitjana</th>
+                               <th>Repeticions bones</th>
+                       </thead>
+
+                       {% for set in sets %}
+                       <tr>
+                               <td>{{set[0]}}</td>
+                               {% if pId == "All" %}
+                                       <td>{{set[1]}}</td>     
+                               {% endif %}
+                               <td>{{set[2]}}</td>
+                               <td>{{set[3]}}</td>     
+                               <td>{{set[4]}}</td>     
+                               <td>{{set[5]}}</td>     
+                       </tr>
+                       {% endfor %}
+               </table>
+
+       </body>
+</html>
diff --git a/tables.txt b/tables.txt
new file mode 100644
index 0000000..d398ca4
--- /dev/null
+++ b/tables.txt
@@ -0,0 +1,13 @@
+#this table is created just to test json
+
+CREATE TABLE encoderData(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, dt TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 
personId INT, machineId INT, exerciseName CHAR(30), meanPowerBestRep FLOAT, repsAbove50pBest INT);
+
+CREATE TABLE machine(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name CHAR(30));
+
+
+CREATE TABLE rfid(dt TIMESTAMP DEFAULT CURRENT_TIMESTAMP, personID INT NOT NULL, rfid CHAR(30));
+
+CREATE TABLE person(uniqueID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name CHAR(30), weight FLOAT, rfid 
CHAR(15));
+
+NO USAR: aquesta és la del client
+CREATE TABLE person(uniqueID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name CHAR(30), sex CHAR(20), dateborn 
CHAR(20), race INT, countryID INT, description CHAR(20), future1 CHAR(20), future2 CHAR(20), serverUniqueID 
INT);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]