added alternative parameter uuid
parent
eb6bd078dd
commit
98385b8900
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -36,6 +37,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
combined_equipment_id = req.params.get('combinedequipmentid')
|
combined_equipment_id = req.params.get('combinedequipmentid')
|
||||||
|
combined_equipment_uuid = req.params.get('combinedequipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -45,17 +47,27 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if combined_equipment_id is None:
|
if combined_equipment_id is None and combined_equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
else:
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
combined_equipment_id = str.strip(combined_equipment_id)
|
combined_equipment_id = str.strip(combined_equipment_id)
|
||||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if combined_equipment_uuid is not None:
|
||||||
|
combined_equipment_uuid = str.strip(combined_equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(combined_equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_COMBINED_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
else:
|
else:
|
||||||
|
@ -136,10 +148,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (combined_equipment_id,))
|
" WHERE id = %s ", (combined_equipment_id,))
|
||||||
row_combined_equipment = cursor_system.fetchone()
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
|
elif combined_equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_combined_equipments "
|
||||||
|
" WHERE uuid = %s ", (combined_equipment_uuid,))
|
||||||
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
if row_combined_equipment is None:
|
if row_combined_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -37,6 +38,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
combined_equipment_id = req.params.get('combinedequipmentid')
|
combined_equipment_id = req.params.get('combinedequipmentid')
|
||||||
|
combined_equipment_uuid = req.params.get('combinedequipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -47,15 +49,27 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if combined_equipment_id is None:
|
if combined_equipment_id is None and combined_equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
else:
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
combined_equipment_id = str.strip(combined_equipment_id)
|
combined_equipment_id = str.strip(combined_equipment_id)
|
||||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if combined_equipment_uuid is not None:
|
||||||
|
combined_equipment_uuid = str.strip(combined_equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(combined_equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_COMBINED_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
else:
|
else:
|
||||||
|
@ -142,10 +156,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (combined_equipment_id,))
|
" WHERE id = %s ", (combined_equipment_id,))
|
||||||
row_combined_equipment = cursor_system.fetchone()
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
|
elif combined_equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_combined_equipments "
|
||||||
|
" WHERE uuid = %s ", (combined_equipment_uuid,))
|
||||||
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
if row_combined_equipment is None:
|
if row_combined_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -36,6 +37,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
combined_equipment_id = req.params.get('combinedequipmentid')
|
combined_equipment_id = req.params.get('combinedequipmentid')
|
||||||
|
combined_equipment_uuid = req.params.get('combinedequipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -45,17 +47,27 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if combined_equipment_id is None:
|
if combined_equipment_id is None and combined_equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
else:
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
combined_equipment_id = str.strip(combined_equipment_id)
|
combined_equipment_id = str.strip(combined_equipment_id)
|
||||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if combined_equipment_uuid is not None:
|
||||||
|
combined_equipment_uuid = str.strip(combined_equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(combined_equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_COMBINED_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
else:
|
else:
|
||||||
|
@ -136,10 +148,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (combined_equipment_id,))
|
" WHERE id = %s ", (combined_equipment_id,))
|
||||||
row_combined_equipment = cursor_system.fetchone()
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
|
elif combined_equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_combined_equipments "
|
||||||
|
" WHERE uuid = %s ", (combined_equipment_uuid,))
|
||||||
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
if row_combined_equipment is None:
|
if row_combined_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -36,6 +37,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
combined_equipment_id = req.params.get('combinedequipmentid')
|
combined_equipment_id = req.params.get('combinedequipmentid')
|
||||||
|
combined_equipment_uuid = req.params.get('combinedequipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -45,17 +47,27 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if combined_equipment_id is None:
|
if combined_equipment_id is None and combined_equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
else:
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
combined_equipment_id = str.strip(combined_equipment_id)
|
combined_equipment_id = str.strip(combined_equipment_id)
|
||||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if combined_equipment_uuid is not None:
|
||||||
|
combined_equipment_uuid = str.strip(combined_equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(combined_equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_COMBINED_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
else:
|
else:
|
||||||
|
@ -136,10 +148,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (combined_equipment_id,))
|
" WHERE id = %s ", (combined_equipment_id,))
|
||||||
row_combined_equipment = cursor_system.fetchone()
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
|
elif combined_equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_combined_equipments "
|
||||||
|
" WHERE uuid = %s ", (combined_equipment_uuid,))
|
||||||
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
if row_combined_equipment is None:
|
if row_combined_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -36,6 +37,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
combined_equipment_id = req.params.get('combinedequipmentid')
|
combined_equipment_id = req.params.get('combinedequipmentid')
|
||||||
|
combined_equipment_uuid = req.params.get('combinedequipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -45,17 +47,27 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if combined_equipment_id is None:
|
if combined_equipment_id is None and combined_equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
else:
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
combined_equipment_id = str.strip(combined_equipment_id)
|
combined_equipment_id = str.strip(combined_equipment_id)
|
||||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if combined_equipment_uuid is not None:
|
||||||
|
combined_equipment_uuid = str.strip(combined_equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(combined_equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_COMBINED_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
else:
|
else:
|
||||||
|
@ -136,10 +148,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (combined_equipment_id,))
|
" WHERE id = %s ", (combined_equipment_id,))
|
||||||
row_combined_equipment = cursor_system.fetchone()
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
|
elif combined_equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_combined_equipments "
|
||||||
|
" WHERE uuid = %s ", (combined_equipment_uuid,))
|
||||||
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
if row_combined_equipment is None:
|
if row_combined_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -36,6 +37,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
combined_equipment_id = req.params.get('combinedequipmentid')
|
combined_equipment_id = req.params.get('combinedequipmentid')
|
||||||
|
combined_equipment_uuid = req.params.get('combinedequipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -45,17 +47,27 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if combined_equipment_id is None:
|
if combined_equipment_id is None and combined_equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
else:
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
combined_equipment_id = str.strip(combined_equipment_id)
|
combined_equipment_id = str.strip(combined_equipment_id)
|
||||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if combined_equipment_uuid is not None:
|
||||||
|
combined_equipment_uuid = str.strip(combined_equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(combined_equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_COMBINED_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
else:
|
else:
|
||||||
|
@ -136,10 +148,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (combined_equipment_id,))
|
" WHERE id = %s ", (combined_equipment_id,))
|
||||||
row_combined_equipment = cursor_system.fetchone()
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
|
elif combined_equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_combined_equipments "
|
||||||
|
" WHERE uuid = %s ", (combined_equipment_uuid,))
|
||||||
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
if row_combined_equipment is None:
|
if row_combined_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -36,6 +37,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
combined_equipment_id = req.params.get('combinedequipmentid')
|
combined_equipment_id = req.params.get('combinedequipmentid')
|
||||||
|
combined_equipment_uuid = req.params.get('combinedequipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -45,17 +47,27 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if combined_equipment_id is None:
|
if combined_equipment_id is None and combined_equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
else:
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
combined_equipment_id = str.strip(combined_equipment_id)
|
combined_equipment_id = str.strip(combined_equipment_id)
|
||||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if combined_equipment_uuid is not None:
|
||||||
|
combined_equipment_uuid = str.strip(combined_equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(combined_equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_COMBINED_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
else:
|
else:
|
||||||
|
@ -136,10 +148,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (combined_equipment_id,))
|
" WHERE id = %s ", (combined_equipment_id,))
|
||||||
row_combined_equipment = cursor_system.fetchone()
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
|
elif combined_equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_combined_equipments "
|
||||||
|
" WHERE uuid = %s ", (combined_equipment_uuid,))
|
||||||
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
if row_combined_equipment is None:
|
if row_combined_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -36,6 +37,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
combined_equipment_id = req.params.get('combinedequipmentid')
|
combined_equipment_id = req.params.get('combinedequipmentid')
|
||||||
|
combined_equipment_uuid = req.params.get('combinedequipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -45,17 +47,27 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if combined_equipment_id is None:
|
if combined_equipment_id is None and combined_equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
else:
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
combined_equipment_id = str.strip(combined_equipment_id)
|
combined_equipment_id = str.strip(combined_equipment_id)
|
||||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if combined_equipment_uuid is not None:
|
||||||
|
combined_equipment_uuid = str.strip(combined_equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(combined_equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_COMBINED_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
else:
|
else:
|
||||||
|
@ -139,10 +151,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (combined_equipment_id,))
|
" WHERE id = %s ", (combined_equipment_id,))
|
||||||
row_combined_equipment = cursor_system.fetchone()
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
|
elif combined_equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_combined_equipments "
|
||||||
|
" WHERE uuid = %s ", (combined_equipment_uuid,))
|
||||||
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
if row_combined_equipment is None:
|
if row_combined_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -36,6 +37,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
combined_equipment_id = req.params.get('combinedequipmentid')
|
combined_equipment_id = req.params.get('combinedequipmentid')
|
||||||
|
combined_equipment_uuid = req.params.get('combinedequipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -45,17 +47,27 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if combined_equipment_id is None:
|
if combined_equipment_id is None and combined_equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
else:
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
combined_equipment_id = str.strip(combined_equipment_id)
|
combined_equipment_id = str.strip(combined_equipment_id)
|
||||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400,
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
title='API.BAD_REQUEST',
|
title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if combined_equipment_uuid is not None:
|
||||||
|
combined_equipment_uuid = str.strip(combined_equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(combined_equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_COMBINED_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
else:
|
else:
|
||||||
|
@ -136,10 +148,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if combined_equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (combined_equipment_id,))
|
" WHERE id = %s ", (combined_equipment_id,))
|
||||||
row_combined_equipment = cursor_system.fetchone()
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
|
elif combined_equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_combined_equipments "
|
||||||
|
" WHERE uuid = %s ", (combined_equipment_uuid,))
|
||||||
|
row_combined_equipment = cursor_system.fetchone()
|
||||||
if row_combined_equipment is None:
|
if row_combined_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -34,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
equipment_id = req.params.get('equipmentid')
|
equipment_id = req.params.get('equipmentid')
|
||||||
|
equipment_uuid = req.params.get('equipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -43,12 +45,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if equipment_id is None:
|
if equipment_id is None and equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
equipment_id = str.strip(equipment_id)
|
equipment_id = str.strip(equipment_id)
|
||||||
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_uuid is not None:
|
||||||
|
equipment_uuid = str.strip(equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -130,10 +146,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_equipments "
|
" FROM tbl_equipments "
|
||||||
" WHERE id = %s ", (equipment_id,))
|
" WHERE id = %s ", (equipment_id,))
|
||||||
row_equipment = cursor_system.fetchone()
|
row_equipment = cursor_system.fetchone()
|
||||||
|
elif equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_equipments "
|
||||||
|
" WHERE uuid = %s ", (equipment_uuid,))
|
||||||
|
row_equipment = cursor_system.fetchone()
|
||||||
if row_equipment is None:
|
if row_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -34,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
equipment_id = req.params.get('equipmentid')
|
equipment_id = req.params.get('equipmentid')
|
||||||
|
equipment_uuid = req.params.get('equipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -43,12 +45,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if equipment_id is None:
|
if equipment_id is None and equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
equipment_id = str.strip(equipment_id)
|
equipment_id = str.strip(equipment_id)
|
||||||
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_uuid is not None:
|
||||||
|
equipment_uuid = str.strip(equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -130,10 +146,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_equipments "
|
" FROM tbl_equipments "
|
||||||
" WHERE id = %s ", (equipment_id,))
|
" WHERE id = %s ", (equipment_id,))
|
||||||
row_equipment = cursor_system.fetchone()
|
row_equipment = cursor_system.fetchone()
|
||||||
|
elif equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_equipments "
|
||||||
|
" WHERE uuid = %s ", (equipment_uuid,))
|
||||||
|
row_equipment = cursor_system.fetchone()
|
||||||
if row_equipment is None:
|
if row_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -34,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
equipment_id = req.params.get('equipmentid')
|
equipment_id = req.params.get('equipmentid')
|
||||||
|
equipment_uuid = req.params.get('equipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -43,12 +45,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if equipment_id is None:
|
if equipment_id is None and equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
equipment_id = str.strip(equipment_id)
|
equipment_id = str.strip(equipment_id)
|
||||||
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_uuid is not None:
|
||||||
|
equipment_uuid = str.strip(equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -130,10 +146,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_equipments "
|
" FROM tbl_equipments "
|
||||||
" WHERE id = %s ", (equipment_id,))
|
" WHERE id = %s ", (equipment_id,))
|
||||||
row_equipment = cursor_system.fetchone()
|
row_equipment = cursor_system.fetchone()
|
||||||
|
elif equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_equipments "
|
||||||
|
" WHERE uuid = %s ", (equipment_uuid,))
|
||||||
|
row_equipment = cursor_system.fetchone()
|
||||||
if row_equipment is None:
|
if row_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -34,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
equipment_id = req.params.get('equipmentid')
|
equipment_id = req.params.get('equipmentid')
|
||||||
|
equipment_uuid = req.params.get('equipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -43,12 +45,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if equipment_id is None:
|
if equipment_id is None and equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
equipment_id = str.strip(equipment_id)
|
equipment_id = str.strip(equipment_id)
|
||||||
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_uuid is not None:
|
||||||
|
equipment_uuid = str.strip(equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -130,10 +146,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_equipments "
|
" FROM tbl_equipments "
|
||||||
" WHERE id = %s ", (equipment_id,))
|
" WHERE id = %s ", (equipment_id,))
|
||||||
row_equipment = cursor_system.fetchone()
|
row_equipment = cursor_system.fetchone()
|
||||||
|
elif equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_equipments "
|
||||||
|
" WHERE uuid = %s ", (equipment_uuid,))
|
||||||
|
row_equipment = cursor_system.fetchone()
|
||||||
if row_equipment is None:
|
if row_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -34,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
equipment_id = req.params.get('equipmentid')
|
equipment_id = req.params.get('equipmentid')
|
||||||
|
equipment_uuid = req.params.get('equipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -43,12 +45,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if equipment_id is None:
|
if equipment_id is None and equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
equipment_id = str.strip(equipment_id)
|
equipment_id = str.strip(equipment_id)
|
||||||
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_uuid is not None:
|
||||||
|
equipment_uuid = str.strip(equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -130,10 +146,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_equipments "
|
" FROM tbl_equipments "
|
||||||
" WHERE id = %s ", (equipment_id,))
|
" WHERE id = %s ", (equipment_id,))
|
||||||
row_equipment = cursor_system.fetchone()
|
row_equipment = cursor_system.fetchone()
|
||||||
|
elif equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_equipments "
|
||||||
|
" WHERE uuid = %s ", (equipment_uuid,))
|
||||||
|
row_equipment = cursor_system.fetchone()
|
||||||
if row_equipment is None:
|
if row_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -34,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
equipment_id = req.params.get('equipmentid')
|
equipment_id = req.params.get('equipmentid')
|
||||||
|
equipment_uuid = req.params.get('equipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -43,12 +45,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if equipment_id is None:
|
if equipment_id is None and equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
equipment_id = str.strip(equipment_id)
|
equipment_id = str.strip(equipment_id)
|
||||||
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_equipment_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_uuid is not None:
|
||||||
|
equipment_uuid = str.strip(equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -130,10 +146,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_equipments "
|
" FROM tbl_equipments "
|
||||||
" WHERE id = %s ", (equipment_id,))
|
" WHERE id = %s ", (equipment_id,))
|
||||||
row_equipment = cursor_system.fetchone()
|
row_equipment = cursor_system.fetchone()
|
||||||
|
elif equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_equipments "
|
||||||
|
" WHERE uuid = %s ", (equipment_uuid,))
|
||||||
|
row_equipment = cursor_system.fetchone()
|
||||||
if row_equipment is None:
|
if row_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
@ -150,7 +172,6 @@ class Reporting:
|
||||||
if cnx_historical:
|
if cnx_historical:
|
||||||
cnx_historical.disconnect()
|
cnx_historical.disconnect()
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.EQUIPMENT_NOT_FOUND')
|
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.EQUIPMENT_NOT_FOUND')
|
||||||
|
|
||||||
equipment = dict()
|
equipment = dict()
|
||||||
equipment['id'] = row_equipment[0]
|
equipment['id'] = row_equipment[0]
|
||||||
equipment['name'] = row_equipment[1]
|
equipment['name'] = row_equipment[1]
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -34,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
equipment_id = req.params.get('equipmentid')
|
equipment_id = req.params.get('equipmentid')
|
||||||
|
equipment_uuid = req.params.get('equipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -43,12 +45,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if equipment_id is None:
|
if equipment_id is None and equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
equipment_id = str.strip(equipment_id)
|
equipment_id = str.strip(equipment_id)
|
||||||
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_uuid is not None:
|
||||||
|
equipment_uuid = str.strip(equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -130,10 +146,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_equipments "
|
" FROM tbl_equipments "
|
||||||
" WHERE id = %s ", (equipment_id,))
|
" WHERE id = %s ", (equipment_id,))
|
||||||
row_equipment = cursor_system.fetchone()
|
row_equipment = cursor_system.fetchone()
|
||||||
|
elif equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_equipments "
|
||||||
|
" WHERE uuid = %s ", (equipment_uuid,))
|
||||||
|
row_equipment = cursor_system.fetchone()
|
||||||
if row_equipment is None:
|
if row_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -34,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
equipment_id = req.params.get('equipmentid')
|
equipment_id = req.params.get('equipmentid')
|
||||||
|
equipment_uuid = req.params.get('equipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -43,12 +45,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if equipment_id is None:
|
if equipment_id is None and equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
equipment_id = str.strip(equipment_id)
|
equipment_id = str.strip(equipment_id)
|
||||||
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_uuid is not None:
|
||||||
|
equipment_uuid = str.strip(equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -133,10 +149,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_equipments "
|
" FROM tbl_equipments "
|
||||||
" WHERE id = %s ", (equipment_id,))
|
" WHERE id = %s ", (equipment_id,))
|
||||||
row_equipment = cursor_system.fetchone()
|
row_equipment = cursor_system.fetchone()
|
||||||
|
elif equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_equipments "
|
||||||
|
" WHERE uuid = %s ", (equipment_uuid,))
|
||||||
|
row_equipment = cursor_system.fetchone()
|
||||||
if row_equipment is None:
|
if row_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -34,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
equipment_id = req.params.get('equipmentid')
|
equipment_id = req.params.get('equipmentid')
|
||||||
|
equipment_uuid = req.params.get('equipmentuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -43,12 +45,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if equipment_id is None:
|
if equipment_id is None and equipment_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
equipment_id = str.strip(equipment_id)
|
equipment_id = str.strip(equipment_id)
|
||||||
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
if not equipment_id.isdigit() or int(equipment_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_EQUIPMENT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if equipment_uuid is not None:
|
||||||
|
equipment_uuid = str.strip(equipment_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(equipment_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -130,10 +146,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if equipment_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, cost_center_id "
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
" FROM tbl_equipments "
|
" FROM tbl_equipments "
|
||||||
" WHERE id = %s ", (equipment_id,))
|
" WHERE id = %s ", (equipment_id,))
|
||||||
row_equipment = cursor_system.fetchone()
|
row_equipment = cursor_system.fetchone()
|
||||||
|
elif equipment_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, cost_center_id "
|
||||||
|
" FROM tbl_equipments "
|
||||||
|
" WHERE uuid = %s ", (equipment_uuid,))
|
||||||
|
row_equipment = cursor_system.fetchone()
|
||||||
if row_equipment is None:
|
if row_equipment is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -178,8 +178,6 @@ class Reporting:
|
||||||
if cnx_historical:
|
if cnx_historical:
|
||||||
cnx_historical.disconnect()
|
cnx_historical.disconnect()
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
||||||
if meter_id is not None and int(meter_id) != int(row_meter[0]):
|
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
|
||||||
meter = dict()
|
meter = dict()
|
||||||
meter['id'] = row_meter[0]
|
meter['id'] = row_meter[0]
|
||||||
meter['name'] = row_meter[1]
|
meter['name'] = row_meter[1]
|
||||||
|
|
|
@ -170,8 +170,6 @@ class Reporting:
|
||||||
if cnx_historical:
|
if cnx_historical:
|
||||||
cnx_historical.disconnect()
|
cnx_historical.disconnect()
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
||||||
if meter_id is not None and int(meter_id) != int(row_meter[0]):
|
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
|
||||||
|
|
||||||
meter = dict()
|
meter = dict()
|
||||||
meter['id'] = row_meter[0]
|
meter['id'] = row_meter[0]
|
||||||
|
|
|
@ -66,13 +66,13 @@ class Reporting:
|
||||||
|
|
||||||
if meter_id is not None:
|
if meter_id is not None:
|
||||||
cursor_system.execute(" SELECT m.id, m.name, m.cost_center_id, m.energy_category_id, "
|
cursor_system.execute(" SELECT m.id, m.name, m.cost_center_id, m.energy_category_id, "
|
||||||
" ec.name, ec.unit_of_measure "
|
" ec.name, ec.unit_of_measure, ec.kgce, ec.kgco2e "
|
||||||
" FROM tbl_meters m, tbl_energy_categories ec "
|
" FROM tbl_meters m, tbl_energy_categories ec "
|
||||||
" WHERE m.id = %s AND m.energy_category_id = ec.id ", (meter_id,))
|
" WHERE m.id = %s AND m.energy_category_id = ec.id ", (meter_id,))
|
||||||
row_meter = cursor_system.fetchone()
|
row_meter = cursor_system.fetchone()
|
||||||
elif meter_uuid is not None:
|
elif meter_uuid is not None:
|
||||||
cursor_system.execute(" SELECT m.id, m.name, m.cost_center_id, m.energy_category_id, "
|
cursor_system.execute(" SELECT m.id, m.name, m.cost_center_id, m.energy_category_id, "
|
||||||
" ec.name, ec.unit_of_measure "
|
" ec.name, ec.unit_of_measure, ec.kgce, ec.kgco2e "
|
||||||
" FROM tbl_meters m, tbl_energy_categories ec "
|
" FROM tbl_meters m, tbl_energy_categories ec "
|
||||||
" WHERE m.uuid = %s AND m.energy_category_id = ec.id ", (meter_uuid,))
|
" WHERE m.uuid = %s AND m.energy_category_id = ec.id ", (meter_uuid,))
|
||||||
row_meter = cursor_system.fetchone()
|
row_meter = cursor_system.fetchone()
|
||||||
|
@ -87,8 +87,6 @@ class Reporting:
|
||||||
if cnx_historical:
|
if cnx_historical:
|
||||||
cnx_historical.disconnect()
|
cnx_historical.disconnect()
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
||||||
if meter_id is not None and int(meter_id) != int(row_meter[0]):
|
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
|
||||||
|
|
||||||
meter = dict()
|
meter = dict()
|
||||||
meter['id'] = row_meter[0]
|
meter['id'] = row_meter[0]
|
||||||
|
|
|
@ -112,13 +112,13 @@ class Reporting:
|
||||||
|
|
||||||
if meter_id is not None:
|
if meter_id is not None:
|
||||||
cursor_system.execute(" SELECT m.id, m.name, m.cost_center_id, m.energy_category_id, "
|
cursor_system.execute(" SELECT m.id, m.name, m.cost_center_id, m.energy_category_id, "
|
||||||
" ec.name, ec.unit_of_measure "
|
" ec.name, ec.unit_of_measure, ec.kgce, ec.kgco2e "
|
||||||
" FROM tbl_meters m, tbl_energy_categories ec "
|
" FROM tbl_meters m, tbl_energy_categories ec "
|
||||||
" WHERE m.id = %s AND m.energy_category_id = ec.id ", (meter_id,))
|
" WHERE m.id = %s AND m.energy_category_id = ec.id ", (meter_id,))
|
||||||
row_meter = cursor_system.fetchone()
|
row_meter = cursor_system.fetchone()
|
||||||
elif meter_uuid is not None:
|
elif meter_uuid is not None:
|
||||||
cursor_system.execute(" SELECT m.id, m.name, m.cost_center_id, m.energy_category_id, "
|
cursor_system.execute(" SELECT m.id, m.name, m.cost_center_id, m.energy_category_id, "
|
||||||
" ec.name, ec.unit_of_measure "
|
" ec.name, ec.unit_of_measure, ec.kgce, ec.kgco2e "
|
||||||
" FROM tbl_meters m, tbl_energy_categories ec "
|
" FROM tbl_meters m, tbl_energy_categories ec "
|
||||||
" WHERE m.uuid = %s AND m.energy_category_id = ec.id ", (meter_uuid,))
|
" WHERE m.uuid = %s AND m.energy_category_id = ec.id ", (meter_uuid,))
|
||||||
row_meter = cursor_system.fetchone()
|
row_meter = cursor_system.fetchone()
|
||||||
|
@ -134,8 +134,6 @@ class Reporting:
|
||||||
cnx_energy.disconnect()
|
cnx_energy.disconnect()
|
||||||
|
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
||||||
if meter_id is not None and int(meter_id) != int(row_meter[0]):
|
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
|
||||||
|
|
||||||
master_meter = dict()
|
master_meter = dict()
|
||||||
master_meter['id'] = row_meter[0]
|
master_meter['id'] = row_meter[0]
|
||||||
|
|
|
@ -129,8 +129,6 @@ class Reporting:
|
||||||
if cnx_historical:
|
if cnx_historical:
|
||||||
cnx_historical.disconnect()
|
cnx_historical.disconnect()
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
||||||
if meter_id is not None and int(meter_id) != int(row_meter[0]):
|
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND')
|
|
||||||
meter = dict()
|
meter = dict()
|
||||||
meter['id'] = row_meter[0]
|
meter['id'] = row_meter[0]
|
||||||
meter['name'] = row_meter[1]
|
meter['name'] = row_meter[1]
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
shopfloor_id = req.params.get('shopfloorid')
|
shopfloor_id = req.params.get('shopfloorid')
|
||||||
|
shopfloor_uuid = req.params.get('shopflooruuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if shopfloor_id is None:
|
if shopfloor_id is None and shopfloor_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_ID')
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
shopfloor_id = str.strip(shopfloor_id)
|
shopfloor_id = str.strip(shopfloor_id)
|
||||||
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_ID')
|
||||||
|
|
||||||
|
if shopfloor_uuid is not None:
|
||||||
|
shopfloor_uuid = str.strip(shopfloor_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(shopfloor_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_shopfloors "
|
" FROM tbl_shopfloors "
|
||||||
" WHERE id = %s ", (shopfloor_id,))
|
" WHERE id = %s ", (shopfloor_id,))
|
||||||
row_shopfloor = cursor_system.fetchone()
|
row_shopfloor = cursor_system.fetchone()
|
||||||
|
elif shopfloor_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_shopfloors "
|
||||||
|
" WHERE uuid = %s ", (shopfloor_uuid,))
|
||||||
|
row_shopfloor = cursor_system.fetchone()
|
||||||
if row_shopfloor is None:
|
if row_shopfloor is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
shopfloor_id = req.params.get('shopfloorid')
|
shopfloor_id = req.params.get('shopfloorid')
|
||||||
|
shopfloor_uuid = req.params.get('shopflooruuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if shopfloor_id is None:
|
if shopfloor_id is None and shopfloor_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_ID')
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
shopfloor_id = str.strip(shopfloor_id)
|
shopfloor_id = str.strip(shopfloor_id)
|
||||||
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_ID')
|
||||||
|
|
||||||
|
if shopfloor_uuid is not None:
|
||||||
|
shopfloor_uuid = str.strip(shopfloor_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(shopfloor_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_shopfloors "
|
" FROM tbl_shopfloors "
|
||||||
" WHERE id = %s ", (shopfloor_id,))
|
" WHERE id = %s ", (shopfloor_id,))
|
||||||
row_shopfloor = cursor_system.fetchone()
|
row_shopfloor = cursor_system.fetchone()
|
||||||
|
elif shopfloor_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_shopfloors "
|
||||||
|
" WHERE uuid = %s ", (shopfloor_uuid,))
|
||||||
|
row_shopfloor = cursor_system.fetchone()
|
||||||
if row_shopfloor is None:
|
if row_shopfloor is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
shopfloor_id = req.params.get('shopfloorid')
|
shopfloor_id = req.params.get('shopfloorid')
|
||||||
|
shopfloor_uuid = req.params.get('shopflooruuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if shopfloor_id is None:
|
if shopfloor_id is None and shopfloor_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
shopfloor_id = str.strip(shopfloor_id)
|
shopfloor_id = str.strip(shopfloor_id)
|
||||||
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if shopfloor_uuid is not None:
|
||||||
|
shopfloor_uuid = str.strip(shopfloor_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(shopfloor_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_shopfloors "
|
" FROM tbl_shopfloors "
|
||||||
" WHERE id = %s ", (shopfloor_id,))
|
" WHERE id = %s ", (shopfloor_id,))
|
||||||
row_shopfloor = cursor_system.fetchone()
|
row_shopfloor = cursor_system.fetchone()
|
||||||
|
elif shopfloor_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_shopfloors "
|
||||||
|
" WHERE uuid = %s ", (shopfloor_uuid,))
|
||||||
|
row_shopfloor = cursor_system.fetchone()
|
||||||
if row_shopfloor is None:
|
if row_shopfloor is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
shopfloor_id = req.params.get('shopfloorid')
|
shopfloor_id = req.params.get('shopfloorid')
|
||||||
|
shopfloor_uuid = req.params.get('shopflooruuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if shopfloor_id is None:
|
if shopfloor_id is None and shopfloor_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
shopfloor_id = str.strip(shopfloor_id)
|
shopfloor_id = str.strip(shopfloor_id)
|
||||||
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_ID')
|
||||||
|
|
||||||
|
if shopfloor_uuid is not None:
|
||||||
|
shopfloor_uuid = str.strip(shopfloor_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(shopfloor_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_EQUIPMENT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_shopfloors "
|
" FROM tbl_shopfloors "
|
||||||
" WHERE id = %s ", (shopfloor_id,))
|
" WHERE id = %s ", (shopfloor_id,))
|
||||||
row_shopfloor = cursor_system.fetchone()
|
row_shopfloor = cursor_system.fetchone()
|
||||||
|
elif shopfloor_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_shopfloors "
|
||||||
|
" WHERE uuid = %s ", (shopfloor_uuid,))
|
||||||
|
row_shopfloor = cursor_system.fetchone()
|
||||||
if row_shopfloor is None:
|
if row_shopfloor is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
shopfloor_id = req.params.get('shopfloorid')
|
shopfloor_id = req.params.get('shopfloorid')
|
||||||
|
shopfloor_uuid = req.params.get('shopflooruuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if shopfloor_id is None:
|
if shopfloor_id is None and shopfloor_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_ID')
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
shopfloor_id = str.strip(shopfloor_id)
|
shopfloor_id = str.strip(shopfloor_id)
|
||||||
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_ID')
|
||||||
|
|
||||||
|
if shopfloor_uuid is not None:
|
||||||
|
shopfloor_uuid = str.strip(shopfloor_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(shopfloor_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -134,10 +150,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_shopfloors "
|
" FROM tbl_shopfloors "
|
||||||
" WHERE id = %s ", (shopfloor_id,))
|
" WHERE id = %s ", (shopfloor_id,))
|
||||||
row_shopfloor = cursor_system.fetchone()
|
row_shopfloor = cursor_system.fetchone()
|
||||||
|
elif shopfloor_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_shopfloors "
|
||||||
|
" WHERE uuid = %s ", (shopfloor_uuid,))
|
||||||
|
row_shopfloor = cursor_system.fetchone()
|
||||||
if row_shopfloor is None:
|
if row_shopfloor is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
shopfloor_id = req.params.get('shopfloorid')
|
shopfloor_id = req.params.get('shopfloorid')
|
||||||
|
shopfloor_uuid = req.params.get('shopflooruuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if shopfloor_id is None:
|
if shopfloor_id is None and shopfloor_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_ID')
|
||||||
|
|
||||||
|
if shopfloor_id is not None:
|
||||||
shopfloor_id = str.strip(shopfloor_id)
|
shopfloor_id = str.strip(shopfloor_id)
|
||||||
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
if not shopfloor_id.isdigit() or int(shopfloor_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SHOPFLOOR_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_ID')
|
||||||
|
|
||||||
|
if shopfloor_uuid is not None:
|
||||||
|
shopfloor_uuid = str.strip(shopfloor_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(shopfloor_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SHOPFLOOR_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -130,11 +146,16 @@ class Reporting:
|
||||||
|
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
if shopfloor_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_shopfloors "
|
" FROM tbl_shopfloors "
|
||||||
" WHERE id = %s ", (shopfloor_id,))
|
" WHERE id = %s ", (shopfloor_id,))
|
||||||
row_shopfloor = cursor_system.fetchone()
|
row_shopfloor = cursor_system.fetchone()
|
||||||
|
elif shopfloor_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_shopfloors "
|
||||||
|
" WHERE uuid = %s ", (shopfloor_uuid,))
|
||||||
|
row_shopfloor = cursor_system.fetchone()
|
||||||
if row_shopfloor is None:
|
if row_shopfloor is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -37,6 +38,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
space_id = req.params.get('spaceid')
|
space_id = req.params.get('spaceid')
|
||||||
|
space_uuid = req.params.get('spaceuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -46,12 +48,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if space_id is None:
|
if space_id is None and space_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
space_id = str.strip(space_id)
|
space_id = str.strip(space_id)
|
||||||
if not space_id.isdigit() or int(space_id) <= 0:
|
if not space_id.isdigit() or int(space_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_uuid is not None:
|
||||||
|
space_uuid = str.strip(space_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -133,10 +149,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_spaces "
|
" FROM tbl_spaces "
|
||||||
" WHERE id = %s ", (space_id,))
|
" WHERE id = %s ", (space_id,))
|
||||||
row_space = cursor_system.fetchone()
|
row_space = cursor_system.fetchone()
|
||||||
|
elif space_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_spaces "
|
||||||
|
" WHERE uuid = %s ", (space_uuid,))
|
||||||
|
row_space = cursor_system.fetchone()
|
||||||
if row_space is None:
|
if row_space is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -37,6 +38,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
space_id = req.params.get('spaceid')
|
space_id = req.params.get('spaceid')
|
||||||
|
space_uuid = req.params.get('spaceuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -46,12 +48,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if space_id is None:
|
if space_id is None and space_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
space_id = str.strip(space_id)
|
space_id = str.strip(space_id)
|
||||||
if not space_id.isdigit() or int(space_id) <= 0:
|
if not space_id.isdigit() or int(space_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_uuid is not None:
|
||||||
|
space_uuid = str.strip(space_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -132,11 +148,16 @@ class Reporting:
|
||||||
|
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
if space_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_spaces "
|
" FROM tbl_spaces "
|
||||||
" WHERE id = %s ", (space_id,))
|
" WHERE id = %s ", (space_id,))
|
||||||
row_space = cursor_system.fetchone()
|
row_space = cursor_system.fetchone()
|
||||||
|
elif space_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_spaces "
|
||||||
|
" WHERE uuid = %s ", (space_uuid,))
|
||||||
|
row_space = cursor_system.fetchone()
|
||||||
if row_space is None:
|
if row_space is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -37,6 +38,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
space_id = req.params.get('spaceid')
|
space_id = req.params.get('spaceid')
|
||||||
|
space_uuid = req.params.get('spaceuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -46,12 +48,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if space_id is None:
|
if space_id is None and space_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
space_id = str.strip(space_id)
|
space_id = str.strip(space_id)
|
||||||
if not space_id.isdigit() or int(space_id) <= 0:
|
if not space_id.isdigit() or int(space_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_uuid is not None:
|
||||||
|
space_uuid = str.strip(space_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -133,10 +149,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_spaces "
|
" FROM tbl_spaces "
|
||||||
" WHERE id = %s ", (space_id,))
|
" WHERE id = %s ", (space_id,))
|
||||||
row_space = cursor_system.fetchone()
|
row_space = cursor_system.fetchone()
|
||||||
|
elif space_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_spaces "
|
||||||
|
" WHERE uuid = %s ", (space_uuid,))
|
||||||
|
row_space = cursor_system.fetchone()
|
||||||
if row_space is None:
|
if row_space is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -37,6 +38,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
space_id = req.params.get('spaceid')
|
space_id = req.params.get('spaceid')
|
||||||
|
space_uuid = req.params.get('spaceuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -46,12 +48,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if space_id is None:
|
if space_id is None and space_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
space_id = str.strip(space_id)
|
space_id = str.strip(space_id)
|
||||||
if not space_id.isdigit() or int(space_id) <= 0:
|
if not space_id.isdigit() or int(space_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_uuid is not None:
|
||||||
|
space_uuid = str.strip(space_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -133,10 +149,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_spaces "
|
" FROM tbl_spaces "
|
||||||
" WHERE id = %s ", (space_id,))
|
" WHERE id = %s ", (space_id,))
|
||||||
row_space = cursor_system.fetchone()
|
row_space = cursor_system.fetchone()
|
||||||
|
elif space_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_spaces "
|
||||||
|
" WHERE uuid = %s ", (space_uuid,))
|
||||||
|
row_space = cursor_system.fetchone()
|
||||||
if row_space is None:
|
if row_space is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -37,6 +38,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
space_id = req.params.get('spaceid')
|
space_id = req.params.get('spaceid')
|
||||||
|
space_uuid = req.params.get('spaceuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -46,12 +48,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if space_id is None:
|
if space_id is None and space_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
space_id = str.strip(space_id)
|
space_id = str.strip(space_id)
|
||||||
if not space_id.isdigit() or int(space_id) <= 0:
|
if not space_id.isdigit() or int(space_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_uuid is not None:
|
||||||
|
space_uuid = str.strip(space_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -133,10 +149,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_spaces "
|
" FROM tbl_spaces "
|
||||||
" WHERE id = %s ", (space_id,))
|
" WHERE id = %s ", (space_id,))
|
||||||
row_space = cursor_system.fetchone()
|
row_space = cursor_system.fetchone()
|
||||||
|
elif space_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_spaces "
|
||||||
|
" WHERE uuid = %s ", (space_uuid,))
|
||||||
|
row_space = cursor_system.fetchone()
|
||||||
if row_space is None:
|
if row_space is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
space_id = req.params.get('spaceid')
|
space_id = req.params.get('spaceid')
|
||||||
|
space_uuid = req.params.get('spaceuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if space_id is None:
|
if space_id is None and space_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
space_id = str.strip(space_id)
|
space_id = str.strip(space_id)
|
||||||
if not space_id.isdigit() or int(space_id) <= 0:
|
if not space_id.isdigit() or int(space_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_uuid is not None:
|
||||||
|
space_uuid = str.strip(space_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_spaces "
|
" FROM tbl_spaces "
|
||||||
" WHERE id = %s ", (space_id,))
|
" WHERE id = %s ", (space_id,))
|
||||||
row_space = cursor_system.fetchone()
|
row_space = cursor_system.fetchone()
|
||||||
|
elif space_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_spaces "
|
||||||
|
" WHERE uuid = %s ", (space_uuid,))
|
||||||
|
row_space = cursor_system.fetchone()
|
||||||
if row_space is None:
|
if row_space is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -37,6 +38,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
space_id = req.params.get('spaceid')
|
space_id = req.params.get('spaceid')
|
||||||
|
space_uuid = req.params.get('spaceuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -46,12 +48,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if space_id is None:
|
if space_id is None and space_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
space_id = str.strip(space_id)
|
space_id = str.strip(space_id)
|
||||||
if not space_id.isdigit() or int(space_id) <= 0:
|
if not space_id.isdigit() or int(space_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_uuid is not None:
|
||||||
|
space_uuid = str.strip(space_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -133,10 +149,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_spaces "
|
" FROM tbl_spaces "
|
||||||
" WHERE id = %s ", (space_id,))
|
" WHERE id = %s ", (space_id,))
|
||||||
row_space = cursor_system.fetchone()
|
row_space = cursor_system.fetchone()
|
||||||
|
elif space_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_spaces "
|
||||||
|
" WHERE uuid = %s ", (space_uuid,))
|
||||||
|
row_space = cursor_system.fetchone()
|
||||||
if row_space is None:
|
if row_space is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -37,6 +38,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
space_id = req.params.get('spaceid')
|
space_id = req.params.get('spaceid')
|
||||||
|
space_uuid = req.params.get('spaceuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -46,12 +48,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if space_id is None:
|
if space_id is None and space_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
space_id = str.strip(space_id)
|
space_id = str.strip(space_id)
|
||||||
if not space_id.isdigit() or int(space_id) <= 0:
|
if not space_id.isdigit() or int(space_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_uuid is not None:
|
||||||
|
space_uuid = str.strip(space_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -136,10 +152,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_spaces "
|
" FROM tbl_spaces "
|
||||||
" WHERE id = %s ", (space_id,))
|
" WHERE id = %s ", (space_id,))
|
||||||
row_space = cursor_system.fetchone()
|
row_space = cursor_system.fetchone()
|
||||||
|
elif space_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_spaces "
|
||||||
|
" WHERE uuid = %s ", (space_uuid,))
|
||||||
|
row_space = cursor_system.fetchone()
|
||||||
if row_space is None:
|
if row_space is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
space_id = req.params.get('spaceid')
|
space_id = req.params.get('spaceid')
|
||||||
|
space_uuid = req.params.get('spaceuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if space_id is None:
|
if space_id is None and space_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
space_id = str.strip(space_id)
|
space_id = str.strip(space_id)
|
||||||
if not space_id.isdigit() or int(space_id) <= 0:
|
if not space_id.isdigit() or int(space_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SPACE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_ID')
|
||||||
|
|
||||||
|
if space_uuid is not None:
|
||||||
|
space_uuid = str.strip(space_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_SPACE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if space_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_spaces "
|
" FROM tbl_spaces "
|
||||||
" WHERE id = %s ", (space_id,))
|
" WHERE id = %s ", (space_id,))
|
||||||
row_space = cursor_system.fetchone()
|
row_space = cursor_system.fetchone()
|
||||||
|
elif space_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_spaces "
|
||||||
|
" WHERE uuid = %s ", (space_uuid,))
|
||||||
|
row_space = cursor_system.fetchone()
|
||||||
if row_space is None:
|
if row_space is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
store_id = req.params.get('storeid')
|
store_id = req.params.get('storeid')
|
||||||
|
store_uuid = req.params.get('storeuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if store_id is None:
|
if store_id is None and store_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
store_id = str.strip(store_id)
|
store_id = str.strip(store_id)
|
||||||
if not store_id.isdigit() or int(store_id) <= 0:
|
if not store_id.isdigit() or int(store_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_uuid is not None:
|
||||||
|
space_uuid = str.strip(store_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_stores "
|
" FROM tbl_stores "
|
||||||
" WHERE id = %s ", (store_id,))
|
" WHERE id = %s ", (store_id,))
|
||||||
row_store = cursor_system.fetchone()
|
row_store = cursor_system.fetchone()
|
||||||
|
elif store_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_stores "
|
||||||
|
" WHERE uuid = %s ", (store_uuid,))
|
||||||
|
row_store = cursor_system.fetchone()
|
||||||
if row_store is None:
|
if row_store is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
store_id = req.params.get('storeid')
|
store_id = req.params.get('storeid')
|
||||||
|
store_uuid = req.params.get('storeuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if store_id is None:
|
if store_id is None and store_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
store_id = str.strip(store_id)
|
store_id = str.strip(store_id)
|
||||||
if not store_id.isdigit() or int(store_id) <= 0:
|
if not store_id.isdigit() or int(store_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_uuid is not None:
|
||||||
|
space_uuid = str.strip(store_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_stores "
|
" FROM tbl_stores "
|
||||||
" WHERE id = %s ", (store_id,))
|
" WHERE id = %s ", (store_id,))
|
||||||
row_store = cursor_system.fetchone()
|
row_store = cursor_system.fetchone()
|
||||||
|
elif store_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_stores "
|
||||||
|
" WHERE uuid = %s ", (store_uuid,))
|
||||||
|
row_store = cursor_system.fetchone()
|
||||||
if row_store is None:
|
if row_store is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
store_id = req.params.get('storeid')
|
store_id = req.params.get('storeid')
|
||||||
|
store_uuid = req.params.get('storeuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if store_id is None:
|
if store_id is None and store_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
store_id = str.strip(store_id)
|
store_id = str.strip(store_id)
|
||||||
if not store_id.isdigit() or int(store_id) <= 0:
|
if not store_id.isdigit() or int(store_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_uuid is not None:
|
||||||
|
space_uuid = str.strip(store_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_stores "
|
" FROM tbl_stores "
|
||||||
" WHERE id = %s ", (store_id,))
|
" WHERE id = %s ", (store_id,))
|
||||||
row_store = cursor_system.fetchone()
|
row_store = cursor_system.fetchone()
|
||||||
|
elif store_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_stores "
|
||||||
|
" WHERE uuid = %s ", (store_uuid,))
|
||||||
|
row_store = cursor_system.fetchone()
|
||||||
if row_store is None:
|
if row_store is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
store_id = req.params.get('storeid')
|
store_id = req.params.get('storeid')
|
||||||
|
store_uuid = req.params.get('storeuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if store_id is None:
|
if store_id is None and store_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
store_id = str.strip(store_id)
|
store_id = str.strip(store_id)
|
||||||
if not store_id.isdigit() or int(store_id) <= 0:
|
if not store_id.isdigit() or int(store_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_uuid is not None:
|
||||||
|
space_uuid = str.strip(store_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,10 +147,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_stores "
|
" FROM tbl_stores "
|
||||||
" WHERE id = %s ", (store_id,))
|
" WHERE id = %s ", (store_id,))
|
||||||
row_store = cursor_system.fetchone()
|
row_store = cursor_system.fetchone()
|
||||||
|
elif store_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_stores "
|
||||||
|
" WHERE uuid = %s ", (store_uuid,))
|
||||||
|
row_store = cursor_system.fetchone()
|
||||||
if row_store is None:
|
if row_store is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
store_id = req.params.get('storeid')
|
store_id = req.params.get('storeid')
|
||||||
|
store_uuid = req.params.get('storeuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if store_id is None:
|
if store_id is None and store_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
store_id = str.strip(store_id)
|
store_id = str.strip(store_id)
|
||||||
if not store_id.isdigit() or int(store_id) <= 0:
|
if not store_id.isdigit() or int(store_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_uuid is not None:
|
||||||
|
space_uuid = str.strip(store_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -134,10 +150,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_stores "
|
" FROM tbl_stores "
|
||||||
" WHERE id = %s ", (store_id,))
|
" WHERE id = %s ", (store_id,))
|
||||||
row_store = cursor_system.fetchone()
|
row_store = cursor_system.fetchone()
|
||||||
|
elif store_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_stores "
|
||||||
|
" WHERE uuid = %s ", (store_uuid,))
|
||||||
|
row_store = cursor_system.fetchone()
|
||||||
if row_store is None:
|
if row_store is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -36,6 +37,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
store_id = req.params.get('storeid')
|
store_id = req.params.get('storeid')
|
||||||
|
store_uuid = req.params.get('storeuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -45,12 +47,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if store_id is None:
|
if store_id is None and store_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
store_id = str.strip(store_id)
|
store_id = str.strip(store_id)
|
||||||
if not store_id.isdigit() or int(store_id) <= 0:
|
if not store_id.isdigit() or int(store_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_STORE_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_ID')
|
||||||
|
|
||||||
|
if store_uuid is not None:
|
||||||
|
space_uuid = str.strip(store_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_STORE_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -132,10 +148,16 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
|
if store_id is not None:
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
" FROM tbl_stores "
|
" FROM tbl_stores "
|
||||||
" WHERE id = %s ", (store_id,))
|
" WHERE id = %s ", (store_id,))
|
||||||
row_store = cursor_system.fetchone()
|
row_store = cursor_system.fetchone()
|
||||||
|
elif store_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
||||||
|
" FROM tbl_stores "
|
||||||
|
" WHERE uuid = %s ", (store_uuid,))
|
||||||
|
row_store = cursor_system.fetchone()
|
||||||
if row_store is None:
|
if row_store is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -32,6 +33,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
tenant_id = req.params.get('tenantid')
|
tenant_id = req.params.get('tenantid')
|
||||||
|
tenant_uuid = req.params.get('tenantuuid')
|
||||||
reporting_start_datetime_local = req.params.get('reportingperiodstartdatetime')
|
reporting_start_datetime_local = req.params.get('reportingperiodstartdatetime')
|
||||||
reporting_end_datetime_local = req.params.get('reportingperiodenddatetime')
|
reporting_end_datetime_local = req.params.get('reportingperiodenddatetime')
|
||||||
# This value is intentionally left daily
|
# This value is intentionally left daily
|
||||||
|
@ -40,12 +42,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if tenant_id is None:
|
if tenant_id is None and tenant_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_id is not None:
|
||||||
tenant_id = str.strip(tenant_id)
|
tenant_id = str.strip(tenant_id)
|
||||||
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_uuid is not None:
|
||||||
|
space_uuid = str.strip(tenant_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_UUID')
|
||||||
|
|
||||||
timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6])
|
timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6])
|
||||||
if config.utc_offset[0] == '-':
|
if config.utc_offset[0] == '-':
|
||||||
|
@ -93,11 +109,18 @@ class Reporting:
|
||||||
cnx_billing = mysql.connector.connect(**config.myems_billing_db)
|
cnx_billing = mysql.connector.connect(**config.myems_billing_db)
|
||||||
cursor_billing = cnx_billing.cursor()
|
cursor_billing = cnx_billing.cursor()
|
||||||
|
|
||||||
|
if tenant_id is not None:
|
||||||
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
" c.email, c.phone, cost_center_id "
|
" c.email, c.phone, cost_center_id "
|
||||||
" FROM tbl_tenants t, tbl_contacts c "
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
" WHERE t.id = %s AND t.contact_id = c.id ", (tenant_id,))
|
" WHERE t.id = %s AND t.contact_id = c.id ", (tenant_id,))
|
||||||
row_tenant = cursor_system.fetchone()
|
row_tenant = cursor_system.fetchone()
|
||||||
|
elif tenant_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.uuid = %s AND t.contact_id = c.id ", (tenant_uuid,))
|
||||||
|
row_tenant = cursor_system.fetchone()
|
||||||
if row_tenant is None:
|
if row_tenant is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
tenant_id = req.params.get('tenantid')
|
tenant_id = req.params.get('tenantid')
|
||||||
|
tenant_uuid = req.params.get('tenantuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if tenant_id is None:
|
if tenant_id is None and tenant_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_id is not None:
|
||||||
tenant_id = str.strip(tenant_id)
|
tenant_id = str.strip(tenant_id)
|
||||||
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_uuid is not None:
|
||||||
|
space_uuid = str.strip(tenant_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,9 +147,17 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
if tenant_id is not None:
|
||||||
" FROM tbl_tenants "
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
" WHERE id = %s ", (tenant_id,))
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.id = %s AND t.contact_id = c.id ", (tenant_id,))
|
||||||
|
row_tenant = cursor_system.fetchone()
|
||||||
|
elif tenant_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.uuid = %s AND t.contact_id = c.id ", (tenant_uuid,))
|
||||||
row_tenant = cursor_system.fetchone()
|
row_tenant = cursor_system.fetchone()
|
||||||
if row_tenant is None:
|
if row_tenant is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
tenant_id = req.params.get('tenantid')
|
tenant_id = req.params.get('tenantid')
|
||||||
|
tenant_uuid = req.params.get('tenantuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if tenant_id is None:
|
if tenant_id is None and tenant_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_id is not None:
|
||||||
tenant_id = str.strip(tenant_id)
|
tenant_id = str.strip(tenant_id)
|
||||||
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_uuid is not None:
|
||||||
|
space_uuid = str.strip(tenant_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,9 +147,17 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
if tenant_id is not None:
|
||||||
" FROM tbl_tenants "
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
" WHERE id = %s ", (tenant_id,))
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.id = %s AND t.contact_id = c.id ", (tenant_id,))
|
||||||
|
row_tenant = cursor_system.fetchone()
|
||||||
|
elif tenant_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.uuid = %s AND t.contact_id = c.id ", (tenant_uuid,))
|
||||||
row_tenant = cursor_system.fetchone()
|
row_tenant = cursor_system.fetchone()
|
||||||
if row_tenant is None:
|
if row_tenant is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
tenant_id = req.params.get('tenantid')
|
tenant_id = req.params.get('tenantid')
|
||||||
|
tenant_uuid = req.params.get('tenantuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if tenant_id is None:
|
if tenant_id is None and tenant_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_id is not None:
|
||||||
tenant_id = str.strip(tenant_id)
|
tenant_id = str.strip(tenant_id)
|
||||||
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_uuid is not None:
|
||||||
|
space_uuid = str.strip(tenant_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,9 +147,17 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
if tenant_id is not None:
|
||||||
" FROM tbl_tenants "
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
" WHERE id = %s ", (tenant_id,))
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.id = %s AND t.contact_id = c.id ", (tenant_id,))
|
||||||
|
row_tenant = cursor_system.fetchone()
|
||||||
|
elif tenant_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.uuid = %s AND t.contact_id = c.id ", (tenant_uuid,))
|
||||||
row_tenant = cursor_system.fetchone()
|
row_tenant = cursor_system.fetchone()
|
||||||
if row_tenant is None:
|
if row_tenant is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
tenant_id = req.params.get('tenantid')
|
tenant_id = req.params.get('tenantid')
|
||||||
|
tenant_uuid = req.params.get('tenantuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if tenant_id is None:
|
if tenant_id is None and tenant_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_id is not None:
|
||||||
tenant_id = str.strip(tenant_id)
|
tenant_id = str.strip(tenant_id)
|
||||||
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_uuid is not None:
|
||||||
|
space_uuid = str.strip(tenant_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,9 +147,17 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
if tenant_id is not None:
|
||||||
" FROM tbl_tenants "
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
" WHERE id = %s ", (tenant_id,))
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.id = %s AND t.contact_id = c.id ", (tenant_id,))
|
||||||
|
row_tenant = cursor_system.fetchone()
|
||||||
|
elif tenant_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.uuid = %s AND t.contact_id = c.id ", (tenant_uuid,))
|
||||||
row_tenant = cursor_system.fetchone()
|
row_tenant = cursor_system.fetchone()
|
||||||
if row_tenant is None:
|
if row_tenant is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
tenant_id = req.params.get('tenantid')
|
tenant_id = req.params.get('tenantid')
|
||||||
|
tenant_uuid = req.params.get('tenantuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if tenant_id is None:
|
if tenant_id is None and tenant_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_id is not None:
|
||||||
tenant_id = str.strip(tenant_id)
|
tenant_id = str.strip(tenant_id)
|
||||||
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_uuid is not None:
|
||||||
|
space_uuid = str.strip(tenant_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -134,9 +150,17 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
if tenant_id is not None:
|
||||||
" FROM tbl_tenants "
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
" WHERE id = %s ", (tenant_id,))
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.id = %s AND t.contact_id = c.id ", (tenant_id,))
|
||||||
|
row_tenant = cursor_system.fetchone()
|
||||||
|
elif tenant_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.uuid = %s AND t.contact_id = c.id ", (tenant_uuid,))
|
||||||
row_tenant = cursor_system.fetchone()
|
row_tenant = cursor_system.fetchone()
|
||||||
if row_tenant is None:
|
if row_tenant is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -35,6 +36,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
tenant_id = req.params.get('tenantid')
|
tenant_id = req.params.get('tenantid')
|
||||||
|
tenant_uuid = req.params.get('tenantuuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
base_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,12 +46,26 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if tenant_id is None:
|
if tenant_id is None and tenant_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
else:
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_id is not None:
|
||||||
tenant_id = str.strip(tenant_id)
|
tenant_id = str.strip(tenant_id)
|
||||||
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
if not tenant_id.isdigit() or int(tenant_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TENANT_ID')
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_ID')
|
||||||
|
|
||||||
|
if tenant_uuid is not None:
|
||||||
|
space_uuid = str.strip(tenant_uuid)
|
||||||
|
regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I)
|
||||||
|
match = regex.match(space_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400,
|
||||||
|
title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_TENANT_UUID')
|
||||||
|
|
||||||
if period_type is None:
|
if period_type is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_PERIOD_TYPE')
|
||||||
|
@ -131,9 +147,17 @@ class Reporting:
|
||||||
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
cnx_historical = mysql.connector.connect(**config.myems_historical_db)
|
||||||
cursor_historical = cnx_historical.cursor()
|
cursor_historical = cnx_historical.cursor()
|
||||||
|
|
||||||
cursor_system.execute(" SELECT id, name, area, cost_center_id "
|
if tenant_id is not None:
|
||||||
" FROM tbl_tenants "
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
" WHERE id = %s ", (tenant_id,))
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.id = %s AND t.contact_id = c.id ", (tenant_id,))
|
||||||
|
row_tenant = cursor_system.fetchone()
|
||||||
|
elif tenant_uuid is not None:
|
||||||
|
cursor_system.execute(" SELECT t.id, t.name, t.buildings, t.floors, t.rooms, t.lease_number, "
|
||||||
|
" c.email, c.phone, cost_center_id "
|
||||||
|
" FROM tbl_tenants t, tbl_contacts c "
|
||||||
|
" WHERE t.uuid = %s AND t.contact_id = c.id ", (tenant_uuid,))
|
||||||
row_tenant = cursor_system.fetchone()
|
row_tenant = cursor_system.fetchone()
|
||||||
if row_tenant is None:
|
if row_tenant is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
|
|
Loading…
Reference in New Issue