[chronojump/chronojump-importer] Moves remove_duplicates() in the Table class.
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/chronojump-importer] Moves remove_duplicates() in the Table class.
- Date: Fri, 9 Sep 2016 15:09:31 +0000 (UTC)
commit 3c68eb9ef44eaf488552130b2e70c18c4e3154fd
Author: Carles Pina i Estany <carles pina cat>
Date: Fri Sep 9 16:09:11 2016 +0100
Moves remove_duplicates() in the Table class.
src/chronojump-importer/chronojump_importer.py | 32 ++++++++++++-------
.../chronojump_importer_test.py | 24 +++++++++++----
2 files changed, 38 insertions(+), 18 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index 0bb3371..94d7d98 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -48,6 +48,9 @@ class Row:
def columns(self):
return self._row.keys()
+ def __eq__(self, other):
+ return self._row == other._row
+
class Table:
""" This class has Table operations. Rows should be inserted and then can
@@ -59,6 +62,19 @@ class Table:
def insert_row(self, row):
self._table_data.append(row)
+ def add_table(self, table):
+ self._table_data += table._table_data
+
+ def remove_duplicates(self):
+ """ Returns a new list without duplicate elements. """
+ new_data = []
+
+ for index, element in enumerate(self._table_data):
+ if element not in self._table_data[index + 1:]:
+ new_data.append(element)
+
+ self._table_data = new_data
+
@property
def name(self):
return self._table_name
@@ -319,17 +335,6 @@ def print_summary(table_name, table_data):
print("\treused: {reused_counter} uniqueIDs: {reused}".format(reused_counter=len(reused_ids),
reused=reused_ids))
-def remove_duplicates_list(l):
- """ Returns a new list without duplicate elements. """
- result = []
-
- for index, element in enumerate(l):
- if element not in l[index+1:]:
- result.append(element)
-
- return result
-
-
def import_database(source_path, destination_path, source_session):
""" Imports the session source_session from source_db into destination_db """
@@ -391,7 +396,10 @@ def import_database(source_path, destination_path, source_session):
group_by_clause="Person77.uniqueID")
persons77 = Table("person77")
- persons77._table_data = remove_duplicates_list(persons77_jump._table_data +
persons77_jump_rj._table_data)
+ persons77.add_table(persons77_jump)
+ persons77.add_table(persons77_jump_rj)
+ persons77.remove_duplicates()
+ # persons77._table_data = remove_duplicates_list(persons77_jump._table_data +
persons77_jump_rj._table_data)
destination_db.write(table=persons77,
matches_columns=["name"])
diff --git a/src/chronojump-importer/chronojump_importer_test.py
b/src/chronojump-importer/chronojump_importer_test.py
index 16d2730..ed5847c 100755
--- a/src/chronojump-importer/chronojump_importer_test.py
+++ b/src/chronojump-importer/chronojump_importer_test.py
@@ -3,13 +3,11 @@
import unittest
import chronojump_importer
import os
-import subprocess
import tempfile
import shutil
import difflib
import ddt
-import pprint
-import sqlite3
+
@ddt.ddt
class TestImporter(unittest.TestCase):
@@ -94,11 +92,25 @@ class TestImporter(unittest.TestCase):
self.assertEqual(row.get('sessionID'), 4)
def test_remove_duplicates_list(self):
- l = [1,1,2,3,2]
+ row1 = chronojump_importer.Row()
+ row1.set("name", "john")
+ row2 = chronojump_importer.Row()
+ row2.set("name", "john")
+ row3 = chronojump_importer.Row()
+ row3.set("name", "sam")
+
+ table = chronojump_importer.Table("Test")
+ table.insert_row(row1)
+ table.insert_row(row2)
+ table.insert_row(row3)
+
+ self.assertEqual(len(table._table_data), 3)
+ table.remove_duplicates()
+
+ self.assertEqual(len(table._table_data), 2)
- actual = chronojump_importer.remove_duplicates_list(l)
+ # TODO: verify that the contents is right
- self.assertEqual(sorted(actual), sorted([1,2,3]))
def test_update_ids_from_table(self):
table_to_update = chronojump_importer.Table("table_to_update")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]