提交 dd04fef2 编写于 作者: nengyuangzhang's avatar nengyuangzhang

updated energy storage power station dashboard

上级 b6cb3d6b
......@@ -44,6 +44,9 @@ from reports import energystoragepowerstationsingledashboard
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
......@@ -937,6 +940,12 @@ api.add_route('/reports/energystoragepowerstationlist',
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',
......
......@@ -21,11 +21,13 @@ class Reporting:
# 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):
......@@ -137,10 +139,8 @@ class Reporting:
################################################################################################################
# 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,))
......@@ -150,7 +150,6 @@ class Reporting:
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')
......@@ -215,54 +214,133 @@ class Reporting:
"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
################################################################################################################
......@@ -271,23 +349,27 @@ class Reporting:
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)
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -31,7 +31,6 @@ class Reporting:
####################################################################################################################
@staticmethod
def on_get(req, resp):
# todo: change this procedure from space to microgrid
if 'API-KEY' not in req.headers or \
not isinstance(req.headers['API-KEY'], str) or \
len(str.strip(req.headers['API-KEY'])) == 0:
......
......@@ -161,7 +161,7 @@ const EnergyStoragePowerStationListItem = ({
</p>
</div>
<div className="mt-md-2">
<ButtonIcon
{/* <ButtonIcon
color="primary"
size="sm"
icon="tv"
......@@ -202,7 +202,7 @@ const EnergyStoragePowerStationListItem = ({
onClick={handleAddToCart}
>
{t('Maintenance')}
</ButtonIcon>
</ButtonIcon> */}
</div>
</Col>
</Row>
......
......@@ -142,7 +142,7 @@ const selectRow = onSelect => ({
sort: true
},
{
dataField: 'total_charge',
dataField: 'subtotal_charge_energy',
text: t('Total Charge'),
formatter: energyFormatter,
classes: 'border-0 align-middle',
......@@ -150,7 +150,7 @@ const selectRow = onSelect => ({
sort: true,
},
{
dataField: 'total_discharge',
dataField: 'subtotal_discharge_energy',
text: t('Total Discharge'),
formatter: energyFormatter,
classes: 'border-0 align-middle',
......@@ -158,7 +158,7 @@ const selectRow = onSelect => ({
sort: true,
},
{
dataField: 'total_revenue',
dataField: 'subtotal_discharge_billing',
text: t('Total Revenue'),
formatter: currencyFormatter,
classes: 'border-0 align-middle',
......
......@@ -17,9 +17,8 @@ import AppContext from '../../../context/Context';
ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend, LogarithmicScale);
const StackBarChart = ({ labels, chargeData, dischargeData, stations, t }) => {
const StackBarChart = ({ labels, chargeData, dischargeData, periodTypes, t }) => {
const colors = ['#2c7be5', '#00d27a', '#27bcfd', '#f5803e', '#e63757'];
const [selectedLabel, setSelectedLabel] = useState('a0');
const [option, setOption] = useState('a0');
const { isDark } = useContext(AppContext);
const chartRef = useRef(null);
......@@ -39,41 +38,32 @@ const StackBarChart = ({ labels, chargeData, dischargeData, stations, t }) => {
gradientFill.addColorStop(0, isDark ? 'rgba(44,123,229, 0.5)' : 'rgba(255, 255, 255, 0.3)');
gradientFill.addColorStop(1, isDark ? 'transparent' : 'rgba(255, 255, 255, 0)');
if (chargeData['subtotals_array'] !== undefined && chargeData['subtotals_array'].length > 0) {
let category = t('CATEGORY Consumption UNIT', {
CATEGORY: chargeData['energy_category_names'][index],
UNIT: chargeData['units'][index]
});
let stationArray = chargeData['station_names_array'][index];
chargeData['subtotals_array'][index].forEach((item, itemIndex) => {
dataArray.push({
label: stationArray[itemIndex] + ' ' + category,
stack: category,
label: chargeData['station_names_array'][itemIndex] + ' ' + t('Charge UNIT', { UNIT: chargeData['unit'] }),
stack: t('Charge UNIT', { UNIT: chargeData['unit'] }),
data: item,
backgroundColor: colors[itemIndex % 5]
});
});
}
if (dischargeData['subtotals_array'] !== undefined && dischargeData['subtotals_array'].length > 0) {
let category = t('CATEGORY Costs UNIT', {
CATEGORY: dischargeData['energy_category_names'][index],
UNIT: dischargeData['units'][index]
});
let stationArray = dischargeData['station_names_array'][index];
dischargeData['subtotals_array'][index].forEach((item, itemIndex) => {
dataArray.push({
label: stationArray[itemIndex] + ' ' + category,
stack: category,
label: dischargeData['station_names_array'][itemIndex] + ' ' + t('Discharge UNIT', { UNIT: dischargeData['unit'] }),
stack: t('Discharge UNIT', { UNIT: dischargeData['unit'] }),
data: item,
backgroundColor: colors[itemIndex % 5]
});
});
}
setChartData({
labels: labels,
labels: labels[index],
datasets: dataArray
});
}
}, [labels, chargeData, dischargeData, option]);
const options = {
scales: {
x: {
......@@ -106,6 +96,7 @@ const StackBarChart = ({ labels, chargeData, dischargeData, stations, t }) => {
mode: 'x'
}
};
return (
<Fragment>
<Card className="mb-3">
......@@ -114,7 +105,7 @@ const StackBarChart = ({ labels, chargeData, dischargeData, stations, t }) => {
<Col>
<h4 className="text-lightSlateGray mb-0" />
</Col>
{isIterableArray(stations) && (
{isIterableArray(periodTypes) && (
<Col xs="auto" className="d-none d-sm-block">
<CustomInput
id="ddd"
......@@ -124,10 +115,9 @@ const StackBarChart = ({ labels, chargeData, dischargeData, stations, t }) => {
value={option}
onChange={({ target }) => {
setOption(target.value);
setSelectedLabel(target.value);
}}
>
{stations.map(({ value, label }) => (
{periodTypes.map(({ value, label }) => (
<option key={value} value={value}>
{label}
</option>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册