[chronojump] chronojump-importer: import runs.



commit 23a88af476d623eff711386fa594e6b781a5ea47
Author: Carles Pina i Estany <carles pina cat>
Date:   Wed Nov 2 00:08:13 2016 +0100

    chronojump-importer: import runs.
    
    Previously the Run and RunInterval tables weren't imported (by
    omission).
    
    In order to test that: the *destination*.sqlite files tables have been
    modified so RunIntervalType and RunType name's columns are UNIQUE index
    (otherwise the foreign key check failed).
    
    It also avoids duplicates in case that a user imports the same database
    session multiple times.

 src/chronojump-importer/chronojump_importer.py     |   12 ++++++++----
 .../chronojump_importer_test.py                    |    2 +-
 .../tests/generic-destination-a.sqlite             |  Bin 56320 -> 58368 bytes
 .../tests/generic-destination-b.sqlite             |  Bin 56320 -> 58368 bytes
 .../tests/generic-destination-c.sqlite             |  Bin 56320 -> 58368 bytes
 .../tests/generic-expected-a.sqlite                |  Bin 72704 -> 74752 bytes
 .../tests/generic-expected-b.sqlite                |  Bin 72704 -> 74752 bytes
 .../tests/generic-expected-c.sqlite                |  Bin 72704 -> 74752 bytes
 .../tests/padu-destination.sqlite                  |  Bin 61440 -> 63488 bytes
 src/chronojump-importer/tests/padu-expected.sqlite |  Bin 68608 -> 70656 bytes
 .../tests/user-jump-destination.sqlite             |  Bin 52224 -> 54272 bytes
 .../tests/user-jump-expected.sqlite                |  Bin 52224 -> 54272 bytes
 .../tests/yoyo-destination.sqlite                  |  Bin 1405952 -> 1408000 bytes
 .../tests/yoyo-expected-session-4-to-5.sqlite      |  Bin 1502208 -> 1504256 bytes
 src/chronojump-importer/tests/yoyo-expected.sqlite |  Bin 1408000 -> 1410048 bytes
 15 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index 85e568e..2eb0f52 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -488,8 +488,8 @@ class ImportSession:
     def _import_runs(self):
         # Imports RunTypes table
         run_types = self.source_db.read(table_name="RunType",
-                                        where_condition="Session.uniqueID={}".format(self.source_session),
-                                        join_clause="LEFT JOIN Run ON RunType.name=Run.type LEFT JOIN 
Session ON Run.sessionID=Session.uniqueID",
+                                        where_condition="Run.sessionID={}".format(self.source_session),
+                                        join_clause="LEFT JOIN Run ON RunType.name=Run.type",
                                         group_by_clause="RunType.uniqueID")
 
         self.destination_db.write(table=run_types,
@@ -498,8 +498,8 @@ class ImportSession:
 
         # Imports RunIntervalTypes table
         run_interval_types = self.source_db.read(table_name="RunIntervalType",
-                                                 
where_condition="Session.uniqueID={}".format(self.source_session),
-                                                 join_clause="LEFT JOIN RunInterval ON 
RunIntervalType.name=RunInterval.type LEFT JOIN Session on RunInterval.sessionID=Session.uniqueID",
+                                                 
where_condition="RunInterval.sessionID={}".format(self.source_session),
+                                                 join_clause="LEFT JOIN RunInterval ON 
RunIntervalType.name=RunInterval.type",
                                                  group_by_clause="RunIntervalType.uniqueID")
 
         self.destination_db.write(table=run_interval_types,
@@ -512,6 +512,8 @@ class ImportSession:
         run.update_ids("personID", self.persons77, "uniqueID", "new_uniqueID")
         run.update_session_ids(self.new_session_id)
         run.update_ids("type", run_types, "old_name", "new_name")
+        self.destination_db.write(table=run,
+                                  matches_columns=self.destination_db.column_names("Run", 
skip_columns=["uniqueID", "personID", "sessionID"]))
 
         # Imports RunInterval table (with the new Person77's uniqueIDs)
         run_interval = self.source_db.read(table_name="RunInterval",
@@ -519,6 +521,8 @@ class ImportSession:
         run_interval.update_ids("personID", self.persons77, "uniqueID", "new_uniqueID")
         run_interval.update_session_ids(self.new_session_id)
         run_interval.update_ids("type", run_interval_types, "old_name", "new_name")
+        self.destination_db.write(table=run_interval,
+                                  matches_columns=self.destination_db.column_names("RunInterval", 
skip_columns=["uniqueID", "personID", "sessionID"]))
 
     def _import_pulse(self):
         # Imports PulseTypes table
diff --git a/src/chronojump-importer/chronojump_importer_test.py 
b/src/chronojump-importer/chronojump_importer_test.py
index bbedce7..abef234 100755
--- a/src/chronojump-importer/chronojump_importer_test.py
+++ b/src/chronojump-importer/chronojump_importer_test.py
@@ -57,7 +57,7 @@ class TestImporter(unittest.TestCase):
         {'base_filename': 'yoyo-{}.sqlite', 'source_session': 4, 'destination_session': 5}
     )
     def test_importer_generic(self, data):
-        re_creates_test = True   # During development change it to True
+        re_creates_test = False  # During development change it to True
                                  # to execute the tests and copy the new
                                  # result as expected test
 
diff --git a/src/chronojump-importer/tests/generic-destination-a.sqlite 
b/src/chronojump-importer/tests/generic-destination-a.sqlite
index 2e809c2..88a3be7 100644
Binary files a/src/chronojump-importer/tests/generic-destination-a.sqlite and 
b/src/chronojump-importer/tests/generic-destination-a.sqlite differ
diff --git a/src/chronojump-importer/tests/generic-destination-b.sqlite 
b/src/chronojump-importer/tests/generic-destination-b.sqlite
index b2dca92..40109c9 100644
Binary files a/src/chronojump-importer/tests/generic-destination-b.sqlite and 
b/src/chronojump-importer/tests/generic-destination-b.sqlite differ
diff --git a/src/chronojump-importer/tests/generic-destination-c.sqlite 
b/src/chronojump-importer/tests/generic-destination-c.sqlite
index 19e5c7a..0ae27cf 100644
Binary files a/src/chronojump-importer/tests/generic-destination-c.sqlite and 
b/src/chronojump-importer/tests/generic-destination-c.sqlite differ
diff --git a/src/chronojump-importer/tests/generic-expected-a.sqlite 
b/src/chronojump-importer/tests/generic-expected-a.sqlite
index 9f1378e..2c8b415 100644
Binary files a/src/chronojump-importer/tests/generic-expected-a.sqlite and 
b/src/chronojump-importer/tests/generic-expected-a.sqlite differ
diff --git a/src/chronojump-importer/tests/generic-expected-b.sqlite 
b/src/chronojump-importer/tests/generic-expected-b.sqlite
index 7ba1aca..7038a68 100644
Binary files a/src/chronojump-importer/tests/generic-expected-b.sqlite and 
b/src/chronojump-importer/tests/generic-expected-b.sqlite differ
diff --git a/src/chronojump-importer/tests/generic-expected-c.sqlite 
b/src/chronojump-importer/tests/generic-expected-c.sqlite
index 121fd7f..292baba 100644
Binary files a/src/chronojump-importer/tests/generic-expected-c.sqlite and 
b/src/chronojump-importer/tests/generic-expected-c.sqlite differ
diff --git a/src/chronojump-importer/tests/padu-destination.sqlite 
b/src/chronojump-importer/tests/padu-destination.sqlite
index 8145086..ab3dd2c 100644
Binary files a/src/chronojump-importer/tests/padu-destination.sqlite and 
b/src/chronojump-importer/tests/padu-destination.sqlite differ
diff --git a/src/chronojump-importer/tests/padu-expected.sqlite 
b/src/chronojump-importer/tests/padu-expected.sqlite
index 1828d4b..ab67695 100644
Binary files a/src/chronojump-importer/tests/padu-expected.sqlite and 
b/src/chronojump-importer/tests/padu-expected.sqlite differ
diff --git a/src/chronojump-importer/tests/user-jump-destination.sqlite 
b/src/chronojump-importer/tests/user-jump-destination.sqlite
index b57f4f8..64c428b 100644
Binary files a/src/chronojump-importer/tests/user-jump-destination.sqlite and 
b/src/chronojump-importer/tests/user-jump-destination.sqlite differ
diff --git a/src/chronojump-importer/tests/user-jump-expected.sqlite 
b/src/chronojump-importer/tests/user-jump-expected.sqlite
index edf1e14..5f0b403 100644
Binary files a/src/chronojump-importer/tests/user-jump-expected.sqlite and 
b/src/chronojump-importer/tests/user-jump-expected.sqlite differ
diff --git a/src/chronojump-importer/tests/yoyo-destination.sqlite 
b/src/chronojump-importer/tests/yoyo-destination.sqlite
index 1d59f23..2376935 100644
Binary files a/src/chronojump-importer/tests/yoyo-destination.sqlite and 
b/src/chronojump-importer/tests/yoyo-destination.sqlite differ
diff --git a/src/chronojump-importer/tests/yoyo-expected-session-4-to-5.sqlite 
b/src/chronojump-importer/tests/yoyo-expected-session-4-to-5.sqlite
index adf65ed..984cd40 100644
Binary files a/src/chronojump-importer/tests/yoyo-expected-session-4-to-5.sqlite and 
b/src/chronojump-importer/tests/yoyo-expected-session-4-to-5.sqlite differ
diff --git a/src/chronojump-importer/tests/yoyo-expected.sqlite 
b/src/chronojump-importer/tests/yoyo-expected.sqlite
index 4dd261e..cc00686 100644
Binary files a/src/chronojump-importer/tests/yoyo-expected.sqlite and 
b/src/chronojump-importer/tests/yoyo-expected.sqlite differ


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