Code Duplication    Length = 125-127 lines in 2 locations

myems-api/excelexporters/equipmentenergyitem.py 1 location

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

myems-api/excelexporters/combinedequipmentenergyitem.py 1 location

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