Code Duplication    Length = 31-39 lines in 7 locations

excelexporters/metertrend.py 1 location

@@ 24-62 (lines=39) @@
21
####################################################################################################################
22
23
24
def export(result,
25
           name,
26
           reporting_start_datetime_local,
27
           reporting_end_datetime_local,
28
           period_type):
29
    ####################################################################################################################
30
    # Step 1: Validate the report data
31
    ####################################################################################################################
32
    if result is None:
33
        return None
34
35
    ####################################################################################################################
36
    # Step 2: Generate excel file from the report data
37
    ####################################################################################################################
38
    filename = generate_excel(result,
39
                              name,
40
                              reporting_start_datetime_local,
41
                              reporting_end_datetime_local,
42
                              period_type)
43
44
    ####################################################################################################################
45
    # Step 3: Encode the excel file to Base64
46
    ####################################################################################################################
47
    try:
48
        with open(filename, 'rb') as binary_file:
49
            binary_file_data = binary_file.read()
50
    except IOError as ex:
51
        pass
52
53
    # Base64 encode the bytes
54
    base64_encoded_data = base64.b64encode(binary_file_data)
55
    # get the Base64 encoded data using human-readable characters.
56
    base64_message = base64_encoded_data.decode('utf-8')
57
    # delete the file from server
58
    try:
59
        os.remove(filename)
60
    except NotImplementedError as ex:
61
        pass
62
    return base64_message
63
64
65
def generate_excel(report,

excelexporters/virtualmeterenergy.py 1 location

@@ 24-57 (lines=34) @@
21
# Step 3: Encode the excelexporters file to Base64
22
####################################################################################################################
23
24
def export(result, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):
25
    ####################################################################################################################
26
    # Step 1: Validate the report data
27
    ####################################################################################################################
28
    if result is None:
29
        return None
30
31
    ####################################################################################################################
32
    # Step 2: Generate excel file from the report data
33
    ####################################################################################################################
34
    filename = generate_excel(result,
35
                              name,
36
                              reporting_start_datetime_local,
37
                              reporting_end_datetime_local,
38
                              period_type)
39
    ####################################################################################################################
40
    # Step 3: Encode the excel file to Base64
41
    ####################################################################################################################
42
    try:
43
        with open(filename, 'rb') as binary_file:
44
            binary_file_data = binary_file.read()
45
    except IOError as ex:
46
        pass
47
48
    # Base64 encode the bytes
49
    base64_encoded_data = base64.b64encode(binary_file_data)
50
    # get the Base64 encoded data using human-readable characters.
51
    base64_message = base64_encoded_data.decode('utf-8')
52
    # delete the file from server
53
    try:
54
        os.remove(filename)
55
    except NotImplementedError as ex:
56
        pass
57
    return base64_message
58
59
60
def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):

excelexporters/offlinemeterenergy.py 1 location

@@ 22-55 (lines=34) @@
19
# Step 3: Encode the excelexporters file to Base64
20
####################################################################################################################
21
22
def export(result, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):
23
    ####################################################################################################################
24
    # Step 1: Validate the report data
25
    ####################################################################################################################
26
    if result is None:
27
        return None
28
29
    ####################################################################################################################
30
    # Step 2: Generate excel file from the report data
31
    ####################################################################################################################
32
    filename = generate_excel(result,
33
                              name,
34
                              reporting_start_datetime_local,
35
                              reporting_end_datetime_local,
36
                              period_type)
37
    ####################################################################################################################
38
    # Step 3: Encode the excel file to Base64
39
    ####################################################################################################################
40
    try:
41
        with open(filename, 'rb') as binary_file:
42
            binary_file_data = binary_file.read()
43
    except IOError as ex:
44
        pass
45
46
    # Base64 encode the bytes
47
    base64_encoded_data = base64.b64encode(binary_file_data)
48
    # get the Base64 encoded data using human-readable characters.
49
    base64_message = base64_encoded_data.decode('utf-8')
50
    # delete the file from server
51
    try:
52
        os.remove(filename)
53
    except NotImplementedError as ex:
54
        pass
55
    return base64_message
56
57
58
def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):

excelexporters/meterenergy.py 1 location

@@ 22-55 (lines=34) @@
19
# Step 3: Encode the excelexporters file to Base64
20
####################################################################################################################
21
22
def export(result, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):
23
    ####################################################################################################################
24
    # Step 1: Validate the report data
25
    ####################################################################################################################
26
    if result is None:
27
        return None
28
29
    ####################################################################################################################
30
    # Step 2: Generate excel file from the report data
31
    ####################################################################################################################
