[chronojump-server] Added new fields (columns) to models Station, Exercise and Task Fixed wrong tablename tasks to task,
- From: Marcos Venteo Garcia <mventeo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Added new fields (columns) to models Station, Exercise and Task Fixed wrong tablename tasks to task,
- Date: Thu, 22 Jun 2017 18:46:21 +0000 (UTC)
commit a50f5d3708422c7b32e04720dfbece8833283ea5
Author: Marcos Venteo García <mventeo gmail com>
Date: Thu Jun 22 20:45:16 2017 +0200
Added new fields (columns) to models Station, Exercise and Task
Fixed wrong tablename tasks to task, and field description for comment
FIX: Now players cannot be added without RFID
Removing unused python requeriments
Table and Model Result now is called ResultEncoder and table is called resultEncoder
chronojumpserver/__init__.py | 2 -
chronojumpserver/api.py | 10 +++-
chronojumpserver/forms.py | 2 +-
chronojumpserver/js/players.js | 6 +-
chronojumpserver/models.py | 60 ++++++++++++++++---------
chronojumpserver/templates/_formhelpers.html | 20 +++++++-
chronojumpserver/templates/player_detail.html | 14 +-----
chronojumpserver/templates/player_list.html | 35 +++++++-------
chronojumpserver/tests/test_person.py | 1 +
chronojumpserver/views.py | 1 +
requirements.txt | 2 -
11 files changed, 91 insertions(+), 62 deletions(-)
---
diff --git a/chronojumpserver/__init__.py b/chronojumpserver/__init__.py
index a7fb7c0..1f6ae6c 100755
--- a/chronojumpserver/__init__.py
+++ b/chronojumpserver/__init__.py
@@ -24,8 +24,6 @@ app.secret_key = config.get("security", "secret_key")
app.config['SECRET_KEY'] = app.secret_key
app.config['UPLOAD_FOLDER'] = "static/images/photos"
-#Initialize SocketIO
-
@app.route('/js/<path:filename>')
def js(filename):
diff --git a/chronojumpserver/api.py b/chronojumpserver/api.py
index 18b96d8..3122ce8 100755
--- a/chronojumpserver/api.py
+++ b/chronojumpserver/api.py
@@ -4,7 +4,7 @@
"""
from chronojumpserver import app
-from chronojumpserver.models import Person, Result, Station
+from chronojumpserver.models import Person, ResultEncoder, Station
from flask import jsonify, request
from time import sleep
import os
@@ -76,7 +76,13 @@ def register_rfid():
status_code = 404
msg = "RFID ERROR: No s'ha pogut llegir cap rfid en el temps assignat."
-
+ # Return response
response = jsonify(rfid=rfid, msg=msg)
response.status_code = status_code
return response
+
+
+@app.route('/api/v1/tasks/new')
+def add_new_task():
+ """API to register a new task that could be free or parametrized."""
+ pass
diff --git a/chronojumpserver/forms.py b/chronojumpserver/forms.py
index b5fc170..17be33d 100755
--- a/chronojumpserver/forms.py
+++ b/chronojumpserver/forms.py
@@ -11,4 +11,4 @@ class PersonForm(FlaskForm):
height=FloatField('Alçada'.decode('utf-8'), validators=[DataRequired('El camp açada és
obligatori.'.decode('utf-8'))])
weight=FloatField('Pes', validators=[DataRequired('El camp pes és obligatori.'.decode('utf-8'))])
photo=FileField('Foto del Jugador')
- rfid = StringField('RFID', [validators.Length(max=23)])
+ rfid = StringField('RFID', [DataRequired('S\'ha de registrar un RFID per jugador.'.decode('utf-8')),
validators.Length(max=23)])
diff --git a/chronojumpserver/js/players.js b/chronojumpserver/js/players.js
index 6afe4b6..ef88e19 100755
--- a/chronojumpserver/js/players.js
+++ b/chronojumpserver/js/players.js
@@ -54,6 +54,7 @@ function addModifyDeleteTask(action) {
Load Players and tasks
*/
$(document).ready(function() {
+
var table = $('#players').DataTable({
"columns": [{
type: "num",
@@ -93,11 +94,11 @@ $(document).ready(function() {
title: "Alçada",
render: $.fn.dataTable.render.number('', ',', 2)
},
- {
+ /*{
type: "html",
data: "rfid",
title: "RFID"
- },
+ },*/
{
type: "html",
title: "Tasques",
@@ -193,7 +194,6 @@ $(document).ready(function() {
// Ok, add options in exercise Select
// First remove previous options
$('#exerciseSelect').find('option').remove().end();
- //console.log('JPOUTA');
$.each(data.exercises, function(i, item) {
console.log(item);
$('#exerciseSelect').append($('<option>', {
diff --git a/chronojumpserver/models.py b/chronojumpserver/models.py
index 9221510..ee46e5d 100755
--- a/chronojumpserver/models.py
+++ b/chronojumpserver/models.py
@@ -19,9 +19,9 @@ class Person(Base):
height = Column(Float, nullable=False)
rfid = Column(String(23), nullable=False, unique=True)
imageName = Column(String(50))
- results = relationship("Result",
- order_by="desc(Result.dt)",
- primaryjoin="Result.personId==Person.id")
+ results = relationship("ResultEncoder",
+ order_by="desc(ResultEncoder.dt)",
+ primaryjoin="ResultEncoder.personId==Person.id")
tasks = relationship("Task",
order_by="desc(Task.ts)",
primaryjoin="Task.personId==Person.id")
@@ -77,10 +77,12 @@ class Station(Base):
__tablename__ = 'station'
id = Column(Integer, primary_key=True)
name = Column(String(30), unique=True)
+ type = Column(String(1), nullable=True) # G - gravitory, I - inertial, S - sprint
+
# Relationships
- results = relationship("Result",
- order_by="desc(Result.dt)",
- primaryjoin="Result.stationId==Station.id")
+ results = relationship("ResultEncoder",
+ order_by="desc(ResultEncoder.dt)",
+ primaryjoin="ResultEncoder.stationId==Station.id")
tasks = relationship("Task",
order_by="desc(Task.ts)",
primaryjoin="Task.stationId==Station.id")
@@ -103,6 +105,7 @@ class Station(Base):
return '<Station %r>' % (self.name,)
+
class Exercise(Base):
"""Exercise model.
@@ -122,15 +125,16 @@ class Exercise(Base):
id = Column(Integer, primary_key=True)
name = Column(String(30))
stationId = Column('stationId', ForeignKey('station.id'), nullable=False)
+ percentBodyMassDisplaced = Column(Float)
# Exercises name are unique by station
uniqueNameByStation = UniqueConstraint('name', 'stationId')
# Relationships
station = relationship(Station, primaryjoin= stationId == Station.id)
- results = relationship("Result",
- order_by="desc(Result.dt)",
- primaryjoin="Result.exerciseId==Exercise.id")
+ results = relationship("ResultEncoder",
+ order_by="desc(ResultEncoder.dt)",
+ primaryjoin="ResultEncoder.exerciseId==Exercise.id")
tasks = relationship("Task",
order_by="desc(Task.ts)",
primaryjoin="Task.exerciseId==Exercise.id")
@@ -163,9 +167,9 @@ class Task(Base):
A task is can be free o parametrized.
"""
- __tablename__ = "tasks"
+ __tablename__ = "task"
id = Column(Integer, primary_key=True)
- taskType = Column(Integer) # 0 - Free, 1 - Parametrized
+ taskType = Column(String(1)) # F - Free, P - Parametrized
ts = Column(Date)
personId = Column('personId', ForeignKey('person.id'))
person = relationship(Person, primaryjoin=personId == Person.id)
@@ -173,16 +177,19 @@ class Task(Base):
station = relationship(Station, primaryjoin=stationId == Station.id)
exerciseId = Column('exerciseId', ForeignKey('exercise.id'))
exercise = relationship(Exercise, primaryjoin=exerciseId == Exercise.id)
- nreps = Column(Integer)
- load = Column(Float)
- laterality = Column(String(2))
- description = Column(String(150))
+ sets = Column(Integer, default=-1)
+ nreps = Column(Integer, default=-1)
+ load = Column(Float, default=-1)
+ speed = Column(Float, default=-1)
+ percentMaxSpeed = Column(Float, default=-1)
+ laterality = Column(String(3))
+ comment = Column(String(150))
done = Column(Boolean)
def __init__(self, taskType=0, ts=None, stationId=None,
personId=None,
- exerciseId=None, nreps=None, load=None, laterality=None,
- description=None, done=False):
+ exerciseId=None, nreps=None, sets=-1, load=None, laterality=None,
+ comment=None, done=False):
"""Initialize a Task object"""
self.taskType = taskType
self.ts = ts
@@ -192,18 +199,19 @@ class Task(Base):
self.exercise = Exercise.query.filter(Exercise.id == exerciseId).first()
self.station = Station.query.filter(Station.id == stationId).first()
self.person = Person.query.filter(Person.id == personId).first()
+ self.sets = sets
self.nreps = nreps
self.load = load
self.laterality = laterality
self.done = done
- if taskType == 1 and self.description is None:
+ if taskType == 'P' and self.comment is None:
# Use Catalan for the moment
- self.description = "%d repeticions del exercisi %s " \
+ self.comment = "%d repeticions del exercisi %s " \
"a l'estació %s amb una velocitat de %.2f " \
"i pèrdua de %.2f%%" % ( self.nreps,
self.exercise.name,
self.station.name,
- self.speed,
+ self.load,
self.loss)
@property
@@ -224,15 +232,23 @@ class Task(Base):
'description': self.description
}
+ def add_free_task(self):
+ """Add a new free task that only has a description."""
+ pass
+
+ def add_param_task(self):
+ """Add a new task with parameters."""
+ pass
+
def __repr__(self):
"""Representation of the task."""
# For the moment show only task
return '<Task %r>' % self.description
-class Result(Base):
+class ResultEncoder(Base):
"""Result model."""
- __tablename__ = 'results'
+ __tablename__ = 'resultEncoder'
id = Column('id', Integer, primary_key=True)
dt = Column('dt', Date)
personId = Column('personId', ForeignKey('person.id'))
diff --git a/chronojumpserver/templates/_formhelpers.html b/chronojumpserver/templates/_formhelpers.html
index 51ecc1b..2793bf0 100755
--- a/chronojumpserver/templates/_formhelpers.html
+++ b/chronojumpserver/templates/_formhelpers.html
@@ -46,6 +46,22 @@
</div>
{% endmacro %}
-{% macro render_field_without_label(field, readonly) %}
-<input class="form-control" type="text" value="{{field.data}}" name="{{field.name}}" id="{{field.name}}"
readonly/>
+{% macro render_rfid_field(field) %}
+<div class="form-group {% if field.errors %}has-error{% endif %}">
+ <label for="rfid">RFID</label>
+ <div class="input-group">
+ <input class="form-control" type="text" value="{{field.data}}" name="{{field.name}}" id="{{field.name}}"
readonly/>
+ <span class="input-group-btn">
+ <button id="registerRFID" class="btn btn-info" type="button" data-loading-text="Registrant..."
autocomplete="off">Registrar RFID</button>
+ </span>
+ </div>
+ {%if field.errors %}
+ {% for error in field.errors %}
+ <span class="help-block">{{ error }}</span>
+ {% endfor %}
+ {% endif %}
+</div>
+
+
+
{% endmacro %}
diff --git a/chronojumpserver/templates/player_detail.html b/chronojumpserver/templates/player_detail.html
index 5e5e398..bcc17ac 100755
--- a/chronojumpserver/templates/player_detail.html
+++ b/chronojumpserver/templates/player_detail.html
@@ -1,4 +1,4 @@
-{% from "_formhelpers.html" import render_field %} {% from "_formhelpers.html" import
render_field_without_label %} {% extends 'layout.html' %} {% block content %} {% if msg %} {% if has_errors %}
+{% from "_formhelpers.html" import render_field %} {% from "_formhelpers.html" import render_rfid_field %}
{% extends 'layout.html' %} {% block content %} {% if msg %} {% if has_errors %}
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
aria-hidden="true">×</span></button> {{msg}}.
</div>
@@ -27,18 +27,10 @@
{{ render_field(form.weight) }}
</div>
</div>
- <div class="form-group">
- <label for="rfid">RFID</label>
- <div class="input-group">
- {{ render_field_without_label(form.rfid, true) }}
- <span class="input-group-btn">
- <button id="registerRFID" class="btn btn-info" type="button"
data-loading-text="Registrant..." autocomplete="off">Registrar RFID</button>
- </span>
- </div>
- </div>
+ {{ render_rfid_field(form.rfid) }}
<button class="btn btn-primary" type="submit">Guardar les dades</button>
- </div>
</div>
+
</form>
{% endblock %}
diff --git a/chronojumpserver/templates/player_list.html b/chronojumpserver/templates/player_list.html
index ca7b2b5..ed7f1ba 100755
--- a/chronojumpserver/templates/player_list.html
+++ b/chronojumpserver/templates/player_list.html
@@ -31,6 +31,23 @@
<li role="presentation" class="active"><a href="#freeTask"
aria-controls="freeTask" role="tab" data-toggle="pill">Lliure</a></li>
<li role="presentation"><a href="#paramTask"
aria-controls="freeTask" role="tab" data-toggle="pill">Parametritzada</a></li>
</ul>
+ <form class="form-inline">
+ <div class="form-group">
+ <label for="recipient-name"
class="control-label">Estació:</label>
+ <select class="form-control" id="stationSelect">
+ <option value="">Selecciona una
estació</option>
+ {% for station in stations %}
+ <option
value={{station.id}}>{{station.name}}</option>
+ {% endfor %}
+ </select>
+ </div>
+ <div class="form-group pull-right">
+ <label for="recipient-name"
class="control-label">Exercici:</label>
+ <select class="form-control" disabled
id="exerciseSelect">
+ <option value=""></option>
+ </select>
+ </div>
+ </form>
<div class="tab-content">
<div role="tabpanel" id="freeTask" class="panel panel-default
tab-pane active">
<div class="panel-heading">Descripció</div>
@@ -41,23 +58,7 @@
<div role="tabpanel" id="paramTask" class="tab-pane panel
panel-default">
<div class="panel-heading">Paràmetres</div>
<div class="panel-body">
- <form class="form-inline">
- <div class="form-group">
- <label for="recipient-name"
class="control-label">Estació:</label>
- <select class="form-control"
id="stationSelect">
- <option value="">Selecciona
una estació</option>
- {% for station in stations %}
- <option
value={{station.id}}>{{station.name}}</option>
- {% endfor %}
- </select>
- </div>
- <div class="form-group pull-right">
- <label for="recipient-name"
class="control-label">Exercici:</label>
- <select class="form-control" disabled
id="exerciseSelect">
- <option value=""></option>
- </select>
- </div>
- </form>
+
<form class="form-inline" style="margin-top: 10px">
<div class="form-group">
<label for="recipient-name"
class="control-label"># Repeticions:</label>
diff --git a/chronojumpserver/tests/test_person.py b/chronojumpserver/tests/test_person.py
index 20d979c..0193f28 100755
--- a/chronojumpserver/tests/test_person.py
+++ b/chronojumpserver/tests/test_person.py
@@ -27,6 +27,7 @@ class TestPerson(unittest.TestCase):
def test_get_byName(self):
"""Get the person by name."""
p = Person.getByName('Player 1')
+
self.assertEqual(p.name, 'Player 1')
def test_player_name_cannot_be_duplicated(self):
diff --git a/chronojumpserver/views.py b/chronojumpserver/views.py
index e322c1e..d3a0ff2 100755
--- a/chronojumpserver/views.py
+++ b/chronojumpserver/views.py
@@ -113,6 +113,7 @@ def add_player():
db_session.add(player)
db_session.commit()
msg = "Ej jugador %s s'ha creat correctament." % form.fullname.data
+ return redirect('/player/%d' % player.id)
else:
# There are some errors in the form
msg = 'Hi han hagut errors, revisa el formulari.'
diff --git a/requirements.txt b/requirements.txt
index d5541f4..69ebcd3 100755
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,8 +3,6 @@ appdirs==1.4.3
click==6.7
Flask==0.12.2
Flask-Autodoc==0.1.1
-Flask-MySQL==1.4.0
-Flask-RESTful==0.3.5
Flask-SQLAlchemy==2.2
gunicorn==0.14.5
itsdangerous==0.24
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]