[chronojump-server] Updated chronojump-flask
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Updated chronojump-flask
- Date: Tue, 2 May 2017 19:01:54 +0000 (UTC)
commit a0d9b396d45ea5e36bd683410feb9bed23a5e3d2
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue May 2 21:01:08 2017 +0200
Updated chronojump-flask
chronojump-flask/chronojump_server.py | 68 +++++++----
chronojump-flask/static/js/js.js | 3 +
chronojump-flask/static/styles/input.css | 8 +-
chronojump-flask/static/styles/tables.css | 2 +-
chronojump-flask/templates/player_add.html | 38 ++++--
chronojump-flask/templates/player_add_result.html | 11 ++-
chronojump-flask/templates/player_list.html | 18 +---
chronojump-flask/templates/sets.html | 142 +++++++++++----------
main.py | 15 ++-
9 files changed, 170 insertions(+), 135 deletions(-)
---
diff --git a/chronojump-flask/chronojump_server.py b/chronojump-flask/chronojump_server.py
index 998fdf6..ed8ecda 100644
--- a/chronojump-flask/chronojump_server.py
+++ b/chronojump-flask/chronojump_server.py
@@ -1,5 +1,7 @@
from flask import Flask, render_template, request, jsonify
from flaskext.mysql import MySQL
+import subprocess
+import os
mysql = MySQL()
@@ -46,7 +48,8 @@ def Sets():
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);
+ " FROM encoderData, person WHERE encoderData.personId = person.uniqueID " + personStr +
dateStr + machineStr +
+ " ORDER by id DESC");
sets = cursor.fetchall()
cursor.execute("SELECT encoderData.personId, person.name FROM encoderData, " +
@@ -67,49 +70,66 @@ def list():
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')
+ rfid = request.args.get('rfid')
+
return render_template('player_add.html', header = getHeader("Afegir jugador"),
- name=name, weight=weight, rfid0=rfid0, rfid1=rfid1, rfid2=rfid2, rfid3=rfid3)
+ name=name, weight=weight, rfid=rfid)
@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']
+ #1 check if name is null
if name is None or name == "":
+ msg += " [Falta el nom del jugador] "
+ if weight is None or weight == "" or weight == 0:
+ msg += " [Falta el pes] "
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
+ added=False, msg = msg, name=name, weight=weight, rfid="")
db = mysql.connect()
cursor = db.cursor()
+ #2 check if person exists
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;
+ msg = "Error, ja existeix el jugador: " + name
+ return render_template("player_add_result.html", header = getHeader("Afegir jugador"),
+ added=False, msg = msg, name=name, weight=weight, rfid="")
+
+
+ #3 read RFID
+ rfidFile = '/tmp/chronojump_rfid.txt'
+
+ if os.access(rfidFile, os.W_OK):
+ os.remove(rfidFile)
+
+ rfidReadedStatus = subprocess.call("/usr/local/bin/chronojump_rfid_capture_exit.py", shell=True)
+
+ try:
+ with open(rfidFile) as f:
+ rfid = f.read()
+ except:
+ rfid = ""
+
+ if rfid == "":
+ return render_template("player_add_result.html", header = getHeader("Afegir jugador"),
+ added=False, msg = "No s'ha detectat el RFID", name=name, weight=weight, rfid=rfid)
+
+
+ #4 insert person and show success
+ cursor.execute("INSERT INTO person (name,weight,rfid) VALUES (" +
+ "'" + name + "', " + str(weight) + ", '" + rfid + "')")
+ db.commit()
+ msg = "Afegit " + name
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)
+ added=True, msg = msg, name=name, weight=weight, rfid=rfid)
if __name__ == "__main__":
diff --git a/chronojump-flask/static/js/js.js b/chronojump-flask/static/js/js.js
new file mode 100644
index 0000000..cbc9f73
--- /dev/null
+++ b/chronojump-flask/static/js/js.js
@@ -0,0 +1,3 @@
+function showDiv() {
+ document.getElementById('hiddenDiv').style.display = "block";
+}
diff --git a/chronojump-flask/static/styles/input.css b/chronojump-flask/static/styles/input.css
index db8c178..5adbae5 100644
--- a/chronojump-flask/static/styles/input.css
+++ b/chronojump-flask/static/styles/input.css
@@ -1,10 +1,15 @@
+div.main {
+ max-width: 1000px;
+ /*margin: auto;*/
+ /*border: 3px solid #73AD21;*/
+}
+
.topalignleft {
font-size: 20px;
float: left;
}
.topalignright {
font-size: 20px;
- width: 1000px;
float: right;
}
@@ -12,7 +17,6 @@
float: left;
}
.alignright {
- width: 1000px;
float: right;
}
diff --git a/chronojump-flask/static/styles/tables.css b/chronojump-flask/static/styles/tables.css
index f299042..5fceb2f 100644
--- a/chronojump-flask/static/styles/tables.css
+++ b/chronojump-flask/static/styles/tables.css
@@ -2,7 +2,7 @@
styling for the tables
- ------------------ */
+ ------------------ */
body
diff --git a/chronojump-flask/templates/player_add.html b/chronojump-flask/templates/player_add.html
index 1865edb..c4ab383 100644
--- a/chronojump-flask/templates/player_add.html
+++ b/chronojump-flask/templates/player_add.html
@@ -4,31 +4,41 @@
<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') }}">
+ <script src="{{ url_for('static',filename='js/js.js') }}"></script>
</head>
<body>
+ <div class="main">
{{ 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>
+ <form action = "{{ url_for('player_add_submit') }}" method = "POST">
+ <table border="0" cellspacing=12>
+ <tr>
+ <td>
+ Nom complet
+ <br><input type = "text" name = "name" value="{{name}}"/></br>
+ </td>
+ <td>
- <br>
- <input type = "submit" value = "Afegeix" /><br>
+ Pes (Kg)
+ <br><input type="number" name="weight" step="0.1" min=50
value="{{weight}}"></br>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <input type = "submit" value = "Llegeix RFID" onclick="showDiv()"
/><br>
+ </td>
+ <td>
+ <div id="hiddenDiv" style="display:none; color:red;"
class="answer_list" >Apropi la pulsera al lector...</div>
+ </td>
+ </tr>
+ </table>
</form>
+ </div>
</body>
</html>
diff --git a/chronojump-flask/templates/player_add_result.html
b/chronojump-flask/templates/player_add_result.html
index 2cf83cf..f7a8605 100644
--- a/chronojump-flask/templates/player_add_result.html
+++ b/chronojump-flask/templates/player_add_result.html
@@ -7,11 +7,18 @@
</head>
<body>
+ <div class="main">
{{ header|safe }}
- <br><br>Resultat : {{ msg }}
+ {% if rfid %}
+ <br><br>RFID: {{rfid}}
+ {% endif %}
+
+ <br><br>{{ msg }}
+
{% if not added %}
- <a
href="player_add?name={{name}}&weight={{weight}}&rfid0={{rfid0}}&rfid1={{rfid1}}&rfid2={{rfid2}}&rfid3={{rfid3}}">Tornar</a>
+ <br></br><br></br><a href="player_add?name={{name}}&weight={{weight}}&rfid={{rfid}}">Tornar</a>
{% endif %}
+ </div>
</body>
</html>
diff --git a/chronojump-flask/templates/player_list.html b/chronojump-flask/templates/player_list.html
index 4b49dc9..a38aa43 100644
--- a/chronojump-flask/templates/player_list.html
+++ b/chronojump-flask/templates/player_list.html
@@ -6,24 +6,9 @@
<link rel= "stylesheet" type= "text/css" href= "{{
url_for('static',filename='styles/input.css') }}">
</head>
<body>
+ <div class="main">
{{ header|safe }}
- <!--
- <form action=sets>
- <input type="radio" id="pIdAll" name="pId" value="All">
- <label for="pIdAll">Tots</label>
-
- {% for row in rows %}
-
- <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>
@@ -41,5 +26,6 @@
</tr>
{% endfor %}
</table>
+ </div>
</body>
</html>
diff --git a/chronojump-flask/templates/sets.html b/chronojump-flask/templates/sets.html
index b2101e1..425f8ba 100644
--- a/chronojump-flask/templates/sets.html
+++ b/chronojump-flask/templates/sets.html
@@ -24,85 +24,86 @@
{% endif %}
+ <div class="main">
{{ header|safe }}
<form action=sets>
-<div id="textbox"><p class="alignleft">
+ <div id="textbox"><p class="alignleft">
- Jugador:
+ 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 %}
+ <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 %}
+ {% 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>
-
- 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>
-
-
- 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>
+ {% endfor %}
+ </select>
+ </span>
+
+ 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>
+
+
+ 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="Actualitza"></p></div>
+ <div style="clear: both;"></div>
</form>
<!-- https://www.smashingmagazine.com/2008/08/top-10-css-table-designs/#7-newspaper -->
@@ -110,7 +111,7 @@
<thead>
<th>Data</th>
{% if pId == "All" %}
- <th>Jugador</th>
+ <th>Jugador</th>
{% endif %}
<th>Màquina</th>
<th>Exercici</th>
@@ -122,7 +123,7 @@
<tr>
<td>{{set[0]}}</td>
{% if pId == "All" %}
- <td>{{set[1]}}</td>
+ <td>{{set[1]}}</td>
{% endif %}
<td>{{set[2]}}</td>
<td>{{set[3]}}</td>
@@ -131,6 +132,7 @@
</tr>
{% endfor %}
</table>
+ </div>
</body>
</html>
diff --git a/main.py b/main.py
index abfd1e5..8b1a03b 100755
--- a/main.py
+++ b/main.py
@@ -102,17 +102,20 @@ def uploadEncoderData():
"""chronojump client sends encoder data"""
content = request.get_json()
- person_id = content.get('person_id', 1)
- person_name = content.get('person_name', "unknown")
- machine_id = content.get('machine_id', 1)
- machine_name = content.get('machine_name', "unknown")
- mean_power = content.get('mean_power', 0)
+ personId = content.get('personId', 1)
+ machineId = content.get('machineId', 1)
+ exerciseName = content.get('exerciseName', "unknown")
+ meanPowerBestRep = content.get('meanPowerBestRep', 0)
+ repsAbove50pBest = content.get('repsAbove50pBest', 0)
+
+ meanPowerBestRep = str(meanPowerBestRep).replace(',', '.')
ip = request.remote_addr
(con, cur) = connect_db()
- cur.execute("INSERT INTO encoderData (personId, personName, machineId, machineName, meanPower) VALUES
(%s, %s, %s, %s, %s)", (person_id, person_name, machine_id, machine_name, mean_power))
+ print("INSERT INTO encoderData (personId, machineId, exerciseName, meanPowerBestRep, repsAbove50pBest)
VALUES (%s, %s, %s, %s, %s)", (personId, machineId, exerciseName, meanPowerBestRep, repsAbove50pBest))
+ cur.execute("INSERT INTO encoderData (personId, machineId, exerciseName, meanPowerBestRep,
repsAbove50pBest) VALUES (%s, %s, %s, %s, %s)", (personId, machineId, exerciseName, meanPowerBestRep,
repsAbove50pBest))
con.commit()
return Response("", 202)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]