Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nengyuanzhang committed May 6, 2024
2 parents 67e4cd0 + dd04fef commit cbdb72d
Show file tree
Hide file tree
Showing 11 changed files with 5,788 additions and 2,692 deletions.
5,687 changes: 4,137 additions & 1,550 deletions myems-api/MyEMS.postman_collection.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions myems-api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
from reports import energystoragepowerstationdetails
from reports import energystoragepowerstationlist
from reports import energystoragepowerstationreporting
from reports import energystoragepowerstationsenergy
from reports import energystoragepowerstationsbilling
from reports import energystoragepowerstationscarbon
from reports import fddfault
from reports import meterbatch
from reports import metercarbon
Expand Down Expand Up @@ -937,6 +940,12 @@
energystoragepowerstationlist.Reporting())
api.add_route('/reports/energystoragepowerstationreporting',
energystoragepowerstationreporting.Reporting())
api.add_route('/reports/energystoragepowerstationsenergy',
energystoragepowerstationsenergy.Reporting())
api.add_route('/reports/energystoragepowerstationsbilling',
energystoragepowerstationsbilling.Reporting())
api.add_route('/reports/energystoragepowerstationscarbon',
energystoragepowerstationscarbon.Reporting())
api.add_route('/reports/equipmentbatch',
equipmentbatch.Reporting())
api.add_route('/reports/equipmentcarbon',
Expand Down
208 changes: 145 additions & 63 deletions myems-api/reports/energystoragepowerstationdashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def on_options(req, resp):
# PROCEDURES
# Step 1: valid parameters
# Step 2: query the energy storage power station list
# Step 3: query charge data
# Step 4: query discharge data
# Step 5: query revenue data
# Step 6: query efficiency data
# Step 7: construct the report
# Step 3: query charge energy data
# Step 4: query discharge energy data
# Step 5: query charge billing data
# Step 6: query discharge billing data
# Step 7: query charge carbon data
# Step 8: query discharge carbon data
# Step 9: construct the report
####################################################################################################################
@staticmethod
def on_get(req, resp):
Expand Down Expand Up @@ -137,10 +139,8 @@ def on_get(req, resp):
################################################################################################################
# Step 2: query the energy storage power station list
################################################################################################################

cnx_user = mysql.connector.connect(**config.myems_user_db)
cursor_user = cnx_user.cursor()

cursor_user.execute(" SELECT id, is_admin, privilege_id "
" FROM tbl_users "
" WHERE uuid = %s ", (user_uuid,))
Expand All @@ -150,7 +150,6 @@ def on_get(req, resp):
cursor_user.close()
if cnx_user:
cnx_user.close()

raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.USER_NOT_FOUND')

Expand Down Expand Up @@ -215,54 +214,133 @@ def on_get(req, resp):
"description": row[9],
"status": 'online' if is_online else 'offline'}
energy_storage_power_station_list.append(meta_result)
charge_ranking = list()
if rows_energy_storage_power_stations is not None and len(rows_energy_storage_power_stations) > 0:
for row in rows_energy_storage_power_stations:
meta_result = {"id": row[0],
"name": row[1],
"uuid": row[2],
"value": Decimal(0.0)}
charge_ranking.append(meta_result)

discharge_ranking = list()
if rows_energy_storage_power_stations is not None and len(rows_energy_storage_power_stations) > 0:
for row in rows_energy_storage_power_stations:
meta_result = {"id": row[0],
"name": row[1],
"uuid": row[2],
"value": Decimal(0.0)}
discharge_ranking.append(meta_result)

revenue_ranking = list()
if rows_energy_storage_power_stations is not None and len(rows_energy_storage_power_stations) > 0:
for row in rows_energy_storage_power_stations:
meta_result = {"id": row[0],
"name": row[1],
"uuid": row[2],
"value": Decimal(0.0)}
revenue_ranking.append(meta_result)

################################################################################################################
# Step 3: query charge data
# Step 3: query charge energy data
################################################################################################################
cnx_energy = mysql.connector.connect(**config.myems_energy_db)
cursor_energy = cnx_energy.cursor()

cnx_billing = mysql.connector.connect(**config.myems_billing_db)
cursor_billing = cnx_billing.cursor()

