Completed
Push — master ( 86313e...33cc0e )
by Jaisen
53s
created

Result.append()   A

Complexity

Conditions 2

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
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
12
    def append(self, row):
13
        id, status = row
14
15
        if status:
16
            self.success += 1
17
        else:
18
            self.error += 1
19
            self.error_items.append(id)
20
21
    def write(self):
22
        if self.error > 0:
23
            error_headers = ["File"]
24
            error_result = []
25
            for id in self.error_items:
26
                error_result.append([id])
27
28
            print("****** ERROR DETAILS ******")
29
            print(tabulate(error_result, headers=error_headers))
30
            print("\n")
31
32
        headers = ["Metric", "Count"]
33
        result = [
34
                    ["Success", self.success],
35
                    ["Error", self.error],
36
                 ]
37
38
        print("****** SUMMARY ******")
39
        print(tabulate(result, headers=headers))
40