Merge branch 'develop'
commit
fb64d8017f
|
@ -11089,7 +11089,14 @@
|
||||||
"query": [
|
"query": [
|
||||||
{
|
{
|
||||||
"key": "meterid",
|
"key": "meterid",
|
||||||
"value": "6"
|
"value": "6",
|
||||||
|
"description": "use meterid or meteruuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "meteruuid",
|
||||||
|
"value": "eb78f7f9-f26f-463b-92fa-d9daf5b3651c",
|
||||||
|
"description": "use meterid or meteruuid",
|
||||||
|
"disabled": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "periodtype",
|
"key": "periodtype",
|
||||||
|
@ -11185,6 +11192,12 @@
|
||||||
{
|
{
|
||||||
"key": "meterid",
|
"key": "meterid",
|
||||||
"value": "1"
|
"value": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "meteruuid",
|
||||||
|
"value": "eb78f7f9-f26f-463b-92fa-d9daf5b3651c",
|
||||||
|
"description": "use meterid or meteruuid",
|
||||||
|
"disabled": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -11208,7 +11221,14 @@
|
||||||
"query": [
|
"query": [
|
||||||
{
|
{
|
||||||
"key": "meterid",
|
"key": "meterid",
|
||||||
"value": "1"
|
"value": "1",
|
||||||
|
"description": "use meterid or meteruuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "meteruuid",
|
||||||
|
"value": "eb78f7f9-f26f-463b-92fa-d9daf5b3651c",
|
||||||
|
"description": "use meterid or meteruuid",
|
||||||
|
"disabled": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "periodtype",
|
"key": "periodtype",
|
||||||
|
@ -11244,7 +11264,14 @@
|
||||||
"query": [
|
"query": [
|
||||||
{
|
{
|
||||||
"key": "meterid",
|
"key": "meterid",
|
||||||
"value": "6"
|
"value": "6",
|
||||||
|
"description": "use meterid or meteruuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "meteruuid",
|
||||||
|
"value": "eb78f7f9-f26f-463b-92fa-d9daf5b3651c",
|
||||||
|
"description": "use meterid or meteruuid",
|
||||||
|
"disabled": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "reportingperiodstartdatetime",
|
"key": "reportingperiodstartdatetime",
|
||||||
|
@ -11253,11 +11280,6 @@
|
||||||
{
|
{
|
||||||
"key": "reportingperiodenddatetime",
|
"key": "reportingperiodenddatetime",
|
||||||
"value": "2020-09-11T00:00:00"
|
"value": "2020-09-11T00:00:00"
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "",
|
|
||||||
"value": "",
|
|
||||||
"disabled": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -11281,7 +11303,14 @@
|
||||||
"query": [
|
"query": [
|
||||||
{
|
{
|
||||||
"key": "meterid",
|
"key": "meterid",
|
||||||
"value": "6"
|
"value": "6",
|
||||||
|
"description": "use meterid or meteruuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "meteruuid",
|
||||||
|
"value": "eb78f7f9-f26f-463b-92fa-d9daf5b3651c",
|
||||||
|
"description": "use meterid or meteruuid",
|
||||||
|
"disabled": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "reportingperiodstartdatetime",
|
"key": "reportingperiodstartdatetime",
|
||||||
|
|
|
@ -2307,22 +2307,37 @@ curl -i -X GET {{base_url}}/reports/equipmentstatistics?equipmentid=1&periodtype
|
||||||
curl -i -X GET {{base_url}}/reports/meterbatch?spaceid=1&reportingperiodstartdatetime=2021-05-01T00:00:00&reportingperiodenddatetime=2021-05-20T11:41:09
|
curl -i -X GET {{base_url}}/reports/meterbatch?spaceid=1&reportingperiodstartdatetime=2021-05-01T00:00:00&reportingperiodenddatetime=2021-05-20T11:41:09
|
||||||
```
|
```
|
||||||
* GET Meter Cost Report
|
* GET Meter Cost Report
|
||||||
|
|
||||||
|
(use meterid or meteruuid to get meter report)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -i -X GET {{base_url}}/reports/metercost?meterid=6&periodtype=daily&baseperiodstartdatetime=2020-08-01T00:00:00&baseperiodenddatetime=2020-09-01T00:00:00&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00
|
curl -i -X GET {{base_url}}/reports/metercost?meterid=6&periodtype=daily&baseperiodstartdatetime=2020-08-01T00:00:00&baseperiodenddatetime=2020-09-01T00:00:00&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00
|
||||||
```
|
```
|
||||||
* GET Meter Energy Report
|
* GET Meter Energy Report
|
||||||
|
|
||||||
|
(use meterid or meteruuid to get meter report)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -i -X GET {{base_url}}/reports/meterenergy?meterid=6&periodtype=daily&baseperiodstartdatetime=2020-08-01T00:00:00&baseperiodenddatetime=2020-09-01T00:00:00&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00
|
curl -i -X GET {{base_url}}/reports/meterenergy?meterid=6&periodtype=daily&baseperiodstartdatetime=2020-08-01T00:00:00&baseperiodenddatetime=2020-09-01T00:00:00&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00
|
||||||
```
|
```
|
||||||
* GET Meter Realtime Report
|
* GET Meter Realtime Report
|
||||||
|
|
||||||
|
(use meterid or meteruuid to get meter report)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -i -X GET {{base_url}}/reports/meterrealtime?meterid=1
|
curl -i -X GET {{base_url}}/reports/meterrealtime?meterid=1
|
||||||
```
|
```
|
||||||
* GET Meter Submeters Balance Report
|
* GET Meter Submeters Balance Report
|
||||||
|
|
||||||
|
(use meterid or meteruuid to get meter report)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -i -X GET {{base_url}}/reports/metersubmetersbalance?meterid=1&periodtype=daily&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00
|
curl -i -X GET {{base_url}}/reports/metersubmetersbalance?meterid=1&periodtype=daily&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00
|
||||||
```
|
```
|
||||||
* GET Meter Trend Report
|
* GET Meter Trend Report
|
||||||
|
|
||||||
|
(use meterid or meteruuid to get meter report)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -i -X GET {{base_url}}/reports/metertrend?meterid=6&reportingperiodstartdatetime=2020-09-10T00:00:00&reportingperiodenddatetime=2020-09-11T00:00:00
|
curl -i -X GET {{base_url}}/reports/metertrend?meterid=6&reportingperiodstartdatetime=2020-09-10T00:00:00&reportingperiodenddatetime=2020-09-11T00:00:00
|
||||||
```
|
```
|
||||||
|
|
|
@ -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)
|
||||||
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_local = req.params.get('baseperiodstartdatetime')
|
base_period_start_datetime_local = req.params.get('baseperiodstartdatetime')
|
||||||
base_period_end_datetime_local = req.params.get('baseperiodenddatetime')
|
base_period_end_datetime_local = req.params.get('baseperiodenddatetime')
|
||||||
|
@ -44,16 +46,20 @@ 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,
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_METER_ID')
|
||||||
title='API.BAD_REQUEST',
|
|
||||||
description='API.INVALID_METER_ID')
|
if meter_id is not None:
|
||||||
else:
|
|
||||||
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,
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_METER_ID')
|
||||||
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')
|
||||||
|
@ -139,12 +145,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()
|
||||||
|
@ -166,7 +178,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]
|
||||||
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
|
||||||
|
@ -28,17 +29,26 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
meter_id = req.params.get('meterid')
|
meter_id = req.params.get('meterid')
|
||||||
|
meter_uuid = req.params.get('meteruuid')
|
||||||
|
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# 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')
|
||||||
|
|
||||||
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] == '-':
|
||||||
timezone_offset = -timezone_offset
|
timezone_offset = -timezone_offset
|
||||||
|
@ -54,11 +64,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.name, ec.unit_of_measure "
|
||||||
" 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 "
|
||||||
|
" 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()
|
||||||
|
@ -70,6 +87,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]
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import re
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -33,6 +35,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
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')
|
||||||
reporting_period_start_datetime_local = req.params.get('reportingperiodstartdatetime')
|
reporting_period_start_datetime_local = req.params.get('reportingperiodstartdatetime')
|
||||||
reporting_period_end_datetime_local = req.params.get('reportingperiodenddatetime')
|
reporting_period_end_datetime_local = req.params.get('reportingperiodenddatetime')
|
||||||
|
@ -40,13 +43,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:
|
||||||
|
@ -99,11 +110,18 @@ class Reporting:
|
||||||
cnx_energy = mysql.connector.connect(**config.myems_energy_db)
|
cnx_energy = mysql.connector.connect(**config.myems_energy_db)
|
||||||
cursor_energy = cnx_energy.cursor()
|
cursor_energy = cnx_energy.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.name, ec.unit_of_measure "
|
||||||
" 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 "
|
||||||
|
" 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()
|
||||||
|
@ -116,6 +134,8 @@ 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]
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import re
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
@ -30,6 +32,7 @@ class Reporting:
|
||||||
def on_get(req, resp):
|
def on_get(req, resp):
|
||||||
print(req.params)
|
print(req.params)
|
||||||
meter_id = req.params.get('meterid')
|
meter_id = req.params.get('meterid')
|
||||||
|
meter_uuid = req.params.get('meteruuid')
|
||||||
reporting_period_start_datetime_local = req.params.get('reportingperiodstartdatetime')
|
reporting_period_start_datetime_local = req.params.get('reportingperiodstartdatetime')
|
||||||
reporting_period_end_datetime_local = req.params.get('reportingperiodenddatetime')
|
reporting_period_end_datetime_local = req.params.get('reportingperiodenddatetime')
|
||||||
quick_mode = req.params.get('quickmode')
|
quick_mode = req.params.get('quickmode')
|
||||||
|
@ -37,13 +40,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')
|
||||||
|
|
||||||
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] == '-':
|
||||||
timezone_offset = -timezone_offset
|
timezone_offset = -timezone_offset
|
||||||
|
@ -95,12 +106,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()
|
||||||
|
@ -112,7 +129,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]
|
||||||
meter['name'] = row_meter[1]
|
meter['name'] = row_meter[1]
|
||||||
|
|
Loading…
Reference in New Issue