Code Duplication    Length = 63-63 lines in 6 locations

myems-api/reports/combinedequipmentefficiency.py 1 location

@@ 692-754 (lines=63) @@
689
        parameters_data['names'] = list()
690
        parameters_data['timestamps'] = list()
691
        parameters_data['values'] = list()
692
        if not is_quick_mode:
693
            for point in point_list:
694
                point_values = []
695
                point_timestamps = []
696
                if point['object_type'] == 'ANALOG_VALUE':
697
                    query = (" SELECT utc_date_time, actual_value "
698
                             " FROM tbl_analog_value "
699
                             " WHERE point_id = %s "
700
                             "       AND utc_date_time BETWEEN %s AND %s "
701
                             " ORDER BY utc_date_time ")
702
                    cursor_historical.execute(query, (point['id'],
703
                                                      reporting_start_datetime_utc,
704
                                                      reporting_end_datetime_utc))
705
                    rows = cursor_historical.fetchall()
706
707
                    if rows is not None and len(rows) > 0:
708
                        for row in rows:
709
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
710
                                                     timedelta(minutes=timezone_offset)
711
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
712
                            point_timestamps.append(current_datetime)
713
                            point_values.append(row[1])
714
715
                elif point['object_type'] == 'ENERGY_VALUE':
716
                    query = (" SELECT utc_date_time, actual_value "
717
                             " FROM tbl_energy_value "
718
                             " WHERE point_id = %s "
719
                             "       AND utc_date_time BETWEEN %s AND %s "
720
                             " ORDER BY utc_date_time ")
721
                    cursor_historical.execute(query, (point['id'],
722
                                                      reporting_start_datetime_utc,
723
                                                      reporting_end_datetime_utc))
724
                    rows = cursor_historical.fetchall()
725
726
                    if rows is not None and len(rows) > 0:
727
                        for row in rows:
728
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
729
                                                     timedelta(minutes=timezone_offset)
730
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
731
                            point_timestamps.append(current_datetime)
732
                            point_values.append(row[1])
733
                elif point['object_type'] == 'DIGITAL_VALUE':
734
                    query = (" SELECT utc_date_time, actual_value "
735
                             " FROM tbl_digital_value "
736
                             " WHERE point_id = %s "
737
                             "       AND utc_date_time BETWEEN %s AND %s "
738
                             " ORDER BY utc_date_time ")
739
                    cursor_historical.execute(query, (point['id'],
740
                                                      reporting_start_datetime_utc,
741
                                                      reporting_end_datetime_utc))
742
                    rows = cursor_historical.fetchall()
743
744
                    if rows is not None and len(rows) > 0:
745
                        for row in rows:
746
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
747
                                                     timedelta(minutes=timezone_offset)
748
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
749
                            point_timestamps.append(current_datetime)
750
                            point_values.append(row[1])
751
752
                parameters_data['names'].append(point['name'] + ' (' + point['units'] + ')')
753
                parameters_data['timestamps'].append(point_timestamps)
754
                parameters_data['values'].append(point_values)
755
756
        ################################################################################################################
757
        # Step 11: query associated equipments energy input

myems-api/reports/spaceenergycategory.py 1 location

@@ 448-510 (lines=63) @@
445
        ################################################################################################################
446
        # Step 10: query associated sensors and points data
447
        ################################################################################################################
448
        if not is_quick_mode:
449
            for point in point_list:
450
                point_values = []
451
                point_timestamps = []
452
                if point['object_type'] == 'ANALOG_VALUE':
453
                    query = (" SELECT utc_date_time, actual_value "
454
                             " FROM tbl_analog_value "
455
                             " WHERE point_id = %s "
456
                             "       AND utc_date_time BETWEEN %s AND %s "
457
                             " ORDER BY utc_date_time ")
458
                    cursor_historical.execute(query, (point['id'],
459
                                                      reporting_start_datetime_utc,
460
                                                      reporting_end_datetime_utc))
461
                    rows = cursor_historical.fetchall()
462
463
                    if rows is not None and len(rows) > 0:
464
                        for row in rows:
465
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
466
                                                     timedelta(minutes=timezone_offset)
467
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
468
                            point_timestamps.append(current_datetime)
469
                            point_values.append(row[1])
470
471
                elif point['object_type'] == 'ENERGY_VALUE':
472
                    query = (" SELECT utc_date_time, actual_value "
473
                             " FROM tbl_energy_value "
474
                             " WHERE point_id = %s "
475
                             "       AND utc_date_time BETWEEN %s AND %s "
476
                             " ORDER BY utc_date_time ")
