Merge branch 'develop'
commit
51918aff97
|
@ -11133,7 +11133,14 @@
|
||||||
"query": [
|
"query": [
|
||||||
{
|
{
|
||||||
"key": "meterid",
|
"key": "meterid",
|
||||||
"value": "6"
|
"value": "6",
|
||||||
|
"description": "use meter id or meteruuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "meteruuid",
|
||||||
|
"value": "5ca47bc5-22c2-47fc-b906-33222191ea40",
|
||||||
|
"description": "use meter id or meteruuid",
|
||||||
|
"disabled": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "periodtype",
|
"key": "periodtype",
|
||||||
|
|
|
@ -6,6 +6,7 @@ from datetime import datetime, timedelta, timezone
|
||||||
from core import utilities
|
from core import utilities
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import excelexporters.meterenergy
|
import excelexporters.meterenergy
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class Reporting:
|
class Reporting:
|
||||||
|
@ -32,7 +33,9 @@ class Reporting:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
|
# this procedure accepts meter id or meter uuid to identify a meter
|
||||||
meter_id = req.params.get('meterid')
|
meter_id = req.params.get('meterid')
|
||||||
|
meter_uuid = req.params.get('meteruuid')
|
||||||
period_type = req.params.get('periodtype')
|
period_type = req.params.get('periodtype')
|
||||||
base_period_start_datetime = req.params.get('baseperiodstartdatetime')
|
base_period_start_datetime = req.params.get('baseperiodstartdatetime')
|
||||||
base_period_end_datetime = req.params.get('baseperiodenddatetime')
|
base_period_end_datetime = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -42,13 +45,21 @@ class Reporting:
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: valid parameters
|
# Step 1: valid parameters
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
if meter_id is None:
|
if meter_id is None and meter_uuid is None:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_METER_ID')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_METER_ID')
|
||||||
else:
|
|
||||||
|
if meter_id is not None:
|
||||||
meter_id = str.strip(meter_id)
|
meter_id = str.strip(meter_id)
|
||||||
if not meter_id.isdigit() or int(meter_id) <= 0:
|
if not meter_id.isdigit() or int(meter_id) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_METER_ID')
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_METER_ID')
|
||||||
|
|
||||||
|
if meter_uuid is not None:
|
||||||
|
meter_uuid = str.strip(meter_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(meter_uuid)
|
||||||
|
if not bool(match):
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_METER_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:
|
||||||
|
@ -131,11 +142,18 @@ 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 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.kgce, ec.kgco2e "
|
" 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:
|
||||||
|
cursor_system.execute(" SELECT m.id, m.name, m.cost_center_id, m.energy_category_id, "
|
||||||
|
" ec.name, ec.unit_of_measure, ec.kgce, ec.kgco2e "
|
||||||
|
" FROM tbl_meters m, tbl_energy_categories ec "
|
||||||
|
" WHERE m.uuid = %s AND m.energy_category_id = ec.id ", (meter_uuid,))
|
||||||
|
row_meter = cursor_system.fetchone()
|
||||||
if row_meter is None:
|
if row_meter is None:
|
||||||
if cursor_system:
|
if cursor_system:
|
||||||
cursor_system.close()
|
cursor_system.close()
|
||||||
|
@ -152,6 +170,8 @@ 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]
|
||||||
|
|
Loading…
Reference in New Issue