cnx_energy_db = mysql.connector.connect(**config.myems_energy_db)
cursor_energy_db = cnx_energy_db.cursor()

cnx_billing_db = mysql.connector.connect(**config.myems_billing_db)
cursor_billing_db = cnx_billing_db.cursor()

cnx_carbon_db = mysql.connector.connect(**config.myems_billing_db)
cursor_carbon_db = cnx_carbon_db.cursor()

query = (" SELECT energy_storage_power_station_id, SUM(actual_value) "
" FROM tbl_energy_storage_power_station_charge_hourly "
" GROUP BY energy_storage_power_station_id ")
cursor_energy_db.execute(query, )
rows_energy_storage_power_stations_subtotal_charge_energy = cursor_energy_db.fetchall()

new_energy_storage_power_station_list = list()
total_charge_energy = Decimal(0.0)
for energy_storage_power_station in energy_storage_power_station_list:
energy_storage_power_station['subtotal_charge_energy'] = Decimal(0.0)
for row in rows_energy_storage_power_stations_subtotal_charge_energy:
if row[0] == energy_storage_power_station['id']:
energy_storage_power_station['subtotal_charge_energy'] = row[1]
total_charge_energy += energy_storage_power_station['subtotal_charge_energy']
break
new_energy_storage_power_station_list.append(energy_storage_power_station)
energy_storage_power_station_list = new_energy_storage_power_station_list
################################################################################################################
# Step 4: query discharge data
# Step 4: query discharge energy data
################################################################################################################

query = (" SELECT energy_storage_power_station_id, SUM(actual_value) "
" FROM tbl_energy_storage_power_station_discharge_hourly "
" GROUP BY energy_storage_power_station_id ")
cursor_energy_db.execute(query, )
rows_energy_storage_power_stations_subtotal_discharge_energy = cursor_energy_db.fetchall()

new_energy_storage_power_station_list = list()
total_discharge_energy = Decimal(0.0)
for energy_storage_power_station in energy_storage_power_station_list:
energy_storage_power_station['subtotal_discharge_energy'] = Decimal(0.0)
for row in rows_energy_storage_power_stations_subtotal_discharge_energy:
if row[0] == energy_storage_power_station['id']:
energy_storage_power_station['subtotal_discharge_energy'] = row[1]
total_discharge_energy += energy_storage_power_station['subtotal_discharge_energy']
break
new_energy_storage_power_station_list.append(energy_storage_power_station)
energy_storage_power_station_list = new_energy_storage_power_station_list
################################################################################################################
# Step 5: query revenue data
# Step 5: query charge billing data
################################################################################################################

query = (" SELECT energy_storage_power_station_id, SUM(actual_value) "
" FROM tbl_energy_storage_power_station_charge_hourly "
" GROUP BY energy_storage_power_station_id ")
cursor_billing_db.execute(query, )
rows_energy_storage_power_stations_subtotal_charge_billing = cursor_billing_db.fetchall()

new_energy_storage_power_station_list = list()
total_charge_billing = Decimal(0.0)
for energy_storage_power_station in energy_storage_power_station_list:
energy_storage_power_station['subtotal_charge_billing'] = Decimal(0.0)
for row in rows_energy_storage_power_stations_subtotal_charge_billing:
if row[0] == energy_storage_power_station['id']:
energy_storage_power_station['subtotal_charge_billing'] = row[1]
total_charge_billing += energy_storage_power_station['subtotal_charge_billing']
break
new_energy_storage_power_station_list.append(energy_storage_power_station)
energy_storage_power_station_list = new_energy_storage_power_station_list
################################################################################################################
# Step 6: query efficiency data
# Step 6: query discharge billing data
################################################################################################################

query = (" SELECT energy_storage_power_station_id, SUM(actual_value) "
" FROM tbl_energy_storage_power_station_discharge_hourly "
" GROUP BY energy_storage_power_station_id ")
cursor_billing_db.execute(query, )
rows_energy_storage_power_stations_subtotal_discharge_billing = cursor_billing_db.fetchall()