477
                    cursor_historical.execute(query, (point['id'],
478
                                                      reporting_start_datetime_utc,
479
                                                      reporting_end_datetime_utc))
480
                    rows = cursor_historical.fetchall()
481
482
                    if rows is not None and len(rows) > 0:
483
                        for row in rows:
484
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
485
                                                     timedelta(minutes=timezone_offset)
486
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
487
                            point_timestamps.append(current_datetime)
488
                            point_values.append(row[1])
489
                elif point['object_type'] == 'DIGITAL_VALUE':
490
                    query = (" SELECT utc_date_time, actual_value "
491
                             " FROM tbl_digital_value "
492
                             " WHERE point_id = %s "
493
                             "       AND utc_date_time BETWEEN %s AND %s "
494
                             " ORDER BY utc_date_time ")
495
                    cursor_historical.execute(query, (point['id'],
496
                                                      reporting_start_datetime_utc,
497
                                                      reporting_end_datetime_utc))
498
                    rows = cursor_historical.fetchall()
499
500
                    if rows is not None and len(rows) > 0:
501
                        for row in rows:
502
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
503
                                                     timedelta(minutes=timezone_offset)
504
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
505
                            point_timestamps.append(current_datetime)
506
                            point_values.append(row[1])
507
508
                parameters_data['names'].append(point['name'] + ' (' + point['units'] + ')')
509
                parameters_data['timestamps'].append(point_timestamps)
510
                parameters_data['values'].append(point_values)
511
512
        ################################################################################################################
513
        # Step 11: query child spaces energy input

myems-api/reports/spaceload.py 1 location

@@ 424-486 (lines=63) @@
421
        ################################################################################################################
422
        # Step 9: query associated sensors and points data
423
        ################################################################################################################
424
        if not is_quick_mode:
425
            for point in point_list:
426
                point_values = []
427
                point_timestamps = []
428
                if point['object_type'] == 'ANALOG_VALUE':
429
                    query = (" SELECT utc_date_time, actual_value "
430
                             " FROM tbl_analog_value "
431
                             " WHERE point_id = %s "
432
                             "       AND utc_date_time BETWEEN %s AND %s "
433
                             " ORDER BY utc_date_time ")
434
                    cursor_historical.execute(query, (point['id'],
435
                                                      reporting_start_datetime_utc,
436
                                                      reporting_end_datetime_utc))
437
                    rows = cursor_historical.fetchall()
438
439
                    if rows is not None and len(rows) > 0:
440
                        for row in rows:
441
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
442
                                                     timedelta(minutes=timezone_offset)
443
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
444
                            point_timestamps.append(current_datetime)
445
                            point_values.append(row[1])
446
447
                elif point['object_type'] == 'ENERGY_VALUE':
448
                    query = (" SELECT utc_date_time, actual_value "
449
                             " FROM tbl_energy_value "
450
                             " WHERE point_id = %s "
451
                             "       AND utc_date_time BETWEEN %s AND %s "
452
                             " ORDER BY utc_date_time ")
453
                    cursor_historical.execute(query, (point['id'],
454
                                                      reporting_start_datetime_utc,
455
                                                      reporting_end_datetime_utc))
456
                    rows = cursor_historical.fetchall()
457
458
                    if rows is not None and len(rows) > 0:
459
                        for row in rows:
460
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
461
                                                     timedelta(minutes=timezone_offset)
462
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
463
                            point_timestamps.append(current_datetime)
464
                            point_values.append(row[1])
465
                elif point['object_type'] == 'DIGITAL_VALUE':
466
                    query = (" SELECT utc_date_time, actual_value "
467
                             " FROM tbl_digital_value "
468
                             " WHERE point_id = %s "
469
                             "       AND utc_date_time BETWEEN %s AND %s "
470
                             " ORDER BY utc_date_time ")
471
                    cursor_historical.execute(query, (point['id'],
472
                                                      reporting_start_datetime_utc,
473
                                                      reporting_end_datetime_utc))
474
                    rows = cursor_historical.fetchall()
475
476
                    if rows is not None and len(rows) > 0:
477
                        for row in rows:
478
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
479
                                                     timedelta(minutes=timezone_offset)
480
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
481
                            point_timestamps.append(current_datetime)
482
                            point_values.append(row[1])
483
484
                parameters_data['names'].append(point['name'] + ' (' + point['units'] + ')')
485
                parameters_data['timestamps'].append(point_timestamps)
486
                parameters_data['values'].append(point_values)
487
488
        ################################################################################################################
