[chronojump/chronojump-importer] Deletes not-needed code (thanks to the new approach).



commit 48c538cb31ae0f0dc32aa84a28fb49b851cc3073
Author: Carles Pina i Estany <carles pina cat>
Date:   Mon Sep 5 18:18:04 2016 +0100

    Deletes not-needed code (thanks to the new approach).

 src/chronojump-importer/chronojump_importer.py |  278 +-----------------------
 1 files changed, 4 insertions(+), 274 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index 62fd96a..003b396 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -3,22 +3,14 @@
 import copy
 import argparse
 import sqlite3
+import logging
+
 import sys
 import pprint
-import logging
 
 logging.basicConfig(level=logging.INFO)
 
 
-def results_delete_column(column, results):
-    new_results = []
-
-    for row in results:
-        new_results.append(list(row[column+1:]))
-
-    return new_results
-
-
 def get_column_names(cursor, table, skip_columns = []):
     cursor.execute("PRAGMA table_info({})".format(table))
     result = cursor.fetchall()
@@ -122,78 +114,6 @@ def return_data_from_table(cursor, table_name, where_condition, join_clause ="",
 
     return data
 
-def find_jump_types(sessionID, source_db, table):
-    """ Returns jumpTypes rows (without the uniqueID) used by sessionID"""
-    source_cursor = source_db.cursor()
-
-    column_names = get_column_names(source_db, table)
-
-    i = 0
-    while i < len(column_names):
-        column_names[i] = table+"." + column_names[i]
-        i += 1
-
-    if table == "JumpType":
-        secondary_table = "Jump"
-    elif table == "JumpRjType":
-        secondary_table = "JumpRj"
-    else:
-        assert False
-
-    result = source_cursor.execute(("SELECT {} FROM " + table + " LEFT JOIN " + secondary_table + " ON 
"+table+".name="+secondary_table+".type LEFT JOIN Session ON "+secondary_table+".sessionID=Session.uniqueID 
WHERE Session.uniqueID={}").format(",".join(column_names), sessionID))
-
-    results = result.fetchall()
-    jump_types = results_delete_column(0, results)
-
-    return jump_types
-
-
-def ids_from_data(db, table, rows):
-    """ Returns a list of ids in table. Inserts it if necessary. """
-    ids = []
-
-    cursor = db.cursor()
-
-    column_names = get_column_names(db, table)
-    column_names = column_names[1:]
-
-    for row in rows:
-        where = ""
-        for idx, column_name in enumerate(column_names):
-            if where != "":
-                where += " AND "
-
-            where += column_name + "=\"" + str(row[idx]) + "\""
-
-        sql = "select uniqueID from " + table + " where " + where
-        print("Will check:", sql)
-
-        execute_and_log(cursor, sql)
-        result = cursor.fetchall()
-
-        if len(result) == 0:
-            values = "("
-            for col in row:
-                if values != "(":
-                    values += ","
-                values += '"' + str(col) + '"'
-
-            values += ")"
-
-            sql = "insert into " + table + " (" + ",".join(column_names) + ") VALUES " + values
-            execute_and_log(cursor, sql)
-            newid = cursor.lastrowid
-
-        else:
-            print("Not inserting because it already existed")
-            newid = result[0][0]
-
-        if newid not in ids:
-            ids.append(newid)
-
-    db.commit()
-    return ids
-
 
 def create_select(table_name, column_names, where):
     sql = "SELECT " + ",".join(column_names) + " FROM " + table_name + " WHERE " + where
@@ -233,182 +153,6 @@ def create_insert(table_name, column_names, row):
     return sql
 
 
-def import_table_with_where(source_db, destination_db, table_name, autoincrement_column_name, where):
-    column_names = get_column_names(source_db, table_name)
-
-    column_names.remove(autoincrement_column_name)
-
-    sql_select = create_select(table_name, column_names, where)
-
-    source_cursor = source_db.cursor()
-    destination_cursor = destination_db.cursor()
-
-    source_cursor.execute(sql_select)
-
-    result = source_cursor.fetchall()
-
-    new_ids = []
-
-    for row in result:
-        sql_insert = create_insert(table_name, column_names, row)
-        destination_cursor.execute(sql_insert)
-
-        new_id = destination_cursor.lastrowid
-
-        new_ids.append(new_id)
-
-    return new_ids
-
-
-def import_session(source_db, destination_db, source_session):
-    """ Imports souce_session from source_d~/.local/share/Chronojump/database/chronojump.dbb into 
destination_db. Returns the session_id"""
-    ids = import_table_with_where(source_db, destination_db, "Session", "uniqueID", 
"uniqueID={}".format(source_session))
-
-    assert len(ids) == 1
-
-    return ids[0]
-
-
-def insert_person77(source_db, destination_db, person_id):
-    column_names = get_column_names(source_db, "Person77")
-    column_names = column_names[1:]
-
-    source_cursor = source_db.cursor()
-    select_sql = create_select("Person77", column_names, "uniqueId = {}".format(person_id))
-
-    source_cursor.execute(select_sql)
-
-    row = source_cursor.fetchall()[0]
-
-    insert_sql = create_insert("Person77", column_names, row)
-
-    destination_cursor = destination_db.cursor()
-
-    destination_cursor.execute(insert_sql)
-
-    person77_id = destination_cursor.lastrowid
-
-    return person77_id
-
-
-def get_person_id(source_db, destination_db, source_person_id):
-    """ Returns the personId if it person_name already exists or creates one and returns the personId"""
-    source_cursor = source_db.cursor()
-    destination_cursor = destination_db.cursor()
-
-    sql_select = "SELECT name FROM Person77 WHERE uniqueID = {}".format(source_person_id)
-    source_cursor.execute(sql_select)
-
-    results = source_cursor.fetchall()
-
-    assert results
-    assert len(results) > 0
-    assert len(results[0]) > 0
-
-    person_name = results[0][0]
-
-    print("Person name to look for:", person_name)
-
-    sql_select = "SELECT * FROM Person77 WHERE name = '{}'".format(person_name)
-    destination_cursor.execute(sql_select)
-
-    result = destination_cursor.fetchall()
-
-    if len(result) == 0:
-        return insert_person77(source_db, destination_db, source_person_id)
-    else:
-        return result[0][0]
-
-
-def import_jump_rj(source_db, destination_db, source_session, new_session_id):
-    source_cursor = source_db.cursor()
-    destination_cursor = destination_db.cursor()
-
-    column_names = get_column_names(source_db, "JumpRj")
-    column_names = column_names[1:]
-
-    source_cursor.execute("SELECT " + ",".join(column_names) + " FROM JumpRJ WHERE sessionID = 
{}".format(source_session))
-
-    results = source_cursor.fetchall()
-
-    new_ids = []
-
-    for row in results:
-        new_row = list(row)
-        personId = row[1]
-        new_person_id = get_person_id(source_db, destination_db, personId)
-        new_row[0] = new_person_id
-
-        sql_insert = create_insert("JumpRj",column_names, new_row)
-        print("Executing:", sql_insert)
-        destination_cursor.execute(sql_insert)
-
-        new_id = destination_cursor.lastrowid
-
-        new_ids.append(new_id)
-
-    return new_ids
-
-
-def import_person_session_77(source_db, destination_db, source_session, destination_session):
-    source_cursor = source_db.cursor()
-
-    person_session_77_columns = get_column_names(source_db, "PersonSession77")
-
-    person_session_77_columns = person_session_77_columns[1:]
-
-    source_cursor.execute("SELECT " + ",".join(person_session_77_columns) + " FROM PersonSession77 WHERE 
sessionID={}".format(source_session))
-    results = source_cursor.fetchall()
-
-    for row in results:
-        new_row = list(row)
-        new_person_id = get_person_id(source_db, destination_db, row[0])
-
-        new_row[0] = new_person_id
-        new_row[1] = destination_session
-
-        insert_person_session_77(destination_db, row)
-
-
-def import_reaction_time(source_db, destination_db, new_session_id):
-    """ TODO: it doesn't work it doesn't know the source session id"""
-    source_cursor = source_db.cursor()
-    destination_db = destination_db.cursor()
-
-    columns = get_column_names(source_db, "ReactionTime")
-    columns = columns[1:]
-    sql = create_select("ReactionTime", columns, "SessionID={}".format(new_session_id))
-
-    source_cursor.execute(sql)
-
-    results = source_cursor.fetchall()
-
-    for row in results:
-        new_row = list(row)
-
-        new_person_id = get_person_id(source_db, destination_db, new_row[0])
-
-        new_row[0] = new_person_id
-
-        create_insert("ReactionTime", columns, new_row)
-
-
-def insert_person_session_77(destination_db, row):
-    """ Inserts row into PersonSession77 and returns the uniqueID"""
-    destination_cursor = destination_db.cursor()
-
-    column_names = get_column_names(destination_db, "PersonSession77")
-    column_names = column_names[1:]
-
-    sql = create_insert("PersonSession77", column_names, row)
-
-    destination_cursor.execute(sql)
-
-    new_id = destination_cursor.lastrowid
-
-    return new_id
-
-
 def update_persons77_ids(table, persons77_list):
     result = copy.deepcopy(table)
 
@@ -456,12 +200,6 @@ def import_database(source_path, destination_path, source_session):
     insert_data(cursor=destination_cursor, table_name="JumpType", data=jump_types,
                 matches_columns=get_column_names(destination_cursor, "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(cursor=source_cursor, table_name="JumpRjType",
                                            where_condition="Session.uniqueID={}".format(source_session),
@@ -525,19 +263,11 @@ def import_database(source_path, destination_path, source_session):
     person_session_77 = update_session_ids(person_session_77, new_session_id)
     insert_data(cursor=destination_cursor, table_name="PersonSession77", data=person_session_77, 
matches_columns=None)
 
-    ### Continue from here
-
-    # import_person_session_77(source_db, destination_db, source_session, new_session_id)
-
-    # new_jump_rj_ids = import_jump_rj(source_db, destination_db, source_session, new_session_id)
-    # print("new_jump_rj_ids:", new_jump_rj_ids)
-
-    # import_reaction_time(source_db, destination_db, new_session_id)
-
     destination_db.commit()
-
     destination_db.close()
 
+    source_db.close()
+
 
 def open_database(filename, read_only):
     """Opens the database specified by filename. If read_only is True


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