|
@@ 1193-1222 (lines=30) @@
|
| 1190 |
|
description='API.ENERGY_ITEM_IS_NOT_BELONG_TO_ENERGY_CATEGORY') |
| 1191 |
|
|
| 1192 |
|
for variable in new_values['expression']['variables']: |
| 1193 |
|
if variable['meter_type'].lower() == 'meter': |
| 1194 |
|
cursor.execute(" SELECT name " |
| 1195 |
|
" FROM tbl_meters " |
| 1196 |
|
" WHERE id = %s ", (variable['meter_id'],)) |
| 1197 |
|
if cursor.fetchone() is None: |
| 1198 |
|
cursor.close() |
| 1199 |
|
cnx.close() |
| 1200 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, |
| 1201 |
|
title='API.NOT_FOUND', |
| 1202 |
|
description='API.METER_OF_VARIABLE_NOT_FOUND') |
| 1203 |
|
elif variable['meter_type'].lower() == 'offline_meter': |
| 1204 |
|
cursor.execute(" SELECT name " |
| 1205 |
|
" FROM tbl_offline_meters " |
| 1206 |
|
" WHERE id = %s ", (variable['meter_id'],)) |
| 1207 |
|
if cursor.fetchone() is None: |
| 1208 |
|
cursor.close() |
| 1209 |
|
cnx.close() |
| 1210 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, |
| 1211 |
|
title='API.NOT_FOUND', |
| 1212 |
|
description='API.OFFLINE_METER_OF_VARIABLE_NOT_FOUND') |
| 1213 |
|
elif variable['meter_type'].lower() == 'virtual_meter': |
| 1214 |
|
cursor.execute(" SELECT name " |
| 1215 |
|
" FROM tbl_virtual_meters " |
| 1216 |
|
" WHERE id = %s ", (variable['meter_id'],)) |
| 1217 |
|
if cursor.fetchone() is None: |
| 1218 |
|
cursor.close() |
| 1219 |
|
cnx.close() |
| 1220 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, |
| 1221 |
|
title='API.NOT_FOUND', |
| 1222 |
|
description='API.VIRTUAL_METER_OF_VARIABLE_NOT_FOUND') |
| 1223 |
|
|
| 1224 |
|
add_values = (" INSERT INTO tbl_virtual_meters " |
| 1225 |
|
" (name, uuid, equation, energy_category_id, is_counted, " |
|
@@ 820-849 (lines=30) @@
|
| 817 |
|
description='API.ENERGY_ITEM_IS_NOT_BELONG_TO_ENERGY_CATEGORY') |
| 818 |
|
|
| 819 |
|
for variable in new_values['data']['expression']['variables']: |
| 820 |
|
if variable['meter_type'].lower() == 'meter': |
| 821 |
|
cursor.execute(" SELECT name " |
| 822 |
|
" FROM tbl_meters " |
| 823 |
|
" WHERE id = %s ", (variable['meter_id'],)) |
| 824 |
|
if cursor.fetchone() is None: |
| 825 |
|
cursor.close() |
| 826 |
|
cnx.close() |
| 827 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, |
| 828 |
|
title='API.NOT_FOUND', |
| 829 |
|
description='API.METER_OF_VARIABLE_NOT_FOUND') |
| 830 |
|
elif variable['meter_type'].lower() == 'offline_meter': |
| 831 |
|
cursor.execute(" SELECT name " |
| 832 |
|
" FROM tbl_offline_meters " |
| 833 |
|
" WHERE id = %s ", (variable['meter_id'],)) |
| 834 |
|
if cursor.fetchone() is None: |
| 835 |
|
cursor.close() |
| 836 |
|
cnx.close() |
| 837 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, |
| 838 |
|
title='API.NOT_FOUND', |
| 839 |
|
description='API.OFFLINE_METER_OF_VARIABLE_NOT_FOUND') |
| 840 |
|
elif variable['meter_type'].lower() == 'virtual_meter': |
| 841 |
|
cursor.execute(" SELECT name " |
| 842 |
|
" FROM tbl_virtual_meters " |
| 843 |
|
" WHERE id = %s ", (variable['meter_id'],)) |
| 844 |
|
if cursor.fetchone() is None: |
| 845 |
|
cursor.close() |
| 846 |
|
cnx.close() |
| 847 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, |
| 848 |
|
title='API.NOT_FOUND', |
| 849 |
|
description='API.VIRTUAL_METER_OF_VARIABLE_NOT_FOUND') |
| 850 |
|
try: |
| 851 |
|
update_row = (" UPDATE tbl_virtual_meters " |
| 852 |
|
" SET name = %s, equation = %s, energy_category_id = %s, is_counted = %s, " |
|
@@ 303-332 (lines=30) @@
|
| 300 |
|
description='API.ENERGY_ITEM_IS_NOT_BELONG_TO_ENERGY_CATEGORY') |
| 301 |
|
|
| 302 |
|
for variable in new_values['data']['expression']['variables']: |
| 303 |
|
if variable['meter_type'].lower() == 'meter': |
| 304 |
|
cursor.execute(" SELECT name " |
| 305 |
|
" FROM tbl_meters " |
| 306 |
|
" WHERE id = %s ", (variable['meter_id'],)) |
| 307 |
|
if cursor.fetchone() is None: |
| 308 |
|
cursor.close() |
| 309 |
|
cnx.close() |
| 310 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, |
| 311 |
|
title='API.NOT_FOUND', |
| 312 |
|
description='API.METER_OF_VARIABLE_NOT_FOUND') |
| 313 |
|
elif variable['meter_type'].lower() == 'offline_meter': |
| 314 |
|
cursor.execute(" SELECT name " |
| 315 |
|
" FROM tbl_offline_meters " |
| 316 |
|
" WHERE id = %s ", (variable['meter_id'],)) |
| 317 |
|
if cursor.fetchone() is None: |
| 318 |
|
cursor.close() |
| 319 |
|
cnx.close() |
| 320 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, |
| 321 |
|
title='API.NOT_FOUND', |
| 322 |
|
description='API.OFFLINE_METER_OF_VARIABLE_NOT_FOUND') |
| 323 |
|
elif variable['meter_type'].lower() == 'virtual_meter': |
| 324 |
|
cursor.execute(" SELECT name " |
| 325 |
|
" FROM tbl_virtual_meters " |
| 326 |
|
" WHERE id = %s ", (variable['meter_id'],)) |
| 327 |
|
if cursor.fetchone() is None: |
| 328 |
|
cursor.close() |
| 329 |
|
cnx.close() |
| 330 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, |
| 331 |
|
title='API.NOT_FOUND', |
| 332 |
|
description='API.VIRTUAL_METER_OF_VARIABLE_NOT_FOUND') |
| 333 |
|
|
| 334 |
|
add_values = (" INSERT INTO tbl_virtual_meters " |
| 335 |
|
" (name, uuid, equation, energy_category_id, is_counted, " |