489
        # Step 10: construct the report

myems-api/reports/metercomparison.py 2 locations

@@ 384-446 (lines=63) @@
381
        parameters_data2['names'] = list()
382
        parameters_data2['timestamps'] = list()
383
        parameters_data2['values'] = list()
384
        if not is_quick_mode:
385
            for point in point_list2:
386
                point_values = []
387
                point_timestamps = []
388
                if point['object_type'] == 'ANALOG_VALUE':
389
                    query = (" SELECT utc_date_time, actual_value "
390
                             " FROM tbl_analog_value "
391
                             " WHERE point_id = %s "
392
                             "       AND utc_date_time BETWEEN %s AND %s "
393
                             " ORDER BY utc_date_time ")
394
                    cursor_historical.execute(query, (point['id'],
395
                                                      reporting_start_datetime_utc,
396
                                                      reporting_end_datetime_utc))
397
                    rows = cursor_historical.fetchall()
398
399
                    if rows is not None and len(rows) > 0:
400
                        for row in rows:
401
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
402
                                                     timedelta(minutes=timezone_offset)
403
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
404
                            point_timestamps.append(current_datetime)
405
                            point_values.append(row[1])
406
407
                elif point['object_type'] == 'ENERGY_VALUE':
408
                    query = (" SELECT utc_date_time, actual_value "
409
                             " FROM tbl_energy_value "
410
                             " WHERE point_id = %s "
411
                             "       AND utc_date_time BETWEEN %s AND %s "
412
                             " ORDER BY utc_date_time ")
413
                    cursor_historical.execute(query, (point['id'],
414
                                                      reporting_start_datetime_utc,
415
                                                      reporting_end_datetime_utc))
416
                    rows = cursor_historical.fetchall()
417
418
                    if rows is not None and len(rows) > 0:
419
                        for row in rows:
420
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
421
                                                     timedelta(minutes=timezone_offset)
422
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
423
                            point_timestamps.append(current_datetime)
424
                            point_values.append(row[1])
425
                elif point['object_type'] == 'DIGITAL_VALUE':
426
                    query = (" SELECT utc_date_time, actual_value "
427
                             " FROM tbl_digital_value "
428
                             " WHERE point_id = %s "
429
                             "       AND utc_date_time BETWEEN %s AND %s "
430
                             " ORDER BY utc_date_time ")
431
                    cursor_historical.execute(query, (point['id'],
432
                                                      reporting_start_datetime_utc,
433
                                                      reporting_end_datetime_utc))
434
                    rows = cursor_historical.fetchall()
435
436
                    if rows is not None and len(rows) > 0:
437
                        for row in rows:
438
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
439
                                                     timedelta(minutes=timezone_offset)
440
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
441
                            point_timestamps.append(current_datetime)
442
                            point_values.append(row[1])
443
444
                parameters_data2['names'].append(point['name'] + ' (' + point['units'] + ')')
445
                parameters_data2['timestamps'].append(point_timestamps)
446
                parameters_data2['values'].append(point_values)
447
        ################################################################################################################
448
        # Step 8: construct the report
449
        ################################################################################################################
@@ 316-378 (lines=63) @@
313
        parameters_data1['timestamps'] = list()
314
        parameters_data1['values'] = list()
315
316
        if not is_quick_mode:
317
            for point in point_list1:
318
                point_values = []
319
                point_timestamps = []
320
                if point['object_type'] == 'ANALOG_VALUE':
321
                    query = (" SELECT utc_date_time, actual_value "
322
                             " FROM tbl_analog_value "
323
                             " WHERE point_id = %s "
324
                             "       AND utc_date_time BETWEEN %s AND %s "
325
                             " ORDER BY utc_date_time ")
326
                    cursor_historical.execute(query, (point['id'],
327
                                                      reporting_start_datetime_utc,
328
                                                      reporting_end_datetime_utc))
329
                    rows = cursor_historical.fetchall()
330
331
                    if rows is not None and len(rows) > 0:
332
                        for row in rows:
333
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
334
                                                     timedelta(minutes=timezone_offset)
335
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
336
                            point_timestamps.append(current_datetime)
337
                            point_values.append(row[1])
338
339
                elif point['object_type'] == 'ENERGY_VALUE':
340
                    query = (" SELECT utc_date_time, actual_value "
341
                             " FROM tbl_energy_value "
342
                             " WHERE point_id = %s "
343
                             "       AND utc_date_time BETWEEN %s AND %s "
344
                             " ORDER BY utc_date_time ")
