@@ 608-652 (lines=45) @@ | ||
605 | resp.status = falcon.HTTP_200 |
|
606 | ||
607 | ||
608 | class PhotovoltaicPowerStationDataSourcePointCollection: |
|
609 | def __init__(self): |
|
610 | """Initializes""" |
|
611 | pass |
|
612 | ||
613 | @staticmethod |
|
614 | def on_options(req, resp, id_): |
|
615 | _ = req |
|
616 | resp.status = falcon.HTTP_200 |
|
617 | _ = id_ |
|
618 | ||
619 | @staticmethod |
|
620 | def on_get(req, resp, id_): |
|
621 | if 'API-KEY' not in req.headers or \ |
|
622 | not isinstance(req.headers['API-KEY'], str) or \ |
|
623 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
624 | access_control(req) |
|
625 | else: |
|
626 | api_key_control(req) |
|
627 | if not id_.isdigit() or int(id_) <= 0: |
|
628 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
629 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
630 | ||
631 | cnx = mysql.connector.connect(** config.myems_system_db) |
|
632 | cursor = cnx.cursor() |
|
633 | ||
634 | query = (" SELECT p.id, p.name " |
|
635 | " FROM tbl_points p, tbl_photovoltaic_power_stations_data_sources ppds, tbl_data_sources ds " |
|
636 | " WHERE ppds.photovoltaic_power_station_id = %s " |
|
637 | " AND ppds.data_source_id = ds.id " |
|
638 | " AND p.data_source_id = ds.id " |
|
639 | " ORDER BY p.id ") |
|
640 | cursor.execute(query, (id_,)) |
|
641 | rows = cursor.fetchall() |
|
642 | ||
643 | result = list() |
|
644 | if rows is not None and len(rows) > 0: |
|
645 | for row in rows: |
|
646 | meta_result = {"id": row[0], "name": row[1]} |
|
647 | result.append(meta_result) |
|
648 | ||
649 | cursor.close() |
|
650 | cnx.close() |
|
651 | ||
652 | resp.text = json.dumps(result) |
|
653 | ||
654 | class PhotovoltaicPowerStationExport: |
|
655 | def __init__(self): |
@@ 924-967 (lines=44) @@ | ||
921 | resp.status = falcon.HTTP_204 |
|
922 | ||
923 | ||
924 | class EnergyStoragePowerStationDataSourcePointCollection: |
|
925 | def __init__(self): |
|
926 | """Initializes""" |
|
927 | pass |
|
928 | ||
929 | @staticmethod |
|
930 | def on_options(req, resp, id_,): |
|
931 | _ = req |
|
932 | resp.status = falcon.HTTP_200 |
|
933 | _ = id_ |
|
934 | ||
935 | @staticmethod |
|
936 | def on_get(req, resp, id_,): |
|
937 | if 'API-KEY' not in req.headers or \ |
|
938 | not isinstance(req.headers['API-KEY'], str) or \ |
|
939 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
940 | access_control(req) |
|
941 | else: |
|
942 | api_key_control(req) |
|
943 | if not id_.isdigit() or int(id_) <= 0: |
|
944 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
945 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
946 | ||
947 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
948 | cursor = cnx.cursor() |
|
949 | ||
950 | query = (" SELECT p.id, p.name " |
|
951 | " FROM tbl_points p, tbl_energy_storage_power_stations_containers espsc, " |
|
952 | " tbl_energy_storage_containers_data_sources ecds, tbl_data_sources ds " |
|
953 | " WHERE espsc.energy_storage_power_station_id = %s " |
|
954 | " AND espsc.energy_storage_container_id = ecds.energy_storage_container_id " |
|
955 | " AND ecds.data_source_id = ds.id " |
|
956 | " AND p.data_source_id = ds.id " |
|
957 | " ORDER BY p.id ") |
|
958 | cursor.execute(query, (id_,)) |
|
959 | rows = cursor.fetchall() |
|
960 | ||
961 | result = list() |
|
962 | if rows is not None and len(rows) > 0: |
|
963 | for row in rows: |
|
964 | meta_result = {"id": row[0], "name": row[1]} |
|
965 | result.append(meta_result) |
|
966 | ||
967 | resp.text = json.dumps(result) |
|
968 | ||
969 | ||
970 | class EnergyStoragePowerStationUserCollection: |
@@ 1641-1682 (lines=42) @@ | ||
1638 | resp.status = falcon.HTTP_204 |
|
1639 | ||
1640 | ||
1641 | class EnergyStorageContainerDataSourcePointCollection: |
|
1642 | def __init__(self): |
|
1643 | """Initializes""" |
|
1644 | pass |
|
1645 | ||
1646 | @staticmethod |
|
1647 | def on_options(req, resp, id_,): |
|
1648 | _ = req |
|
1649 | resp.status = falcon.HTTP_200 |
|
1650 | _ = id_ |
|
1651 | ||
1652 | @staticmethod |
|
1653 | def on_get(req, resp, id_,): |
|
1654 | if 'API-KEY' not in req.headers or \ |
|
1655 | not isinstance(req.headers['API-KEY'], str) or \ |
|
1656 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
1657 | access_control(req) |
|
1658 | else: |
|
1659 | api_key_control(req) |
|
1660 | if not id_.isdigit() or int(id_) <= 0: |
|
1661 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1662 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
1663 | ||
1664 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1665 | cursor = cnx.cursor() |
|
1666 | ||
1667 | query = (" SELECT p.id, p.name " |
|
1668 | " FROM tbl_points p, tbl_energy_storage_containers_data_sources ecds, tbl_data_sources ds " |
|
1669 | " WHERE ecds.energy_storage_container_id = %s " |
|
1670 | " AND ecds.data_source_id = ds.id " |
|
1671 | " AND p.data_source_id = ds.id " |
|
1672 | " ORDER BY p.id ") |
|
1673 | cursor.execute(query, (id_,)) |
|
1674 | rows = cursor.fetchall() |
|
1675 | ||
1676 | result = list() |
|
1677 | if rows is not None and len(rows) > 0: |
|
1678 | for row in rows: |
|
1679 | meta_result = {"id": row[0], "name": row[1]} |
|
1680 | result.append(meta_result) |
|
1681 | ||
1682 | resp.text = json.dumps(result) |
|
1683 | ||
1684 | ||
1685 | class EnergyStorageContainerDCDCCollection: |