Skip to content
Snippets Groups Projects
Commit d9e03068 authored by Yoan VALLET's avatar Yoan VALLET
Browse files

fix: change max value for analysis chart display

parent b4ba96fd
No related branches found
No related tags found
1 merge request!296fix: change max value for analysis chart display
......@@ -31,39 +31,26 @@ const AnalysisConsumption: React.FC<AnalysisConsumptionProps> = ({
const [homePriceConsumption, setHomePriceConsumption] = useState<number>(0)
const [forecast, setForecast] = useState<MonthlyForecast | null>(null)
const [toggleHome, setToggleHome] = useState<string>('average')
const idealCoefficient = 0.1
const disconnectedFluidTypes: FluidType[] = [
FluidType.ELECTRICITY,
FluidType.WATER,
FluidType.GAS,
].filter(fluidType => !fluidTypes.includes(fluidType))
const getTotalValueWithConnectedFluids = useCallback(
(monthlyForecast: MonthlyForecast) => {
if (fluidTypes.length === 3) {
if (toggleHome === 'ideal') {
const idealPriceConsumption =
monthlyForecast.totalValue -
monthlyForecast.totalValue * idealCoefficient
setHomePriceConsumption(idealPriceConsumption)
} else {
setHomePriceConsumption(monthlyForecast.totalValue)
}
setHomePriceConsumption(monthlyForecast.totalValue)
} else {
let totalPrice = 0
fluidTypes.forEach(fluid => {
totalPrice += monthlyForecast.fluidForecast[fluid].value
})
if (toggleHome === 'ideal') {
const idealPriceConsumption =
totalPrice - totalPrice * idealCoefficient
setHomePriceConsumption(idealPriceConsumption)
} else {
setHomePriceConsumption(totalPrice)
}
setHomePriceConsumption(totalPrice)
}
},
[fluidTypes, toggleHome]
[fluidTypes]
)
const toggleAverage = () => {
setToggleHome('average')
......
......@@ -36,6 +36,10 @@ const AnalysisConsumptionRow: React.FC<AnalysisConsumptionRowProps> = ({
userPriceConsumption,
homePriceConsumption
)
const forecastPriceConsumption: number =
toggleHome === 'ideal'
? homePriceConsumption - homePriceConsumption * idealCoefficient
: homePriceConsumption
const fluidLoad: number =
forecast && fluid !== FluidType.MULTIFLUID
? forecast.fluidForecast[fluid].load
......@@ -61,7 +65,7 @@ const AnalysisConsumptionRow: React.FC<AnalysisConsumptionRowProps> = ({
const formatFluidConsumptionForForecast = (_fluid: FluidType) => {
if (_fluid === FluidType.MULTIFLUID) {
return `${formatNumberValues(homePriceConsumption).toString()} €`
return `${formatNumberValues(forecastPriceConsumption).toString()} €`
} else {
return (performanceValue && performanceValue >= 1000) || fluidLoad >= 1000
? formatNumberValues(fluidLoad / 1000).toString() +
......@@ -83,7 +87,7 @@ const AnalysisConsumptionRow: React.FC<AnalysisConsumptionRowProps> = ({
const getWidthForForecast = (_fluid: FluidType) => {
if (_fluid === FluidType.MULTIFLUID) {
return `${(homePriceConsumption / maxPriceConsumption) * 100}%`
return `${(forecastPriceConsumption / maxPriceConsumption) * 100}%`
} else {
let fluidValue: number = forecast
? forecast.fluidForecast[_fluid].value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment