[chronojump] chronojump-importer: fixes a bug: updates the exerciseEncoder IDs accordingly with the new needed ID



commit 5933ef7e2284372c0a381b5875427fef1beeeee2
Author: Carles Pina i Estany <carles pina cat>
Date:   Thu Dec 15 13:14:25 2016 +0000

    chronojump-importer: fixes a bug: updates the exerciseEncoder IDs accordingly with the new needed IDs.
    
    Before this commit some exerciseEncoder could be wrong: they had the
    same ID than the source database but the exerciseType could have been
    different.
    
    This is in the new line:
    encoder_1rm.update_ids("exerciseID", encoder_exercise, "uniqueID", "new_uniqueID")
    that updates the exerciseID in the encoder_1rm table based on the
    encoder_exercise table and its uniqueID and new_uniqueID.
    
    Note that for the encoder table it was very wrong in a strange way:
    -encoder.update_ids("exerciseID", encoder_1rm, "old_exerciseID", "new_exerciseID")
    +encoder.update_ids("exerciseID", encoder_exercise, "uniqueID", "new_uniqueID")
    
    And there were another mistake: exercises related to encoder1RM weren't
    imported. Now it reads and treats like the other exercises.

 src/chronojump-importer/chronojump_importer.py |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index 3c7355f..39f500f 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -555,10 +555,22 @@ class ImportSession:
 
     def _import_encoder(self):
         # Imports EncoderExercise
-        encoder_exercise = self.source_db.read(table_name="EncoderExercise",
+        encoder_exercise_from_encoder = self.source_db.read(table_name="EncoderExercise",
                                                
where_condition="Encoder.sessionID={}".format(self.source_session),
                                                join_clause="LEFT JOIN Encoder ON 
Encoder.exerciseID=EncoderExercise.uniqueID",
                                                group_by_clause="EncoderExercise.uniqueID")
+
+        encoder_exercise_from_encoder_1rm = self.source_db.read(table_name="EncoderExercise",
+                                                            where_condition="Encoder1RM.sessionID={}".format(
+                                                            self.source_session),
+                                                            join_clause="LEFT JOIN Encoder1RM ON 
Encoder1RM.exerciseID=EncoderExercise.uniqueID",
+                                                            group_by_clause="EncoderExercise.uniqueID")
+
+        encoder_exercise = Table("encoderExercise")
+        encoder_exercise.concatenate_table(encoder_exercise_from_encoder)
+        encoder_exercise.concatenate_table(encoder_exercise_from_encoder_1rm)
+        encoder_exercise.remove_duplicates()
+
         self.destination_db.write(table=encoder_exercise,
                                   matches_columns=self.destination_db.column_names("EncoderExercise", 
["uniqueID"]))
 
@@ -567,6 +579,7 @@ class ImportSession:
                                           
where_condition="Encoder1RM.sessionID={}".format(self.source_session))
         encoder_1rm.update_session_ids(self.new_session_id)
         encoder_1rm.update_ids("personID", self.persons77, "uniqueID", "new_uniqueID")
+        encoder_1rm.update_ids("exerciseID", encoder_exercise, "uniqueID", "new_uniqueID")
         self.destination_db.write(table=encoder_1rm,
                                   matches_columns=None)
 
@@ -574,7 +587,7 @@ class ImportSession:
         encoder = self.source_db.read(table_name="Encoder",
                                       where_condition="Encoder.sessionID={}".format(self.source_session))
         encoder.update_ids("personID", self.persons77, "uniqueID", "new_uniqueID")
-        encoder.update_ids("exerciseID", encoder_1rm, "old_exerciseID", "new_exerciseID")
+        encoder.update_ids("exerciseID", encoder_exercise, "uniqueID", "new_uniqueID")
         encoder.update_session_ids(self.new_session_id)
 
         self._import_encoder_files(encoder)


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