345
                    cursor_historical.execute(query, (point['id'],
346
                                                      reporting_start_datetime_utc,
347
                                                      reporting_end_datetime_utc))
348
                    rows = cursor_historical.fetchall()
349
350
                    if rows is not None and len(rows) > 0:
351
                        for row in rows:
352
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
353
                                                     timedelta(minutes=timezone_offset)
354
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
355
                            point_timestamps.append(current_datetime)
356
                            point_values.append(row[1])
357
                elif point['object_type'] == 'DIGITAL_VALUE':
358
                    query = (" SELECT utc_date_time, actual_value "
359
                             " FROM tbl_digital_value "
360
                             " WHERE point_id = %s "
361
                             "       AND utc_date_time BETWEEN %s AND %s "
362
                             " ORDER BY utc_date_time ")
363
                    cursor_historical.execute(query, (point['id'],
364
                                                      reporting_start_datetime_utc,
365
                                                      reporting_end_datetime_utc))
366
                    rows = cursor_historical.fetchall()
367
368
                    if rows is not None and len(rows) > 0:
369
                        for row in rows:
370
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
371
                                                     timedelta(minutes=timezone_offset)
372
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
373
                            point_timestamps.append(current_datetime)
374
                            point_values.append(row[1])
375
376
                parameters_data1['names'].append(point['name'] + ' (' + point['units'] + ')')
377
                parameters_data1['timestamps'].append(point_timestamps)
378
                parameters_data1['values'].append(point_values)
379
380
        parameters_data2 = dict()
381
        parameters_data2['names'] = list()

myems-api/reports/meterenergy.py 1 location

@@ 342-404 (lines=63) @@
339
        ################################################################################################################
340
        # Step 7: query associated points data
341
        ################################################################################################################
342
        if not is_quick_mode:
343
            for point in point_list:
344
                point_values = []
345
                point_timestamps = []
346
                if point['object_type'] == 'ANALOG_VALUE':
347
                    query = (" SELECT utc_date_time, actual_value "
348
                             " FROM tbl_analog_value "
349
                             " WHERE point_id = %s "
350
                             "       AND utc_date_time BETWEEN %s AND %s "
351
                             " ORDER BY utc_date_time ")
352
                    cursor_historical.execute(query, (point['id'],
353
                                                      reporting_start_datetime_utc,
354
                                                      reporting_end_datetime_utc))
355
                    rows = cursor_historical.fetchall()
356
357
                    if rows is not None and len(rows) > 0:
358
                        for row in rows:
359
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
360
                                                     timedelta(minutes=timezone_offset)
361
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
362
                            point_timestamps.append(current_datetime)
363
                            point_values.append(row[1])
364
365
                elif point['object_type'] == 'ENERGY_VALUE':
366
                    query = (" SELECT utc_date_time, actual_value "
367
                             " FROM tbl_energy_value "
368
                             " WHERE point_id = %s "
369
                             "       AND utc_date_time BETWEEN %s AND %s "
370
                             " ORDER BY utc_date_time ")
371
                    cursor_historical.execute(query, (point['id'],
372
                                                      reporting_start_datetime_utc,
373
                                                      reporting_end_datetime_utc))
374
                    rows = cursor_historical.fetchall()
375
376
                    if rows is not None and len(rows) > 0:
377
                        for row in rows:
378
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
379
                                                     timedelta(minutes=timezone_offset)
380
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
381
                            point_timestamps.append(current_datetime)
382
                            point_values.append(row[1])
383
                elif point['object_type'] == 'DIGITAL_VALUE':
384
                    query = (" SELECT utc_date_time, actual_value "
385
                             " FROM tbl_digital_value "
386
                             " WHERE point_id = %s "
387
                             "       AND utc_date_time BETWEEN %s AND %s "
388
                             " ORDER BY utc_date_time ")
389
                    cursor_historical.execute(query, (point['id'],
390
                                                      reporting_start_datetime_utc,
391
                                                      reporting_end_datetime_utc))
392
                    rows = cursor_historical.fetchall()
393
394
                    if rows is not None and len(rows) > 0:
395
                        for row in rows:
396
                            current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
397
                                                     timedelta(minutes=timezone_offset)
398
                            current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
399
                            point_timestamps.append(current_datetime)
400
                            point_values.append(row[1])
401
402
                parameters_data['names'].append(point['name'] + ' (' + point['units'] + ')')
403
                parameters_data['timestamps'].append(point_timestamps)
404
                parameters_data['values'].append(point_values)
405
406
        ################################################################################################################
407
        # Step 8: construct the report