32
    filename = generate_excel(result,
33
                              name,
34
                              reporting_start_datetime_local,
35
                              reporting_end_datetime_local,
36
                              period_type)
37
    ####################################################################################################################
38
    # Step 3: Encode the excel file to Base64
39
    ####################################################################################################################
40
    try:
41
        with open(filename, 'rb') as binary_file:
42
            binary_file_data = binary_file.read()
43
    except IOError as ex:
44
        pass
45
46
    # Base64 encode the bytes
47
    base64_encoded_data = base64.b64encode(binary_file_data)
48
    # get the Base64 encoded data using human-readable characters.
49
    base64_message = base64_encoded_data.decode('utf-8')
50
    # delete the file from server
51
    try:
52
        os.remove(filename)
53
    except NotImplementedError as ex:
54
        pass
55
    return base64_message
56
57
58
def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):

excelexporters/metersubmetersbalance.py 1 location

@@ 22-55 (lines=34) @@
19
# Step 3: Encode the excelexporters file to Base64
20
####################################################################################################################
21
22
def export(result, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):
23
    ####################################################################################################################
24
    # Step 1: Validate the report data
25
    ####################################################################################################################
26
    if result is None:
27
        return None
28
29
    ####################################################################################################################
30
    # Step 2: Generate excel file from the report data
31
    ####################################################################################################################
32
    filename = generate_excel(result,
33
                              name,
34
                              reporting_start_datetime_local,
35
                              reporting_end_datetime_local,
36
                              period_type)
37
    ####################################################################################################################
38
    # Step 3: Encode the excel file to Base64
39
    ####################################################################################################################
40
    try:
41
        with open(filename, 'rb') as binary_file:
42
            binary_file_data = binary_file.read()
43
    except IOError as ex:
44
        pass
45
46
    # Base64 encode the bytes
47
    base64_encoded_data = base64.b64encode(binary_file_data)
48
    # get the Base64 encoded data using human-readable characters.
49
    base64_message = base64_encoded_data.decode('utf-8')
50
    # delete the file from server
51
    try:
52
        os.remove(filename)
53
    except NotImplementedError as ex:
54
        pass
55
    return base64_message
56
57
58
def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):

excelexporters/equipmenttracking.py 1 location

@@ 21-51 (lines=31) @@
18
# Step 3: Encode the excelexporters file to Base64
19
####################################################################################################################
20
21
def export(result, space_name):
22
    ####################################################################################################################
23
    # Step 1: Validate the report data
24
    ####################################################################################################################
25
    if result is None:
26
        return None
27
28
    ####################################################################################################################
29
    # Step 2: Generate excel file from the report data
30
    ####################################################################################################################
31
    filename = generate_excel(result,
32
                              space_name)
33
    ####################################################################################################################
34
    # Step 3: Encode the excel file to Base64
35
    ####################################################################################################################
36
    try:
37
        with open(filename, 'rb') as binary_file:
38
            binary_file_data = binary_file.read()
39
    except IOError as ex:
40
        pass
41
42
    # Base64 encode the bytes
43
    base64_encoded_data = base64.b64encode(binary_file_data)
44
    # get the Base64 encoded data using human-readable characters.
45
    base64_message = base64_encoded_data.decode('utf-8')
46
    # delete the file from server
47
    try:
48
        os.remove(filename)
49
    except NotImplementedError as ex:
50
        pass
51
    return base64_message
52
53
54
def generate_excel(report, space_name):

excelexporters/metertracking.py 1 location

@@ 21-51 (lines=31) @@
18
# Step 3: Encode the excelexporters file to Base64
19
####################################################################################################################
20
21
def export(result, space_name):
22
    ####################################################################################################################
23
    # Step 1: Validate the report data
24
    ####################################################################################################################
25
    if result is None:
26
        return None
27
28
    ####################################################################################################################
29
    # Step 2: Generate excel file from the report data
30
    ####################################################################################################################
31
    filename = generate_excel(result,
32
                              space_name)
33
    ####################################################################################################################
34
    # Step 3: Encode the excel file to Base64
35
    ####################################################################################################################
36
    try:
37
        with open(filename, 'rb') as binary_file:
38
            binary_file_data = binary_file.read()
39
    except IOError as ex:
40
        pass
41
42
    # Base64 encode the bytes
43
    base64_encoded_data = base64.b64encode(binary_file_data)
44
    # get the Base64 encoded data using human-readable characters.
45
    base64_message = base64_encoded_data.decode('utf-8')
46
    # delete the file from server
47
    try:
48
        os.remove(filename)
49
    except NotImplementedError as ex:
50
        pass
51
    return base64_message
52
53
54
def generate_excel(report, space_name):