/*
* Copyright (c) 2021 AtLarge Research
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React 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 { mean, std } from 'mathjs'
import approx from 'approximate-number'
import {
Bullseye,
Card,
CardActions,
CardBody,
CardHeader,
CardTitle,
EmptyState,
EmptyStateBody,
EmptyStateIcon,
Grid,
GridItem,
Spinner,
Title,
} from '@patternfly/react-core'
import { ErrorCircleOIcon, CubesIcon } from '@patternfly/react-icons'
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,
})
if (status === 'loading') {
return (
Loading Results
)
} else if (status === 'error') {
return (
Unable to connect
There was an error retrieving data. Check your connection and try again.
)
} else if (scenarios.length === 0) {
return (
No results
No results are currently available for this portfolio. Run a scenario to obtain simulation
results.
)
}
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]),
}))
})
return (
{AVAILABLE_METRICS.map((metric) => (
{METRIC_NAMES[metric]}
approx(tick)}
label={{ value: METRIC_UNITS[metric], position: 'bottom', offset: 0 }}
type="number"
/>
))}
)
}
PortfolioResults.propTypes = {
projectId: PropTypes.number,
portfolioId: PropTypes.number,
}
export default PortfolioResults