[chronojump-server] Improved chronojump-flask
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Improved chronojump-flask
- Date: Wed, 10 May 2017 18:08:22 +0000 (UTC)
commit 1d30fdee81df2746efd574080ae77a71b74787da
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed May 10 20:07:53 2017 +0200
Improved chronojump-flask
chronojump-flask/chronojump_server.py | 57 ++++++----
chronojump-flask/templates/index.html | 2 +-
chronojump-flask/templates/player_add.html | 7 +-
chronojump-flask/templates/player_add_result.html | 2 +-
chronojump-flask/templates/player_list.html | 2 +
.../templates/{sets.html => results.html} | 122 +++++++++++---------
tables.txt | 28 ++++-
7 files changed, 135 insertions(+), 85 deletions(-)
---
diff --git a/chronojump-flask/chronojump_server.py b/chronojump-flask/chronojump_server.py
index 1864e56..7da453f 100644
--- a/chronojump-flask/chronojump_server.py
+++ b/chronojump-flask/chronojump_server.py
@@ -24,12 +24,12 @@ def main():
#call:
-#http://192.168.200.1:5000/sets
-@app.route("/sets")
+#http://192.168.200.1:5000/results
+@app.route("/results")
def Sets():
date = request.args.get('date') #days
personId = request.args.get('pId')
- machineId = request.args.get('mId')
+ stationId = request.args.get('sId')
cursor = mysql.connect().cursor()
if date is None or date == "" or date == "Any":
@@ -37,26 +37,32 @@ def Sets():
else:
dateStr = " AND FLOOR(TO_DAYS(NOW()) - TO_DAYS(dt)) <= " + date
- if machineId is None or machineId == "" or machineId == "All":
- machineStr = ""
+ if stationId is None or stationId == "" or stationId == "All":
+ stationStr = ""
else:
- machineStr = " AND machineId = " + machineId;
+ stationStr = " AND stationId = " + stationId;
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 +
- " ORDER by id DESC");
- sets = cursor.fetchall()
+ personStr = " AND person.id = " + personId;
+
+ cursor.execute("SELECT results.dt, person.name, station.name, results.resistance, results.exerciseName,
results.meanPowerBestRep, results.repsAbove50pBest, results.comments" +
+ " FROM results, person, station " +
+ " WHERE results.personId = person.id " +
+ " AND results.stationId = station.id " +
+ personStr + dateStr + stationStr +
+ " ORDER by results.id DESC");
+ results = cursor.fetchall()
- cursor.execute("SELECT encoderData.personId, person.name FROM encoderData, " +
- "person WHERE encoderData.personId = person.uniqueID GROUP BY person.uniqueId");
+ cursor.execute("SELECT results.personId, person.name FROM results, " +
+ "person WHERE results.personId = person.id GROUP BY person.id");
persons = cursor.fetchall()
- return render_template('sets.html', header=getHeader("Sèries d'encoder"), date=date,
pId=personId, mId=machineId, sets=sets, persons=persons)
+ cursor.execute("SELECT * FROM station");
+ stations = cursor.fetchall()
+
+ return render_template('results.html', header=getHeader("Resultats"), date=date, pId=personId,
sId=stationId, results=results, persons=persons, stations=stations)
@app.route('/player_list')
def list():
@@ -70,10 +76,11 @@ def list():
def player_add():
name = request.args.get('name')
weight = request.args.get('weight')
+ height = request.args.get('height')
rfid = request.args.get('rfid')
return render_template('player_add.html', header = getHeader("Afegir jugador"),
- name=name, weight=weight, rfid=rfid)
+ name=name, weight=weight, height=height, rfid=rfid)
@app.route('/player_add_submit',methods = ['POST', 'GET'])
def player_add_submit():
@@ -82,14 +89,18 @@ def player_add_submit():
name = request.form['name']
weight = request.form['weight']
+ height = request.form['height']
#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] "
+ if height is None or height == "" or height == 0:
+ msg += " [Falta al¸ada] "
+ if msg != "":
return render_template("player_add_result.html", header = getHeader("Afegir jugador"),
- added=False, msg = msg, name=name, weight=weight, rfid="")
+ added=False, msg = msg, name=name, weight=weight, height=height, rfid="")
db = mysql.connect()
cursor = db.cursor()
@@ -100,7 +111,7 @@ def player_add_submit():
if rows:
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="")
+ added=False, msg = msg, name=name, weight=weight, height=height, rfid="")
#3 read RFID
@@ -119,7 +130,7 @@ def player_add_submit():
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)
+ added=False, msg = "No s'ha detectat el RFID", name=name, weight=weight, height=height,
rfid=rfid)
#4 check if RFID exists
@@ -128,17 +139,17 @@ def player_add_submit():
if rows:
msg = "Error, ja existeix el rfid: " + rfid
return render_template("player_add_result.html", header = getHeader("Afegir jugador"),
- added=False, msg = msg, name=name, weight=weight, rfid=rfid)
+ added=False, msg = msg, name=name, weight=weight, height=height, rfid=rfid)
#5 insert person and show success
- cursor.execute("INSERT INTO person (name,weight,rfid) VALUES (" +
- "'" + name + "', " + str(weight) + ", '" + rfid + "')")
+ cursor.execute("INSERT INTO person (name, weight, height, rfid) VALUES (" +
+ "'" + name + "', " + str(weight) + ", " + str(height) + ", '" + rfid + "')")
db.commit()
msg = "Afegit " + name
return render_template("player_add_result.html", header = getHeader("Afegir jugador"),
- added=True, msg = msg, name=name, weight=weight, rfid=rfid)
+ added=True, msg = msg, name=name, weight=weight, height=height, rfid=rfid)
if __name__ == "__main__":
diff --git a/chronojump-flask/templates/index.html b/chronojump-flask/templates/index.html
index 0be39e3..a4c54ee 100644
--- a/chronojump-flask/templates/index.html
+++ b/chronojump-flask/templates/index.html
@@ -11,7 +11,7 @@
<br></br>
<section class="border">
- <a href="sets"><button>Veure sèries d'encoder</button></a>
+ <a href="results"><button>Resultats</button></a>
<a href="player_list"><button>Llistat jugadors</button></a>
<a href="player_add"><button>Afegir jugador</button></a>
<a href="rfid_lost"><button>RFID perduda</button></a>
diff --git a/chronojump-flask/templates/player_add.html b/chronojump-flask/templates/player_add.html
index c4ab383..ab37151 100644
--- a/chronojump-flask/templates/player_add.html
+++ b/chronojump-flask/templates/player_add.html
@@ -25,7 +25,12 @@
<td>
Pes (Kg)
- <br><input type="number" name="weight" step="0.1" min=50
value="{{weight}}"></br>
+ <br><input type="number" name="weight" step="0.1" min=50 max=250
value="{{weight}}"></br>
+ </td>
+ <td>
+
+ Alçada (cm)
+ <br><input type="number" name="height" step="0.1" min=100 max=250
value="{{height}}"></br>
</td>
</tr>
<tr>
diff --git a/chronojump-flask/templates/player_add_result.html
b/chronojump-flask/templates/player_add_result.html
index f7a8605..28185cb 100644
--- a/chronojump-flask/templates/player_add_result.html
+++ b/chronojump-flask/templates/player_add_result.html
@@ -16,7 +16,7 @@
<br><br>{{ msg }}
{% if not added %}
- <br></br><br></br><a href="player_add?name={{name}}&weight={{weight}}&rfid={{rfid}}">Tornar</a>
+ <br></br><br></br><a
href="player_add?name={{name}}&weight={{weight}}&height={{height}}&rfid={{rfid}}">Tornar</a>
{% endif %}
</div>
</body>
diff --git a/chronojump-flask/templates/player_list.html b/chronojump-flask/templates/player_list.html
index a38aa43..e83edf1 100644
--- a/chronojump-flask/templates/player_list.html
+++ b/chronojump-flask/templates/player_list.html
@@ -14,6 +14,7 @@
<th>id</th>
<th>Nom</th>
<th>Pes</th>
+ <th>Alçada</th>
<th>RFID</th>
</thead>
@@ -23,6 +24,7 @@
<td>{{row[1]}}</td>
<td>{{row[2]}}</td>
<td>{{row[3]}}</td>
+ <td>{{row[4]}}</td>
</tr>
{% endfor %}
</table>
diff --git a/chronojump-flask/templates/sets.html b/chronojump-flask/templates/results.html
similarity index 58%
rename from chronojump-flask/templates/sets.html
rename to chronojump-flask/templates/results.html
index 425f8ba..07130a1 100644
--- a/chronojump-flask/templates/sets.html
+++ b/chronojump-flask/templates/results.html
@@ -1,58 +1,56 @@
<!doctype html>
<html lang="ca">
<head>
- <title>Chronojump encoder - Veure sèries</title>
+ <title>Chronojump 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>
{% if (not date or date == "") %}
- {% set date = "Any" %}
+ {% set date = "1" %}
{% endif %}
{% if (not pId or pId == "") %}
{% set pId = "All" %}
{% endif %}
- {% if (not mId or mId == "") %}
- {% set mId = "All" %}
+ {% if (not sId or sId == "") %}
+ {% set sId = "All" %}
{% endif %}
{% if (not persons or persons == "") %}
{% set persons = "" %}
{% endif %}
+ {% if (not stations or stations == "") %}
+ {% set stations = "" %}
+ {% endif %}
+
<div class="main">
{{ header|safe }}
- <form action=sets>
+ <form action=results>
<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 %}
+ Data:
- {% 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>
+ <span class="noselect"> <!-- make values not selectable (highlight by cursor)
-->
+ {% if date == "1" %}
+ <input type="radio" id="date1" name="date" value="1"
checked="checked">
+ {% else %}
+ <input type="radio" id="date1" name="date" value="1">
+ {% endif %}
+ <label for="date1">1d</label>
- Data:
+ {% if date == "3" %}
+ <input type="radio" id="date3" name="date" value="3"
checked="checked">
+ {% else %}
+ <input type="radio" id="date3" name="date" value="3">
+ {% endif %}
+ <label for="date3">3d</label>
- <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 %}
@@ -75,30 +73,44 @@
<label for="dateAny">Sempre</label>
</span>
+ <!-- Jugador: -->
+
+ <span class="styled-select slate">
+ <select name="pId">
+ {% if pId == "All" %}
+ <option value="All" selected="selected">Tots els
jugadors</option>
+ {% else %}
+ <option value="All">Tots els jugadors</option>
+ {% endif %}
- Màquina:
+ {% 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>
- <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>
+ <!-- Estació: -->
- {% 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>
+ <span class="styled-select slate">
+ <select name="sId">
+ {% if sId == "All" %}
+ <option value="All" selected="selected">Totes les
estacions</option>
+ {% else %}
+ <option value="All">Totes les estacions</option>
+ {% endif %}
- {% 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>
+ {% for row in stations %}
+ {% if sId|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>
</p>
@@ -113,22 +125,26 @@
{% if pId == "All" %}
<th>Jugador</th>
{% endif %}
- <th>Màquina</th>
+ <th>Estació</th>
+ <th>Càrrega</th>
<th>Exercici</th>
<th>Potencia mitjana</th>
<th>Repeticions bones</th>
+ <th>Comentaris</th>
</thead>
- {% for set in sets %}
+ {% for row in results %}
<tr>
- <td>{{set[0]}}</td>
+ <td>{{row[0]}}</td>
{% if pId == "All" %}
- <td>{{set[1]}}</td>
+ <td>{{row[1]}}</td>
{% endif %}
- <td>{{set[2]}}</td>
- <td>{{set[3]}}</td>
- <td>{{set[4]}}</td>
- <td>{{set[5]}}</td>
+ <td>{{row[2]}}</td>
+ <td>{{row[3]}}</td>
+ <td>{{row[4]}}</td>
+ <td>{{ row[5] if row[5] != None }}</td>
+ <td>{{ row[6] if row[6] != None }}</td>
+ <td>{{row[7]}}</td>
</tr>
{% endfor %}
</table>
diff --git a/tables.txt b/tables.txt
index 1d0eb66..21c8d2a 100644
--- a/tables.txt
+++ b/tables.txt
@@ -1,14 +1,30 @@
-#this table is created just to test json
+# 1.- creation of database and tables
+
+create database chronojump;
+use chronojump;
-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);
+#this table is created just to test json
-CREATE TABLE machine(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name CHAR(30));
+CREATE TABLE results(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, dt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
personId INT, stationId INT, resistance FLOAT, exerciseName CHAR(30), meanPowerBestRep FLOAT,
repsAbove50pBest INT, comments CHAR(20));
+CREATE TABLE station(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));
#rfid can be six numbers long (of three digits each), separated by commas
-CREATE TABLE person(uniqueID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name CHAR(30), weight FLOAT, rfid
CHAR(23));
+CREATE TABLE person(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name CHAR(30), weight FLOAT, height FLOAT,
rfid CHAR(23));
+
+# 2.- insert sample data:
-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);
+insert into station VALUES(1, "Sprint");
+insert into station VALUES(2, "Multipower 1");
+insert into station VALUES(3, "Multipower 2");
+insert into station VALUES(4, "Press banca");
+insert into station VALUES(5, "Inercial 1");
+insert into station VALUES(6, "Inercial 2");
+insert into station VALUES(7, "Inercial 3");
+insert into station VALUES(8, "Dominades");
+insert into station VALUES(9, "Leg press");
+insert into person VALUES(NULL, "joan", 80, 175.7, "212,212,212,212");
+insert into results VALUES(NULL, NULL, 1, 2, 45.2, "press de banca", 480, 6, "");
+insert into results VALUES(NULL, NULL, 1, 1, 2, "sprint", NULL, NULL, "5 segons");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]