[chronojump/chronojump-importer] Simplifies queries with the GROUP BY.
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/chronojump-importer] Simplifies queries with the GROUP BY.
- Date: Mon, 5 Sep 2016 16:19:48 +0000 (UTC)
commit 920063cd74ac25486f2df44985175cfe4974d95a
Author: Carles Pina i Estany <carles pina cat>
Date: Mon Sep 5 17:19:28 2016 +0100
Simplifies queries with the GROUP BY.
src/chronojump-importer/chronojump_importer.py | 35 +++++++++++++------
.../chronojump_importer_test.py | 5 ++-
.../tests/generic-expected-a.sqlite | Bin 58368 -> 61440 bytes
3 files changed, 28 insertions(+), 12 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index bcc0b2e..1c8a5b7 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -6,6 +6,7 @@ import sqlite3
import sys
import pprint
+
def results_delete_column(column, results):
new_results = []
@@ -441,32 +442,42 @@ def update_session_ids(table, new_session_id):
def import_database(source_path, destination_path, source_session):
""" Imports the session source_session from source_db into destination_db """
+ print("source path:", source_path)
+ print("destination path:", destination_path)
+
source_db = open_database(source_path, read_only=True)
destination_db = open_database(destination_path, read_only=False)
# Imports JumpType table
jump_types = return_data_from_table(database=source_db, table_name="JumpType",
where_condition="Session.uniqueID={}".format(source_session),
- join_clause="LEFT JOIN Jump ON JumpType.name=Jump.type LEFT JOIN
Session ON Jump.sessionID=Session.uniqueID")
+ join_clause="LEFT JOIN Jump ON JumpType.name=Jump.type LEFT JOIN
Session ON Jump.sessionID=Session.uniqueID",
+ group_by_clause="JumpType.uniqueID")
insert_data(database=destination_db, table_name="JumpType", data=jump_types,
- matches_columns=["name", "startIn", "weight", "description"])
+ matches_columns=get_column_names(destination_db, "JumpType", ["uniqueID"]))
+ cursor = destination_db.cursor()
+ cursor.execute("select * from jumptype")
+ pprint.pprint(cursor.fetchall())
+ #cursor.execute('INSERT INTO Jump
(weight,angle,tc,type,tv,fall,description,sessionID,personID,simulated) VALUES
("0","-1.0","0.0","Free","0.729703","0.0","","1","1","-1")')
+
+ #destination_db.commit()
# Imports JumpRjType table
jump_rj_types = return_data_from_table(database=source_db, table_name="JumpRjType",
where_condition="Session.uniqueID={}".format(source_session),
- join_clause="LEFT JOIN JumpRj ON JumpRjType.name=JumpRj.type LEFT
JOIN Session on JumpRj.sessionID=Session.uniqueID")
+ join_clause="LEFT JOIN JumpRj ON JumpRjType.name=JumpRj.type LEFT
JOIN Session on JumpRj.sessionID=Session.uniqueID",
+ group_by_clause="JumpRjType.uniqueID")
insert_data(database=destination_db, table_name="JumpRjType", data=jump_rj_types,
- matches_columns=["name", "startIn", "weight", "jumpsLimited", "fixedValue", "description"])
-
+ matches_columns=get_column_names(destination_db, "JumpRjType", ["uniqueID"]))
# Imports the session
session = return_data_from_table(database=source_db, table_name="Session",
where_condition="Session.uniqueID={}".format(source_session))
session = insert_data(database=destination_db, table_name="Session", data=session,
- matches_columns=["name", "place", "date", "personsSportID",
"personsSpeciallityID", "personsPractice", "comments"])
+ matches_columns=get_column_names(destination_db, "Session", ["uniqueID"]))
new_session_id = session[0]['new_unique_id']
@@ -477,19 +488,19 @@ def import_database(source_path, destination_path, source_session):
group_by_clause="Person77.uniqueID")
persons77_jump_rj = insert_data(database=destination_db, table_name="Person77", data=persons77_jump_rj,
- matches_columns=["name"])
+ matches_columns=["name"])
# Imports Person77 used by Jump table
persons77_jump = return_data_from_table(database=source_db, table_name="Person77",
where_condition="Jump.sessionID={}".format(source_session),
- join_clause="LEFT JOIN Jump ON Person77.uniqueID=Jump.personID")
+ join_clause="LEFT JOIN Jump ON Person77.uniqueID=Jump.personID",
+ group_by_clause="Person77.uniqueID")
persons77_jump = insert_data(database=destination_db, table_name="Person77", data=persons77_jump,
- matches_columns=["name"])
+ matches_columns=["name"])
persons77 = persons77_jump_rj + persons77_jump
-
# Imports JumpRj table (with the new Person77's uniqueIDs)
jump_rj = return_data_from_table(database=source_db, table_name="JumpRj",
where_condition="JumpRj.sessionID={}".format(source_session))
@@ -545,10 +556,12 @@ def open_database(filename, read_only):
return conn
+
def execute_and_log(cursor, sql, comment = ""):
- print("Will execute:", sql, comment)
+ print("SQL:", sql, comment)
cursor.execute(sql)
+
def process_command_line():
parser = argparse.ArgumentParser(description="Process some integers.")
parser.add_argument("--source", type=str, required=True,
diff --git a/src/chronojump-importer/chronojump_importer_test.py
b/src/chronojump-importer/chronojump_importer_test.py
index d538a34..d7af7dd 100755
--- a/src/chronojump-importer/chronojump_importer_test.py
+++ b/src/chronojump-importer/chronojump_importer_test.py
@@ -19,18 +19,21 @@ class TestImporter(unittest.TestCase):
def test_importerGeneric(self):
# lists the names. They will expand to generic-destination-X.sqlite / generic-source-X.sqlite /
generic-expected-X.sqlite
- generic_tests = ["a"]
+ generic_tests = ["a", "b"]
for generic_test in generic_tests:
source_file_name = "generic-source-{}.sqlite".format(generic_test)
destination_file_name = "generic-destination-{}.sqlite".format(generic_test)
expected_file_name = "generic-expected-{}.sqlite".format(generic_test)
+ original_destination_file_path = "generic-original-destination-{}.sqlite".format(generic_test)
source_file_path = "{}/{}".format(self.temporary_directory_path, source_file_name)
destination_file_path = "{}/{}".format(self.temporary_directory_path, destination_file_name)
+ original_destination_file_path = "{}/{}".format(self.temporary_directory_path,
original_destination_file_path)
shutil.copy("tests/{}".format(source_file_name), source_file_path)
shutil.copy("tests/{}".format(destination_file_name), destination_file_path)
+ shutil.copy("tests/{}".format(destination_file_name), original_destination_file_path)
# command = "python3 ./chronojump_importer.py --source {} --destination {} --source_session
1".format(source_file_path, destination_file_path)
# print("Command:", command)
diff --git a/src/chronojump-importer/tests/generic-expected-a.sqlite
b/src/chronojump-importer/tests/generic-expected-a.sqlite
index e169c3e..8d52927 100644
Binary files a/src/chronojump-importer/tests/generic-expected-a.sqlite and
b/src/chronojump-importer/tests/generic-expected-a.sqlite differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]