[chronojump-server] Script to fix resultEncoder resistance values
- From: Marcos Venteo Garcia <mventeo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Script to fix resultEncoder resistance values
- Date: Thu, 26 Oct 2017 14:20:35 +0000 (UTC)
commit 092a1152c6731f85985db4bd1b484f165a15ce65
Author: Marcos Venteo <mventeo gmail com>
Date: Thu Oct 26 16:20:05 2017 +0200
Script to fix resultEncoder resistance values
chronojumpserver/scripts/fixResultEncoder.py | 37 ++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/chronojumpserver/scripts/__init__.py b/chronojumpserver/scripts/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/chronojumpserver/scripts/fixResultEncoder.py b/chronojumpserver/scripts/fixResultEncoder.py
new file mode 100644
index 0000000..f2d926b
--- /dev/null
+++ b/chronojumpserver/scripts/fixResultEncoder.py
@@ -0,0 +1,37 @@
+"""
+ fixResultEncoder.py
+
+ Python script to fix resultEncoder.resistance values based on Exercise table
+
+ If resultEncoder.exercise.percentBodyMassDisplaced = 100 then
+ resultEncoder.resistance = resultEncoder.resistance - resultEncoder.person.weight
+"""
+from chronojumpserver.database import db_session
+from chronojumpserver.models import ResultEncoder
+
+
+if __name__ == "__main__":
+ # Get all results from database
+ results = ResultEncoder.query.all()
+ total_modified = 0
+ for result in results:
+ if result.exercise.percentBodyMassDisplaced == 100:
+ # Modify resistance value for this result
+ player_weigth = result.person.weight;
+ previous_resistance_value = result.resistance;
+ new_resistance_value = previous_resistance_value - player_weigth
+ db_session.query(ResultEncoder).filter_by(id=result.id).update({
+ 'resistance' : new_resistance_value
+ })
+ print "Result Id: %d, Player weight is %.2f. Changing resistance value %.2f to %.2f" %
(result.id, player_weigth,
+ previous_resistance_value,
+ new_resistance_value)
+ total_modified +=1
+
+ # Commit all the changes
+ if total_modified > 0 :
+ print "Updating %d records" % total_modified
+ db_session.commit()
+ else:
+ # Nothing to update
+ print "Nothing to update"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]