Code Duplication    Length = 15-15 lines in 5 locations

myems-api/reports/spaceproduction.py 3 locations

@@ 386-400 (lines=15) @@
383
        start_datetime_local = start_datetime_utc + timedelta(hours=int(config.utc_offset[1:3]))
384
        current_datetime_utc = start_datetime_local.replace(hour=0) - timedelta(hours=int(config.utc_offset[1:3]))
385
386
        while current_datetime_utc <= end_datetime_utc:
387
            flag = True
388
            subtotal = Decimal(0.0)
389
            for row in rows_space_production_hourly:
390
                if current_datetime_utc <= row[0] < current_datetime_utc + timedelta(days=1):
391
                    flag = False
392
                    subtotal += row[1]
393
            if flag:
394
                subtotal = None
395
            current_datetime = start_datetime_local.isoformat()[0:10]
396
397
            base_date_list.append(current_datetime)
398
            base_daily_values.append(subtotal)
399
            current_datetime_utc += timedelta(days=1)
400
            start_datetime_local += timedelta(days=1)
401
402
        ################################################################################################################
403
        # Step 6: query base period energy consumption
@@ 332-346 (lines=15) @@
329
        start_datetime_local = start_datetime_utc + timedelta(hours=int(config.utc_offset[1:3]))
330
        current_datetime_utc = start_datetime_local.replace(hour=0) - timedelta(hours=int(config.utc_offset[1:3]))
331
332
        while current_datetime_utc <= end_datetime_utc:
333
            flag = True
334
            subtotal = Decimal(0.0)
335
            for row in rows_space_production_hourly:
336
                if current_datetime_utc <= row[0] < current_datetime_utc + timedelta(days=1):
337
                    flag = False
338
                    subtotal += row[1]
339
            if flag:
340
                subtotal = None
341
            current_datetime = start_datetime_local.isoformat()[0:10]
342
343
            reporting_date_list.append(current_datetime)
344
            reporting_daily_values.append(subtotal)
345
            current_datetime_utc += timedelta(days=1)
346
            start_datetime_local += timedelta(days=1)
347
348
        query = (" SELECT name, unit_of_measure, tag, standard_product_coefficient "
349
                 " FROM tbl_products "
@@ 220-234 (lines=15) @@
217
        start_datetime_local = start_datetime_utc + timedelta(hours=int(config.utc_offset[1:3]))
218
        current_datetime_utc = start_datetime_local.replace(hour=0) - timedelta(hours=int(config.utc_offset[1:3]))
219
220
        while current_datetime_utc <= end_datetime_utc:
221
            flag = True
222
            subtotal = Decimal(0.0)
223
            for row in rows_space_production_hourly:
224
                if current_datetime_utc <= row[0] < current_datetime_utc + timedelta(days=1):
225
                    flag = False
226
                    subtotal += row[1]
227
            if flag:
228
                subtotal = None
229
            current_datetime = start_datetime_local.isoformat()[0:10]
230
231
            base_date_list.append(current_datetime)
232
            base_daily_values.append(subtotal)
233
            current_datetime_utc += timedelta(days=1)
234
            start_datetime_local += timedelta(days=1)
235
236
        ################################################################################################################
237
        # Step 3: query energy categories

myems-api/reports/enterproduction.py 1 location

@@ 178-192 (lines=15) @@
175
        start_datetime_local = start_datetime_utc + timedelta(hours=int(config.utc_offset[1:3]))
176
        current_datetime_utc = start_datetime_local.replace(hour=0) - timedelta(hours=int(config.utc_offset[1:3]))
177
178
        while current_datetime_utc <= end_datetime_utc:
179
            flag = True
180
            subtotal = Decimal(0.0)
181
            for row in rows_space_production_hourly:
182
                if current_datetime_utc <= row[0] < current_datetime_utc + timedelta(days=1):
183
                    flag = False
184
                    subtotal += row[1]
185
            if flag:
186
                subtotal = None
187
            current_datetime = start_datetime_local.isoformat()[0:10]
188
189
            reporting_date_list.append(current_datetime)
190
            reporting_daily_values.append(subtotal)
191
            current_datetime_utc += timedelta(days=1)
192
            start_datetime_local += timedelta(days=1)
193
194
        ################################################################################################################
195
        # Step 3: construct the report

myems-api/reports/offlinemeterdaily.py 1 location

@@ 151-165 (lines=15) @@
148
        start_datetime_local = start_datetime_utc + timedelta(hours=int(config.utc_offset[1:3]))
149
        current_datetime_utc = start_datetime_local.replace(hour=0) - timedelta(hours=int(config.utc_offset[1:3]))
150
151
        while current_datetime_utc <= end_datetime_utc:
152
            flag = True
153
            subtotal = Decimal(0.0)
154
            for row in rows_offline_meter_hourly:
155
                if current_datetime_utc <= row[0] < current_datetime_utc + timedelta(days=1):
156
                    flag = False
157
                    subtotal += row[1]
158
            if flag:
159
                subtotal = None
160
            current_datetime = start_datetime_local.isoformat()[0:10]
161
162
            reporting_date_list.append(current_datetime)
163
            reporting_daily_values.append(subtotal)
164
            current_datetime_utc += timedelta(days=1)
165
            start_datetime_local += timedelta(days=1)
166
        
167
        ################################################################################################################
168
        # Step 6: construct the report