|
@@ 885-938 (lines=54) @@
|
| 882 |
|
resp.status = falcon.HTTP_200 |
| 883 |
|
_ = id_ |
| 884 |
|
|
| 885 |
|
@staticmethod |
| 886 |
|
def on_get(req, resp, id_): |
| 887 |
|
"""Handles GET requests""" |
| 888 |
|
admin_control(req) |
| 889 |
|
if not id_.isdigit() or int(id_) <= 0: |
| 890 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 891 |
|
description='API.INVALID_POINT_ID') |
| 892 |
|
|
| 893 |
|
cnx = mysql.connector.connect(**config.myems_system_db) |
| 894 |
|
cursor = cnx.cursor() |
| 895 |
|
|
| 896 |
|
query = (" SELECT id, name, uuid " |
| 897 |
|
" FROM tbl_data_sources ") |
| 898 |
|
cursor.execute(query) |
| 899 |
|
rows_data_sources = cursor.fetchall() |
| 900 |
|
|
| 901 |
|
data_source_dict = dict() |
| 902 |
|
if rows_data_sources is not None and len(rows_data_sources) > 0: |
| 903 |
|
for row in rows_data_sources: |
| 904 |
|
data_source_dict[row[0]] = {"id": row[0], |
| 905 |
|
"name": row[1], |
| 906 |
|
"uuid": row[2]} |
| 907 |
|
|
| 908 |
|
query = (" SELECT id, name, data_source_id, object_type, units, " |
| 909 |
|
" high_limit, low_limit, higher_limit, lower_limit, ratio, offset_constant, " |
| 910 |
|
" is_trend, is_virtual, address, description, faults, definitions " |
| 911 |
|
" FROM tbl_points " |
| 912 |
|
" WHERE id = %s ") |
| 913 |
|
cursor.execute(query, (id_,)) |
| 914 |
|
row = cursor.fetchone() |
| 915 |
|
cursor.close() |
| 916 |
|
cnx.close() |
| 917 |
|
if row is None: |
| 918 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
| 919 |
|
description='API.POINT_NOT_FOUND') |
| 920 |
|
|
| 921 |
|
result = {"id": row[0], |
| 922 |
|
"name": row[1], |
| 923 |
|
"data_source": data_source_dict.get(row[2], None), |
| 924 |
|
"object_type": row[3], |
| 925 |
|
"units": row[4], |
| 926 |
|
"high_limit": row[5], |
| 927 |
|
"low_limit": row[6], |
| 928 |
|
"higher_limit": row[7], |
| 929 |
|
"lower_limit": row[8], |
| 930 |
|
"ratio": Decimal(row[9]), |
| 931 |
|
"offset_constant": Decimal(row[10]), |
| 932 |
|
"is_trend": bool(row[11]), |
| 933 |
|
"is_virtual": bool(row[12]), |
| 934 |
|
"address": row[13], |
| 935 |
|
"description": row[14], |
| 936 |
|
"faults": row[15], |
| 937 |
|
"definitions": row[16]} |
| 938 |
|
resp.text = json.dumps(result) |
| 939 |
|
|
| 940 |
|
|
| 941 |
|
class PointImport: |
|
@@ 413-466 (lines=54) @@
|
| 410 |
|
resp.status = falcon.HTTP_200 |
| 411 |
|
_ = id_ |
| 412 |
|
|
| 413 |
|
@staticmethod |
| 414 |
|
def on_get(req, resp, id_): |
| 415 |
|
"""Handles GET requests""" |
| 416 |
|
admin_control(req) |
| 417 |
|
if not id_.isdigit() or int(id_) <= 0: |
| 418 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 419 |
|
description='API.INVALID_POINT_ID') |
| 420 |
|
|
| 421 |
|
cnx = mysql.connector.connect(**config.myems_system_db) |
| 422 |
|
cursor = cnx.cursor() |
| 423 |
|
|
| 424 |
|
query = (" SELECT id, name, uuid " |
| 425 |
|
" FROM tbl_data_sources ") |
| 426 |
|
cursor.execute(query) |
| 427 |
|
rows_data_sources = cursor.fetchall() |
| 428 |
|
|
| 429 |
|
data_source_dict = dict() |
| 430 |
|
if rows_data_sources is not None and len(rows_data_sources) > 0: |
| 431 |
|
for row in rows_data_sources: |
| 432 |
|
data_source_dict[row[0]] = {"id": row[0], |
| 433 |
|
"name": row[1], |
| 434 |
|
"uuid": row[2]} |
| 435 |
|
|
| 436 |
|
query = (" SELECT id, name, data_source_id, object_type, units, " |
| 437 |
|
" high_limit, low_limit, higher_limit, lower_limit, ratio, offset_constant, " |
| 438 |
|
" is_trend, is_virtual, address, description, faults, definitions " |
| 439 |
|
" FROM tbl_points " |
| 440 |
|
" WHERE id = %s ") |
| 441 |
|
cursor.execute(query, (id_,)) |
| 442 |
|
row = cursor.fetchone() |
| 443 |
|
cursor.close() |
| 444 |
|
cnx.close() |
| 445 |
|
if row is None: |
| 446 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
| 447 |
|
description='API.POINT_NOT_FOUND') |
| 448 |
|
|
| 449 |
|
result = {"id": row[0], |
| 450 |
|
"name": row[1], |
| 451 |
|
"data_source": data_source_dict.get(row[2], None), |
| 452 |
|
"object_type": row[3], |
| 453 |
|
"units": row[4], |
| 454 |
|
"high_limit": row[5], |
| 455 |
|
"low_limit": row[6], |
| 456 |
|
"higher_limit": row[7], |
| 457 |
|
"lower_limit": row[8], |
| 458 |
|
"ratio": Decimal(row[9]), |
| 459 |
|
"offset_constant": Decimal(row[10]), |
| 460 |
|
"is_trend": bool(row[11]), |
| 461 |
|
"is_virtual": bool(row[12]), |
| 462 |
|
"address": row[13], |
| 463 |
|
"description": row[14], |
| 464 |
|
"faults": row[15], |
| 465 |
|
"definitions": row[16]} |
| 466 |
|
resp.text = json.dumps(result) |
| 467 |
|
|
| 468 |
|
@staticmethod |
| 469 |
|
@user_logger |