| Conditions | 9 | 
| Total Lines | 91 | 
| Code Lines | 77 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import base64  | 
            ||
| 55 | def generate_excel(report, space_name, reporting_start_datetime_local, reporting_end_datetime_local, language):  | 
            ||
| 56 | |||
| 57 | locale_path = './i18n/'  | 
            ||
| 58 | if language == 'zh_CN':  | 
            ||
| 59 |         trans = gettext.translation('myems', locale_path, languages=['zh_CN']) | 
            ||
| 60 | elif language == 'de':  | 
            ||
| 61 |         trans = gettext.translation('myems', locale_path, languages=['de']) | 
            ||
| 62 | elif language == 'en':  | 
            ||
| 63 |         trans = gettext.translation('myems', locale_path, languages=['en']) | 
            ||
| 64 | else:  | 
            ||
| 65 |         trans = gettext.translation('myems', locale_path, languages=['en']) | 
            ||
| 66 | trans.install()  | 
            ||
| 67 | _ = trans.gettext  | 
            ||
| 68 | |||
| 69 | wb = Workbook()  | 
            ||
| 70 | ws = wb.active  | 
            ||
| 71 | ws.title = "MeterTracking"  | 
            ||
| 72 | |||
| 73 | # Column width  | 
            ||
| 74 |     for i in range(ord('A'), ord('I')): | 
            ||
| 75 | ws.column_dimensions[chr(i)].width = 25.0  | 
            ||
| 76 | |||
| 77 | # Head image  | 
            ||
| 78 | ws.row_dimensions[1].height = 105  | 
            ||
| 79 |     img = Image("excelexporters/myems.png") | 
            ||
| 80 | ws.add_image(img, 'A1')  | 
            ||
| 81 | |||
| 82 | # Query Parameters  | 
            ||
| 83 | b_r_alignment = Alignment(vertical='bottom',  | 
            ||
| 84 | horizontal='right',  | 
            ||
| 85 | text_rotation=0,  | 
            ||
| 86 | wrap_text=True,  | 
            ||
| 87 | shrink_to_fit=False,  | 
            ||
| 88 | indent=0)  | 
            ||
| 89 | ws['A3'].alignment = b_r_alignment  | 
            ||
| 90 |     ws['A3'] = _('Space') + ':' | 
            ||
| 91 | ws['B3'] = space_name  | 
            ||
| 92 | ws['A4'].alignment = b_r_alignment  | 
            ||
| 93 |     ws['A4'] = _('Start Datetime') + ':' | 
            ||
| 94 | ws['B4'] = reporting_start_datetime_local  | 
            ||
| 95 | ws['A5'].alignment = b_r_alignment  | 
            ||
| 96 |     ws['A5'] = _('End Datetime') + ':' | 
            ||
| 97 | ws['B5'] = reporting_end_datetime_local  | 
            ||
| 98 | ws['A6'].alignment = b_r_alignment  | 
            ||
| 99 |     ws['A6'] = _('Start Integrity Rate') + ':' | 
            ||
| 100 | ws['B6'] = (str(report['start_integrity_rate'] * Decimal(100.0)) + '%') \  | 
            ||
| 101 | if report['start_integrity_rate'] is not None else None  | 
            ||
| 102 | ws['A7'].alignment = b_r_alignment  | 
            ||
| 103 |     ws['A7'] = _('End Integrity Rate') + ':' | 
            ||
| 104 | ws['B7'] = (str(report['end_integrity_rate'] * Decimal(100.0)) + '%') \  | 
            ||
| 105 | if report['end_integrity_rate'] is not None else None  | 
            ||
| 106 | ws['A8'].alignment = b_r_alignment  | 
            ||
| 107 |     ws['A8'] = _('Full Integrity Rate') + ':' | 
            ||
| 108 | ws['B8'] = (str(report['full_integrity_rate'] * Decimal(100.0)) + '%') \  | 
            ||
| 109 | if report['full_integrity_rate'] is not None else None  | 
            ||
| 110 | |||
| 111 | # Title  | 
            ||
| 112 | title_font = Font(size=12, bold=True)  | 
            ||
| 113 | ws['A9'].font = title_font  | 
            ||
| 114 | ws['A9'] = 'ID'  | 
            ||
| 115 | ws['B9'].font = title_font  | 
            ||
| 116 | ws['B9'] = 'Name'  | 
            ||
| 117 | ws['C9'].font = title_font  | 
            ||
| 118 | ws['C9'] = 'Space'  | 
            ||
| 119 | ws['D9'].font = title_font  | 
            ||
| 120 | ws['D9'] = 'Cost Center'  | 
            ||
| 121 | ws['E9'].font = title_font  | 
            ||
| 122 | ws['E9'] = 'Energy Category'  | 
            ||
| 123 | ws['F9'].font = title_font  | 
            ||
| 124 | ws['F9'] = 'Description'  | 
            ||
| 125 | ws['G9'].font = title_font  | 
            ||
| 126 | ws['G9'] = 'Start Value'  | 
            ||
| 127 | ws['H9'].font = title_font  | 
            ||
| 128 | ws['H9'] = 'End Value'  | 
            ||
| 129 | |||
| 130 | current_row_number = 10  | 
            ||
| 131 | for i in range(0, len(report['meters'])):  | 
            ||
| 132 | ws['A' + str(current_row_number)] = report['meters'][i]['id']  | 
            ||
| 133 | ws['B' + str(current_row_number)] = report['meters'][i]['meter_name']  | 
            ||
| 134 | ws['C' + str(current_row_number)] = report['meters'][i]['space_name']  | 
            ||
| 135 | ws['D' + str(current_row_number)] = report['meters'][i]['cost_center_name']  | 
            ||
| 136 | ws['E' + str(current_row_number)] = report['meters'][i]['energy_category_name']  | 
            ||
| 137 | ws['F' + str(current_row_number)] = report['meters'][i]['description']  | 
            ||
| 138 | ws['G' + str(current_row_number)] = report['meters'][i]['start_value']  | 
            ||
| 139 | ws['H' + str(current_row_number)] = report['meters'][i]['end_value']  | 
            ||
| 140 | current_row_number += 1  | 
            ||
| 141 | |||
| 142 | filename = str(uuid.uuid4()) + '.xlsx'  | 
            ||
| 143 | wb.save(filename)  | 
            ||
| 144 | |||
| 145 | return filename  | 
            ||
| 146 |