fixed issue when links is None in energyflowdiagram in API
parent
a367bfc140
commit
35bb9600b5
|
@ -209,45 +209,46 @@ 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()
|
||||||
for x in range(len(meta_result['links'])):
|
if meta_result['links'] is not None and len(meta_result['links']) > 0:
|
||||||
if meta_result['links'][x] is None or meta_result['links'][x]['meter'] is None:
|
for x in range(len(meta_result['links'])):
|
||||||
continue
|
if meta_result['links'][x] is None or meta_result['links'][x]['meter'] is None:
|
||||||
if meta_result['links'][x]['meter']['type'] == 'meter':
|
continue
|
||||||
query = (" SELECT SUM(actual_value) "
|
if meta_result['links'][x]['meter']['type'] == 'meter':
|
||||||
" FROM tbl_meter_hourly "
|
query = (" SELECT SUM(actual_value) "
|
||||||
" WHERE meter_id = %s "
|
" FROM tbl_meter_hourly "
|
||||||
" AND start_datetime_utc >= %s "
|
" WHERE meter_id = %s "
|
||||||
" AND start_datetime_utc < %s ")
|
" AND start_datetime_utc >= %s "
|
||||||
cursor_energy.execute(query, (meta_result['links'][x]['meter']['id'],
|
" AND start_datetime_utc < %s ")
|
||||||
reporting_start_datetime_utc,
|
cursor_energy.execute(query, (meta_result['links'][x]['meter']['id'],
|
||||||
reporting_end_datetime_utc))
|
reporting_start_datetime_utc,
|
||||||
row = cursor_energy.fetchone()
|
reporting_end_datetime_utc))
|
||||||
if row is not None:
|
row = cursor_energy.fetchone()
|
||||||
meta_result['links'][x]['value'] = row[0]
|
if row is not None:
|
||||||
elif meta_result['links'][x]['meter']['type'] == 'offline_meter':
|
meta_result['links'][x]['value'] = row[0]
|
||||||
query = (" SELECT SUM(actual_value) "
|
elif meta_result['links'][x]['meter']['type'] == 'offline_meter':
|
||||||
" FROM tbl_offline_meter_hourly "
|
query = (" SELECT SUM(actual_value) "
|
||||||
" WHERE offline_meter_id = %s "
|
" FROM tbl_offline_meter_hourly "
|
||||||
" AND start_datetime_utc >= %s "
|
" WHERE offline_meter_id = %s "
|
||||||
" AND start_datetime_utc < %s ")
|
" AND start_datetime_utc >= %s "
|
||||||
cursor_energy.execute(query, (meta_result['links'][x]['meter']['id'],
|
" AND start_datetime_utc < %s ")
|
||||||
reporting_start_datetime_utc,
|
cursor_energy.execute(query, (meta_result['links'][x]['meter']['id'],
|
||||||
reporting_end_datetime_utc))
|
reporting_start_datetime_utc,
|
||||||
row = cursor_energy.fetchone()
|
reporting_end_datetime_utc))
|
||||||
if row is not None:
|
row = cursor_energy.fetchone()
|
||||||
meta_result['links'][x]['value'] = row[0]
|
if row is not None:
|
||||||
elif meta_result['links'][x]['meter']['type'] == 'virtual_meter':
|
meta_result['links'][x]['value'] = row[0]
|
||||||
query = (" SELECT SUM(actual_value) "
|
elif meta_result['links'][x]['meter']['type'] == 'virtual_meter':
|
||||||
" FROM tbl_virtual_meter_hourly "
|
query = (" SELECT SUM(actual_value) "
|
||||||
" WHERE virtual_meter_id = %s "
|
" FROM tbl_virtual_meter_hourly "
|
||||||
" AND start_datetime_utc >= %s "
|
" WHERE virtual_meter_id = %s "
|
||||||
" AND start_datetime_utc < %s ")
|
" AND start_datetime_utc >= %s "
|
||||||
cursor_energy.execute(query, (meta_result['links'][x]['meter']['id'],
|
" AND start_datetime_utc < %s ")
|
||||||
reporting_start_datetime_utc,
|
cursor_energy.execute(query, (meta_result['links'][x]['meter']['id'],
|
||||||
reporting_end_datetime_utc))
|
reporting_start_datetime_utc,
|
||||||
row = cursor_energy.fetchone()
|
reporting_end_datetime_utc))
|
||||||
if row is not None:
|
row = cursor_energy.fetchone()
|
||||||
meta_result['links'][x]['value'] = row[0]
|
if row is not None:
|
||||||
|
meta_result['links'][x]['value'] = row[0]
|
||||||
|
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 8: construct the report
|
# Step 8: construct the report
|
||||||
|
|
Loading…
Reference in New Issue