@@ 16-58 (lines=43) @@ | ||
13 | def on_options(req, resp): |
|
14 | resp.status = falcon.HTTP_200 |
|
15 | ||
16 | @staticmethod |
|
17 | def on_get(req, resp): |
|
18 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
19 | cursor = cnx.cursor(dictionary=True) |
|
20 | ||
21 | query = (" SELECT id, name, uuid " |
|
22 | " FROM tbl_data_sources ") |
|
23 | cursor.execute(query) |
|
24 | rows_data_sources = cursor.fetchall() |
|
25 | ||
26 | data_source_dict = dict() |
|
27 | if rows_data_sources is not None and len(rows_data_sources) > 0: |
|
28 | for row in rows_data_sources: |
|
29 | data_source_dict[row['id']] = {"id": row['id'], |
|
30 | "name": row['name'], |
|
31 | "uuid": row['uuid']} |
|
32 | ||
33 | query = (" SELECT id, name, data_source_id, object_type, units, " |
|
34 | " high_limit, low_limit, ratio, is_trend, address, description " |
|
35 | " FROM tbl_points ") |
|
36 | cursor.execute(query) |
|
37 | rows = cursor.fetchall() |
|
38 | cursor.close() |
|
39 | cnx.disconnect() |
|
40 | ||
41 | result = list() |
|
42 | if rows is not None and len(rows) > 0: |
|
43 | for row in rows: |
|
44 | data_source = data_source_dict.get(row['data_source_id'], None) |
|
45 | meta_result = {"id": row['id'], |
|
46 | "name": row['name'], |
|
47 | "data_source": data_source, |
|
48 | "object_type": row['object_type'], |
|
49 | "units": row['units'], |
|
50 | "high_limit": row['high_limit'], |
|
51 | "low_limit": row['low_limit'], |
|
52 | "ratio": float(row['ratio']), |
|
53 | "is_trend": row['is_trend'], |
|
54 | "address": row['address'], |
|
55 | "description": row['description']} |
|
56 | result.append(meta_result) |
|
57 | ||
58 | resp.body = json.dumps(result) |
|
59 | ||
60 | @staticmethod |
|
61 | def on_post(req, resp): |
@@ 17-58 (lines=42) @@ | ||
14 | def on_options(req, resp): |
|
15 | resp.status = falcon.HTTP_200 |
|
16 | ||
17 | @staticmethod |
|
18 | def on_get(req, resp): |
|
19 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
20 | cursor = cnx.cursor(dictionary=True) |
|
21 | ||
22 | query = (" SELECT id, name, uuid " |
|
23 | " FROM tbl_distribution_systems ") |
|
24 | cursor.execute(query) |
|
25 | rows_distribution_systems = cursor.fetchall() |
|
26 | ||
27 | distribution_system_dict = dict() |
|
28 | if rows_distribution_systems is not None and len(rows_distribution_systems) > 0: |
|
29 | for row in rows_distribution_systems: |
|
30 | distribution_system_dict[row['id']] = {"id": row['id'], |
|
31 | "name": row['name'], |
|
32 | "uuid": row['uuid']} |
|
33 | query = (" SELECT id, name, uuid, distribution_system_id, " |
|
34 | " distribution_room, switchgear, peak_load, peak_current, customers, meters " |
|
35 | " FROM tbl_distribution_circuits " |
|
36 | " ORDER BY id ") |
|
37 | cursor.execute(query) |
|
38 | rows_distribution_circuits = cursor.fetchall() |
|
39 | ||
40 | result = list() |
|
41 | if rows_distribution_circuits is not None and len(rows_distribution_circuits) > 0: |
|
42 | for row in rows_distribution_circuits: |
|
43 | distribution_system = distribution_system_dict.get(row['distribution_system_id']) |
|
44 | meta_result = {"id": row['id'], |
|
45 | "name": row['name'], |
|
46 | "uuid": row['uuid'], |
|
47 | "distribution_system": distribution_system, |
|
48 | "distribution_room": row['distribution_room'], |
|
49 | "switchgear": row['switchgear'], |
|
50 | "peak_load": row['peak_load'], |
|
51 | "peak_current": row['peak_current'], |
|
52 | "customers": row['customers'], |
|
53 | "meters": row['meters']} |
|
54 | result.append(meta_result) |
|
55 | ||
56 | cursor.close() |
|
57 | cnx.disconnect() |
|
58 | resp.body = json.dumps(result) |
|
59 | ||
60 | @staticmethod |
|
61 | def on_post(req, resp): |