Code Duplication    Length = 26-26 lines in 2 locations

myems-api/core/distributionsystem.py 2 locations

@@ 675-700 (lines=26) @@
672
            rows = cursor.fetchall()
673
674
            result = list()
675
            if rows is not None and len(rows) > 0:
676
                for row in rows:
677
                    circuit_result = {"id": row[0], "name": row[1], "uuid": row[2],
678
                                      "distribution_room": row[3], "switchgear": row[4],
679
                                      "peak_load": row[5], "peak_current": row[6],
680
                                      "customers": row[7], "meters": row[8],
681
                                      "points": None}
682
                    query = (" SELECT p.id AS point_id, p.name AS point_name, p.address AS point_address, "
683
                             "        dc.id AS distribution_circuit_id, dc.name AS distribution_circuit_name, "
684
                             "        dc.uuid AS distribution_circuit_uuid "
685
                             " FROM tbl_points p, tbl_distribution_circuits_points dcp, tbl_distribution_circuits dc "
686
                             " WHERE dcp.distribution_circuit_id = %s AND p.id = dcp.point_id "
687
                             "       AND dcp.distribution_circuit_id = dc.id "
688
                             " ORDER BY p.name ")
689
                    cursor.execute(query, (circuit_result['id'],))
690
                    rows = cursor.fetchall()
691
692
                    points = list()
693
                    if rows is not None and len(rows) > 0:
694
                        for point_row in rows:
695
                            point_result = {"id": point_row[0], "name": point_row[1], "address": point_row[2]}
696
                            points.append(point_result)
697
                        circuit_result['points'] = points
698
699
                    result.append(circuit_result)
700
                meta_result['circuits'] = result
701
            timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6])
702
            if config.utc_offset[0] == '-':
703
                timezone_offset = -timezone_offset
@@ 465-490 (lines=26) @@
462
            rows = cursor.fetchall()
463
464
            result = list()
465
            if rows is not None and len(rows) > 0:
466
                for row in rows:
467
                    circuit_result = {"id": row[0], "name": row[1], "uuid": row[2],
468
                                      "distribution_room": row[3], "switchgear": row[4],
469
                                      "peak_load": row[5], "peak_current": row[6],
470
                                      "customers": row[7], "meters": row[8],
471
                                      "points": None}
472
                    query = (" SELECT p.id AS point_id, p.name AS point_name, "
473
                             "        dc.id AS distribution_circuit_id, dc.name AS distribution_circuit_name, "
474
                             "        dc.uuid AS distribution_circuit_uuid "
475
                             " FROM tbl_points p, tbl_distribution_circuits_points dcp, tbl_distribution_circuits dc "
476
                             " WHERE dcp.distribution_circuit_id = %s AND p.id = dcp.point_id "
477
                             "       AND dcp.distribution_circuit_id = dc.id "
478
                             " ORDER BY p.name ")
479
                    cursor.execute(query, (circuit_result['id'],))
480
                    rows = cursor.fetchall()
481
482
                    points = list()
483
                    if rows is not None and len(rows) > 0:
484
                        for point_row in rows:
485
                            point_result = {"id": point_row[0], "name": point_row[1]}
486
                            points.append(point_result)
487
                        circuit_result['points'] = points
488
489
                    result.append(circuit_result)
490
                meta_result['circuits'] = result
491
492
        cursor.close()
493
        cnx.close()