Passed
Pull Request — master (#461)
by
unknown
02:13
created

elodie.result.Result.write()   B

Complexity

Conditions 5

Size

Total Lines 31
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 25
nop 1
dl 0
loc 31
rs 8.8133
c 0
b 0
f 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:
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