new_energy_storage_power_station_list = list()
total_discharge_billing = Decimal(0.0)
for energy_storage_power_station in energy_storage_power_station_list:
energy_storage_power_station['subtotal_discharge_billing'] = Decimal(0.0)
for row in rows_energy_storage_power_stations_subtotal_discharge_billing:
if row[0] == energy_storage_power_station['id']:
energy_storage_power_station['subtotal_discharge_billing'] = row[1]
total_discharge_billing += energy_storage_power_station['subtotal_discharge_billing']
break
new_energy_storage_power_station_list.append(energy_storage_power_station)
energy_storage_power_station_list = new_energy_storage_power_station_list
################################################################################################################
# Step 7: query charge carbon data
################################################################################################################
query = (" SELECT energy_storage_power_station_id, SUM(actual_value) "
" FROM tbl_energy_storage_power_station_charge_hourly "
" GROUP BY energy_storage_power_station_id ")
cursor_carbon_db.execute(query, )
rows_energy_storage_power_stations_subtotal_charge_carbon = cursor_carbon_db.fetchall()
new_energy_storage_power_station_list = list()
total_charge_carbon = Decimal(0.0)
for energy_storage_power_station in energy_storage_power_station_list:
energy_storage_power_station['subtotal_charge_carbon'] = Decimal(0.0)
for row in rows_energy_storage_power_stations_subtotal_charge_carbon:
if row[0] == energy_storage_power_station['id']:
energy_storage_power_station['subtotal_charge_carbon'] = row[1]
total_charge_carbon += energy_storage_power_station['subtotal_charge_carbon']
break
new_energy_storage_power_station_list.append(energy_storage_power_station)
energy_storage_power_station_list = new_energy_storage_power_station_list
################################################################################################################
# Step 8: query discharge carbon data
################################################################################################################
query = (" SELECT energy_storage_power_station_id, SUM(actual_value) "
" FROM tbl_energy_storage_power_station_discharge_hourly "
" GROUP BY energy_storage_power_station_id ")
cursor_carbon_db.execute(query, )
rows_energy_storage_power_stations_subtotal_discharge_carbon = cursor_carbon_db.fetchall()
new_energy_storage_power_station_list = list()
total_discharge_carbon = Decimal(0.0)
for energy_storage_power_station in energy_storage_power_station_list:
energy_storage_power_station['subtotal_discharge_carbon'] = Decimal(0.0)
for row in rows_energy_storage_power_stations_subtotal_discharge_carbon:
if row[0] == energy_storage_power_station['id']:
energy_storage_power_station['subtotal_discharge_carbon'] = row[1]
total_discharge_carbon += energy_storage_power_station['subtotal_discharge_carbon']
break
new_energy_storage_power_station_list.append(energy_storage_power_station)
energy_storage_power_station_list = new_energy_storage_power_station_list
################################################################################################################
# Step 7: construct the report
################################################################################################################
Expand All @@ -271,23 +349,27 @@ def on_get(req, resp):
if cnx_system_db:
cnx_system_db.close()

if cursor_energy:
cursor_energy.close()
if cnx_energy:
cnx_energy.close()
if cursor_energy_db:
cursor_energy_db.close()
if cnx_energy_db:
cnx_energy_db.close()

if cursor_billing:
cursor_billing.close()
if cnx_billing:
cnx_billing.close()
if cursor_billing_db:
cursor_billing_db.close()
if cnx_billing_db:
cnx_billing_db.close()

result = dict()
if cursor_carbon_db:
cursor_carbon_db.close()
if cnx_carbon_db:
cnx_carbon_db.close()

result = dict()
result['energy_storage_power_stations'] = energy_storage_power_station_list
result['charge_ranking'] = charge_ranking
result['total_charge'] = Decimal(0.0)
result['discharge_ranking'] = discharge_ranking
result['total_discharge'] = Decimal(0.0)
result['revenue_ranking'] = revenue_ranking
result['total_revenue'] = Decimal(0.0)
result['total_charge_energy'] = total_charge_energy
result['total_discharge_energy'] = total_discharge_energy
result['total_charge_billing'] = total_charge_billing
result['total_discharge_billing'] = total_discharge_billing
result['total_charge_carbon'] = total_charge_carbon
result['total_discharge_carbon'] = total_discharge_carbon
resp.text = json.dumps(result)

0 comments on commit cbdb72d

Please sign in to comment.