summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/portfolios/PortfolioResults.js
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-09-14 14:23:02 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-09-20 16:07:05 +0200
commitb8f726cd84ee5b7b0816d04d802f53f0815f6d82 (patch)
tree793236ab58cf386d13e0f33be1ef6b1a0c7b812c /opendc-web/opendc-web-ui/src/components/portfolios/PortfolioResults.js
parent7da6543fb9c58736c2fa8c000b25290be4f78de4 (diff)
fix(web/ui): Only display selected metrics
This change fixes an issue with the web interface where all available metrics were shown to the user, instead of the metrics belonging to the portfolio.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/components/portfolios/PortfolioResults.js')
-rw-r--r--opendc-web/opendc-web-ui/src/components/portfolios/PortfolioResults.js38
1 files changed, 20 insertions, 18 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/portfolios/PortfolioResults.js b/opendc-web/opendc-web-ui/src/components/portfolios/PortfolioResults.js
index f63f0c7f..33604896 100644
--- a/opendc-web/opendc-web-ui/src/components/portfolios/PortfolioResults.js
+++ b/opendc-web/opendc-web-ui/src/components/portfolios/PortfolioResults.js
@@ -20,10 +20,10 @@
* SOFTWARE.
*/
-import React from 'react'
+import React, { useMemo } from 'react'
import PropTypes from 'prop-types'
import { Bar, CartesianGrid, ComposedChart, ErrorBar, ResponsiveContainer, Scatter, XAxis, YAxis } from 'recharts'
-import { AVAILABLE_METRICS, METRIC_NAMES, METRIC_UNITS } from '../../util/available-metrics'
+import { METRIC_NAMES, METRIC_UNITS } from '../../util/available-metrics'
import { mean, std } from 'mathjs'
import approx from 'approximate-number'
import {
@@ -46,10 +46,9 @@ import { usePortfolio } from '../../data/project'
import PortfolioResultInfo from './PortfolioResultInfo'
import NewScenario from './NewScenario'
-const PortfolioResults = ({ projectId, portfolioId }) => {
- const { status, data: scenarios = [] } = usePortfolio(projectId, portfolioId, {
- select: (portfolio) => portfolio.scenarios,
- })
+function PortfolioResults({ projectId, portfolioId }) {
+ const { status, data: portfolio } = usePortfolio(projectId, portfolioId)
+ const scenarios = portfolio?.scenarios ?? []
if (status === 'loading') {
return (
@@ -94,21 +93,24 @@ const PortfolioResults = ({ projectId, portfolioId }) => {
)
}
- const dataPerMetric = {}
-
- AVAILABLE_METRICS.forEach((metric) => {
- dataPerMetric[metric] = scenarios
- .filter((scenario) => scenario.job?.results)
- .map((scenario) => ({
- name: scenario.name,
- value: mean(scenario.job.results[metric]),
- errorX: std(scenario.job.results[metric]),
- }))
- })
+ const metrics = portfolio?.targets?.metrics ?? []
+ const dataPerMetric = useMemo(() => {
+ const dataPerMetric = {}
+ metrics.forEach((metric) => {
+ dataPerMetric[metric] = scenarios
+ .filter((scenario) => scenario.job?.results)
+ .map((scenario) => ({
+ name: scenario.name,
+ value: mean(scenario.job.results[metric]),
+ errorX: std(scenario.job.results[metric]),
+ }))
+ })
+ return dataPerMetric
+ }, [scenarios, metrics])
return (
<Grid hasGutter>
- {AVAILABLE_METRICS.map((metric) => (
+ {metrics.map((metric) => (
<GridItem xl={6} lg={12} key={metric}>
<Card>
<CardHeader>