Total Complexity | 9 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from tabulate import tabulate |
||
2 | |||
3 | |||
4 | class Result(object): |
||
5 | |||
6 | def __init__(self): |
||
7 | self.records = [] |
||
8 | self.success = 0 |
||
9 | self.error = 0 |
||
10 | self.error_items = [] |
||
11 | self.duplicate = 0 |
||
12 | self.duplicate_items = [] |
||
13 | |||
14 | def append(self, row): |
||
15 | id, status = row |
||
16 | |||
17 | # status can only be True, False, or None |
||
18 | if status is True: |
||
19 | self.success += 1 |
||
20 | elif status is None: # status is only ever None if file checksum matched an existing file checksum and is therefore a duplicate file |
||
21 | self.duplicate += 1 |
||
22 | self.duplicate_items.append(id) |
||
23 | else: |
||
24 | self.error += 1 |
||
25 | self.error_items.append(id) |
||
26 | |||
27 | def write(self): |
||
28 | print("\n") |
||
29 | if self.error > 0: |
||
30 | error_headers = ["File"] |
||
31 | error_result = [] |
||
32 | for id in self.error_items: |
||
33 | error_result.append([id]) |
||
34 | |||
35 | print("****** ERROR DETAILS ******") |
||
36 | print(tabulate(error_result, headers=error_headers)) |
||
37 | print("\n") |
||
38 | |||
39 | if self.duplicate > 0: |
||
40 | duplicate_headers = ["File"] |
||
41 | duplicate_result = [] |
||
42 | for id in self.duplicate_items: |
||
43 | duplicate_result.append([id]) |
||
44 | |||
45 | print("****** DUPLICATE (NOT IMPORTED) DETAILS ******") |
||
46 | print(tabulate(duplicate_result, headers=duplicate_headers)) |
||
47 | print("\n") |
||
48 | |||
49 | headers = ["Metric", "Count"] |
||
50 | result = [ |
||
51 | ["Success", self.success], |
||
52 | ["Error", self.error], |
||
53 | ["Duplicate, not imported", self.duplicate] |
||
54 | ] |
||
55 | |||
56 | print("****** SUMMARY ******") |
||
57 | print(tabulate(result, headers=headers)) |
||
58 |