@@ 1052-1134 (lines=83) @@ | ||
1049 | resp.status = falcon.HTTP_204 |
|
1050 | ||
1051 | ||
1052 | class EnergyStoragePowerStationExport: |
|
1053 | def __init__(self): |
|
1054 | """"Initializes Class""" |
|
1055 | pass |
|
1056 | ||
1057 | @staticmethod |
|
1058 | def on_options(req, resp, id_): |
|
1059 | resp.status = falcon.HTTP_200 |
|
1060 | ||
1061 | @staticmethod |
|
1062 | def on_get(req, resp, id_): |
|
1063 | access_control(req) |
|
1064 | if not id_.isdigit() or int(id_) <= 0: |
|
1065 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1066 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
1067 | ||
1068 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1069 | cursor = cnx.cursor() |
|
1070 | ||
1071 | query = (" SELECT id, name, uuid " |
|
1072 | " FROM tbl_contacts ") |
|
1073 | cursor.execute(query) |
|
1074 | rows_contacts = cursor.fetchall() |
|
1075 | ||
1076 | contact_dict = dict() |
|
1077 | if rows_contacts is not None and len(rows_contacts) > 0: |
|
1078 | for row in rows_contacts: |
|
1079 | contact_dict[row[0]] = {"id": row[0], |
|
1080 | "name": row[1], |
|
1081 | "uuid": row[2]} |
|
1082 | ||
1083 | query = (" SELECT id, name, uuid " |
|
1084 | " FROM tbl_cost_centers ") |
|
1085 | cursor.execute(query) |
|
1086 | rows_cost_centers = cursor.fetchall() |
|
1087 | ||
1088 | cost_center_dict = dict() |
|
1089 | if rows_cost_centers is not None and len(rows_cost_centers) > 0: |
|
1090 | for row in rows_cost_centers: |
|
1091 | cost_center_dict[row[0]] = {"id": row[0], |
|
1092 | "name": row[1], |
|
1093 | "uuid": row[2]} |
|
1094 | ||
1095 | query = (" SELECT id, name, uuid " |
|
1096 | " FROM tbl_svgs ") |
|
1097 | cursor.execute(query) |
|
1098 | rows_svgs = cursor.fetchall() |
|
1099 | ||
1100 | svg_dict = dict() |
|
1101 | if rows_svgs is not None and len(rows_svgs) > 0: |
|
1102 | for row in rows_svgs: |
|
1103 | svg_dict[row[0]] = {"id": row[0], |
|
1104 | "name": row[1], |
|
1105 | "uuid": row[2]} |
|
1106 | ||
1107 | query = (" SELECT id, name, uuid, " |
|
1108 | " address, latitude, longitude, rated_capacity, rated_power, " |
|
1109 | " contact_id, cost_center_id, svg_id, is_cost_data_displayed, description " |
|
1110 | " FROM tbl_energy_storage_power_stations " |
|
1111 | " WHERE id = %s ") |
|
1112 | cursor.execute(query, (id_,)) |
|
1113 | row = cursor.fetchone() |
|
1114 | cursor.close() |
|
1115 | cnx.close() |
|
1116 | ||
1117 | if row is None: |
|
1118 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1119 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
1120 | else: |
|
1121 | meta_result = {"name": row[1], |
|
1122 | "uuid": row[2], |
|
1123 | "address": row[3], |
|
1124 | "latitude": row[4], |
|
1125 | "longitude": row[5], |
|
1126 | "rated_capacity": row[6], |
|
1127 | "rated_power": row[7], |
|
1128 | "contact": contact_dict.get(row[8], None), |
|
1129 | "cost_center": cost_center_dict.get(row[9], None), |
|
1130 | "svg": svg_dict.get(row[10], None), |
|
1131 | "is_cost_data_displayed": bool(row[11]), |
|
1132 | "description": row[12]} |
|
1133 | ||
1134 | resp.text = json.dumps(meta_result) |
|
1135 | ||
1136 | ||
1137 | class EnergyStoragePowerStationImport: |
@@ 513-594 (lines=82) @@ | ||
510 | resp.status = falcon.HTTP_200 |
|
511 | ||
512 | ||
513 | class WindFarmExport: |
|
514 | def __init__(self): |
|
515 | """"Initializes WindFarmItem""" |
|
516 | pass |
|
517 | ||
518 | @staticmethod |
|
519 | def on_options(req, resp, id_): |
|
520 | resp.status = falcon.HTTP_200 |
|
521 | ||
522 | @staticmethod |
|
523 | def on_get(req, resp, id_): |
|
524 | access_control(req) |
|
525 | if not id_.isdigit() or int(id_) <= 0: |
|
526 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
527 | description='API.INVALID_WIND_FARM_ID') |
|
528 | ||
529 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
530 | cursor = cnx.cursor() |
|
531 | ||
532 | query = (" SELECT id, name, uuid " |
|
533 | " FROM tbl_contacts ") |
|
534 | cursor.execute(query) |
|
535 | rows_contacts = cursor.fetchall() |
|
536 | ||
537 | contact_dict = dict() |
|
538 | if rows_contacts is not None and len(rows_contacts) > 0: |
|
539 | for row in rows_contacts: |
|
540 | contact_dict[row[0]] = {"id": row[0], |
|
541 | "name": row[1], |
|
542 | "uuid": row[2]} |
|
543 | ||
544 | query = (" SELECT id, name, uuid " |
|
545 | " FROM tbl_cost_centers ") |
|
546 | cursor.execute(query) |
|
547 | rows_cost_centers = cursor.fetchall() |
|
548 | ||
549 | cost_center_dict = dict() |
|
550 | if rows_cost_centers is not None and len(rows_cost_centers) > 0: |
|
551 | for row in rows_cost_centers: |
|
552 | cost_center_dict[row[0]] = {"id": row[0], |
|
553 | "name": row[1], |
|
554 | "uuid": row[2]} |
|
555 | ||
556 | query = (" SELECT id, name, uuid " |
|
557 | " FROM tbl_svgs ") |
|
558 | cursor.execute(query) |
|
559 | rows_svgs = cursor.fetchall() |
|
560 | ||
561 | svg_dict = dict() |
|
562 | if rows_svgs is not None and len(rows_svgs) > 0: |
|
563 | for row in rows_svgs: |
|
564 | svg_dict[row[0]] = {"id": row[0], |
|
565 | "name": row[1], |
|
566 | "uuid": row[2]} |
|
567 | ||
568 | query = (" SELECT id, name, uuid, " |
|
569 | " address, latitude, longitude, rated_power, " |
|
570 | " contact_id, cost_center_id, svg_id, description " |
|
571 | " FROM tbl_wind_farms " |
|
572 | " WHERE id = %s ") |
|
573 | cursor.execute(query, (id_,)) |
|
574 | row = cursor.fetchone() |
|
575 | cursor.close() |
|
576 | cnx.close() |
|
577 | ||
578 | if row is None: |
|
579 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
580 | description='API.WIND_FARM_NOT_FOUND') |
|
581 | else: |
|
582 | meta_result = {"id": row[0], |
|
583 | "name": row[1], |
|
584 | "uuid": row[2], |
|
585 | "address": row[3], |
|
586 | "latitude": row[4], |
|
587 | "longitude": row[5], |
|
588 | "rated_power": row[6], |
|
589 | "contact": contact_dict.get(row[7], None), |
|
590 | "cost_center": cost_center_dict.get(row[8], None), |
|
591 | "svg": svg_dict.get(row[9], None), |
|
592 | "description": row[10]} |
|
593 | ||
594 | resp.text = json.dumps(meta_result) |
|
595 | ||
596 | ||
597 | class WindFarmImport: |