Code Duplication    Length = 125-127 lines in 2 locations

myems-api/excelexporters/combinedequipmentenergyitem.py 1 location

@@ 188-314 (lines=127) @@
185
    current_row_number = 7
186
187
    reporting_period_data = report['reporting_period']
188
    if "names" not in reporting_period_data.keys() or \
189
            reporting_period_data['names'] is None or \
190
            len(reporting_period_data['names']) == 0:
191
        pass
192
    else:
193
        ws['B' + str(current_row_number)].font = title_font
194
        ws['B' + str(current_row_number)] = name + ' ' + _('Reporting Period Consumption')
195
196
        current_row_number += 1
197
198
        category = reporting_period_data['names']
199
        ca_len = len(category)
200
201
        ws.row_dimensions[current_row_number].height = 60
202
        ws['B' + str(current_row_number)].fill = table_fill
203
        ws['B' + str(current_row_number)].border = f_border
204
205
        col = 'C'
206
207
        for i in range(0, ca_len):
208
            ws[col + str(current_row_number)].fill = table_fill
209
            ws[col + str(current_row_number)].font = name_font
210
            ws[col + str(current_row_number)].alignment = c_c_alignment
211
            ws[col + str(current_row_number)].border = f_border
212
            ws[col + str(current_row_number)] = \
213
                reporting_period_data['names'][i] + " " + reporting_period_data['energy_category_names'][i] + \
214
                " (" + reporting_period_data['units'][i] + ")"
215
216
            col = chr(ord(col) + 1)
217
218
        current_row_number += 1
219
220
        ws['B' + str(current_row_number)].font = title_font
221
        ws['B' + str(current_row_number)].alignment = c_c_alignment
222
        ws['B' + str(current_row_number)].border = f_border
223
        ws['B' + str(current_row_number)] = _('Per Unit Area')
224
225
        col = 'C'
226
227
        for i in range(0, ca_len):
228
            ws[col + str(current_row_number)].font = name_font
229
            ws[col + str(current_row_number)].alignment = c_c_alignment
230
            ws[col + str(current_row_number)].border = f_border
231
            ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals'][i], 2)
232
233
            col = chr(ord(col) + 1)
234
235
        current_row_number += 1
236
237
        ws['B' + str(current_row_number)].font = title_font
238
        ws['B' + str(current_row_number)].alignment = c_c_alignment
239
        ws['B' + str(current_row_number)].border = f_border
240
        ws['B' + str(current_row_number)] = _('Increment Rate')
241
242
        col = 'C'
243
244
        for i in range(0, ca_len):
245
            ws[col + str(current_row_number)].font = name_font
246
            ws[col + str(current_row_number)].alignment = c_c_alignment
247
            ws[col + str(current_row_number)].border = f_border
248
            ws[col + str(current_row_number)] = str(
249
                round2(reporting_period_data['increment_rates'][i] * 100, 2)) + '%' \
250
                if reporting_period_data['increment_rates'][i] is not None else '-'
251
252
            col = chr(ord(col) + 1)
253
254
        current_row_number += 2
255
256
        category_dict = group_by_category(reporting_period_data['energy_category_names'])
257
258
        for category_dict_name, category_dict_values in category_dict.items():
259
260
            ws['B' + str(current_row_number)].font = title_font
261
            ws['B' + str(current_row_number)] = \
262
                name + ' ' + category_dict_name + ' ' + \
263
                '(' + reporting_period_data['units'][category_dict_values[0]] + ') by Energy Item'
264
265
            current_row_number += 1
266
            table_start_row_number = current_row_number
267
268
            ws['B' + str(current_row_number)].fill = table_fill
269
            ws['B' + str(current_row_number)].border = f_border
270
271
            ws['C' + str(current_row_number)].font = name_font
272
            ws['C' + str(current_row_number)].fill = table_fill
273
            ws['C' + str(current_row_number)].alignment = c_c_alignment
274
            ws['C' + str(current_row_number)].border = f_border
275
            ws['C' + str(current_row_number)] = _('Per Unit Area')
276
277
            current_row_number += 1
278
279
            for i in category_dict_values:
280
                ws['B' + str(current_row_number)].font = title_font
281
                ws['B' + str(current_row_number)].alignment = c_c_alignment
282
                ws['B' + str(current_row_number)].border = f_border
283
                ws['B' + str(current_row_number)] = \
284
                    reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
285
                ws['C' + str(current_row_number)].font = name_font
286
                ws['C' + str(current_row_number)].alignment = c_c_alignment
287
                ws['C' + str(current_row_number)].border = f_border
288
                ws['C' + str(current_row_number)] = round2(reporting_period_data['subtotals'][i], 3)
289
290
                current_row_number += 1
291
292
            table_end_row_number = current_row_number - 1
293
294
            pie = PieChart()
295
            pie.title = \
296
                name + ' ' + category_dict_name + ' ' + \
297
                '(' + reporting_period_data['units'][category_dict_values[0]] + ') by Energy Item'
298
            labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
299
            pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
300
            pie.add_data(pie_data, titles_from_data=True)
301
            pie.set_categories(labels)
302
            pie.height = 6.6
303
            pie.width = 9
304
            s1 = pie.series[0]
305
            s1.dLbls = DataLabelList()
306
            s1.dLbls.showCatName = False
307
            s1.dLbls.showVal = False
308
            s1.dLbls.showPercent = True
309
            ws.add_chart(pie, 'D' + str(table_start_row_number))
310
311
            if len(category_dict_values) < 4:
312
                current_row_number = current_row_number - len(category_dict_values) + 4
313
314
            current_row_number += 1
315
316
    ####################################################################################################################
