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_SHORT, METRIC_UNITS } from '../../../util/available-metrics'
import { mean, std } from 'mathjs'
import Shapes from '../../../shapes/index'
import approx from 'approximate-number'
const PortfolioResultsComponent = ({ portfolio, scenarios }) => {
if (!portfolio) {
return
Loading...
}
const nonFinishedScenarios = scenarios.filter((s) => s.simulation.state !== 'FINISHED')
if (nonFinishedScenarios.length > 0) {
if (nonFinishedScenarios.every((s) => s.simulation.state === 'QUEUED' || s.simulation.state === 'RUNNING')) {
return (
Simulation running...
{nonFinishedScenarios.length} of the scenarios are still being simulated
)
}
if (nonFinishedScenarios.some((s) => s.simulation.state === 'FAILED')) {
return (
Simulation failed.
Try again by creating a new scenario. Please contact the OpenDC team for support, if issues
persist.
)
}
}
const dataPerMetric = {}
AVAILABLE_METRICS.forEach((metric) => {
dataPerMetric[metric] = scenarios.map((scenario) => ({
name: scenario.name,
value: mean(scenario.results[metric]),
errorX: std(scenario.results[metric]),
}))
})
return (
Portfolio: {portfolio.name}
Repeats per Scenario: {portfolio.targets.repeatsPerScenario}
{AVAILABLE_METRICS.map((metric) => (
{METRIC_NAMES_SHORT[metric]}
approx(tick)}
label={{ value: METRIC_UNITS[metric], position: 'bottom', offset: 0 }}
type="number"
/>
))}
)
}
PortfolioResultsComponent.propTypes = {
portfolio: Shapes.Portfolio,
scenarios: PropTypes.arrayOf(Shapes.Scenario),
}
export default PortfolioResultsComponent