317
    chart_start_row_number = current_row_number

myems-api/excelexporters/equipmentenergyitem.py 1 location

@@ 182-306 (lines=125) @@
179
180
    current_row_number = 7
181
    reporting_period_data = report['reporting_period']
182
    if "names" not in reporting_period_data.keys() or \
183
            reporting_period_data['names'] is None or \
184
            len(reporting_period_data['names']) == 0:
185
        pass
186
    else:
187
        ws['B' + str(current_row_number)].font = title_font
188
        ws['B' + str(current_row_number)] = name + ' ' + _('Reporting Period Consumption')
189
190
        current_row_number += 1
191
192
        category = reporting_period_data['names']
193
        ca_len = len(category)
194
195
        ws.row_dimensions[current_row_number].height = 60
196
        ws['B' + str(current_row_number)].fill = table_fill
197
        ws['B' + str(current_row_number)].border = f_border
198
199
        col = 'C'
200
201
        for i in range(0, ca_len):
202
            ws[col + str(current_row_number)].fill = table_fill
203
            ws[col + str(current_row_number)].font = name_font
204
            ws[col + str(current_row_number)].alignment = c_c_alignment
205
            ws[col + str(current_row_number)].border = f_border
206
            ws[col + str(current_row_number)] = \
207
                reporting_period_data['names'][i] + " " + reporting_period_data['energy_category_names'][i] + \
208
                " (" + reporting_period_data['units'][i] + ")"
209
210
            col = chr(ord(col) + 1)
211
212
        current_row_number += 1
213
214
        ws['B' + str(current_row_number)].font = title_font
215
        ws['B' + str(current_row_number)].alignment = c_c_alignment
216
        ws['B' + str(current_row_number)].border = f_border
217
        ws['B' + str(current_row_number)] = _('Consumption')
218
219
        col = 'C'
220
221
        for i in range(0, ca_len):
222
            ws[col + str(current_row_number)].font = name_font
223
            ws[col + str(current_row_number)].alignment = c_c_alignment
224
            ws[col + str(current_row_number)].border = f_border
225
            ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals'][i], 2)
226
227
            col = chr(ord(col) + 1)
228
229
        current_row_number += 1
230
231
        ws['B' + str(current_row_number)].font = title_font
232
        ws['B' + str(current_row_number)].alignment = c_c_alignment
233
        ws['B' + str(current_row_number)].border = f_border
234
        ws['B' + str(current_row_number)] = _('Increment Rate')
235
236
        col = 'C'
237
238
        for i in range(0, ca_len):
239
            ws[col + str(current_row_number)].font = name_font
240
            ws[col + str(current_row_number)].alignment = c_c_alignment
241
            ws[col + str(current_row_number)].border = f_border
242
            ws[col + str(current_row_number)] = str(
243
                round2(reporting_period_data['increment_rates'][i] * 100, 2)) + '%' \
244
                if reporting_period_data['increment_rates'][i] is not None else '-'
245
246
            col = chr(ord(col) + 1)
247
248
        current_row_number += 2
249
250
        category_dict = group_by_category(reporting_period_data['energy_category_names'])
251
252
        for category_dict_name, category_dict_values in category_dict.items():
253
254
            ws['B' + str(current_row_number)].font = title_font
255
            ws['B' + str(current_row_number)] = name + ' ' + category_dict_name + ' ' + \
256
                '(' + reporting_period_data['units'][category_dict_values[0]] + ') by Energy Item'
257
258
            current_row_number += 1
259
            table_start_row_number = current_row_number
260
261
            ws['B' + str(current_row_number)].fill = table_fill
262
            ws['B' + str(current_row_number)].border = f_border
263
264
            ws['C' + str(current_row_number)].font = name_font
265
            ws['C' + str(current_row_number)].fill = table_fill
266
            ws['C' + str(current_row_number)].alignment = c_c_alignment
267
            ws['C' + str(current_row_number)].border = f_border
268
            ws['C' + str(current_row_number)] = _('Consumption')
269
270
            current_row_number += 1
271
272
            for i in category_dict_values:
273
                ws['B' + str(current_row_number)].font = title_font
274
                ws['B' + str(current_row_number)].alignment = c_c_alignment
275
                ws['B' + str(current_row_number)].border = f_border
276
                ws['B' + str(current_row_number)] = \
277
                    reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
278
                ws['C' + str(current_row_number)].font = name_font
279
                ws['C' + str(current_row_number)].alignment = c_c_alignment
280
                ws['C' + str(current_row_number)].border = f_border
281
                ws['C' + str(current_row_number)] = round2(reporting_period_data['subtotals'][i], 3)
282
283
                current_row_number += 1
284
285
            table_end_row_number = current_row_number - 1
286
287
            pie = PieChart()
288
            pie.title = name + ' ' + category_dict_name + ' ' + \
289
                '(' + reporting_period_data['units'][category_dict_values[0]] + ') by Energy Item'
290
            labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
291
            pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
292
            pie.add_data(pie_data, titles_from_data=True)
293
            pie.set_categories(labels)
294
            pie.height = 6.6
295
            pie.width = 9
296
            s1 = pie.series[0]
297
            s1.dLbls = DataLabelList()
298
            s1.dLbls.showCatName = False
299
            s1.dLbls.showVal = False
300
            s1.dLbls.showPercent = True
301
            ws.add_chart(pie, 'D' + str(table_start_row_number))
302
303
            if len(category_dict_values) < 4:
304
                current_row_number = current_row_number - len(category_dict_values) + 4
305
306
            current_row_number += 1
307
308
    ####################################################################################################################
309
    chart_start_row_number = current_row_number