Commit fe9f2123 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

fix(Analysis): Fix analysis navigation and bad month issue

- the december month now shows a proper comparison analysis instead of NaN
parent 758b9fb5
...@@ -82,7 +82,7 @@ const AnalysisConsumption: React.FC<AnalysisConsumptionProps> = ({ ...@@ -82,7 +82,7 @@ const AnalysisConsumption: React.FC<AnalysisConsumptionProps> = ({
analysisDate.year analysisDate.year
) )
const monthlyForecast: MonthlyForecast = await profileTypeService.getMonthlyForecast( const monthlyForecast: MonthlyForecast = await profileTypeService.getMonthlyForecast(
analysisDate.month - 1 analysisDate.minus({ month: 1 }).startOf('month').month
) )
if (subscribed) { if (subscribed) {
setForecast(monthlyForecast) setForecast(monthlyForecast)
......
...@@ -24,7 +24,6 @@ const LastDataConsumptionVisualizer: React.FC<LastDataConsumptionVisualizerProps ...@@ -24,7 +24,6 @@ const LastDataConsumptionVisualizer: React.FC<LastDataConsumptionVisualizerProps
) )
const moveToDate = () => { const moveToDate = () => {
console.log(fluidType)
if (lastDataDate) { if (lastDataDate) {
const dateChartService = new DateChartService() const dateChartService = new DateChartService()
const updatedIndex: number = dateChartService.defineDateIndex( const updatedIndex: number = dateChartService.defineDateIndex(
......
...@@ -8,7 +8,7 @@ import { DateTime } from 'luxon' ...@@ -8,7 +8,7 @@ import { DateTime } from 'luxon'
import classNames from 'classnames' import classNames from 'classnames'
import DateChartService from 'services/dateChart.service' import DateChartService from 'services/dateChart.service'
import { isLastDateReached, isLastPeriodReached } from 'utils/date' import { isLastDateReached } from 'utils/date'
import DateNavigatorFormat from 'components/DateNavigator/DateNavigatorFormat' import DateNavigatorFormat from 'components/DateNavigator/DateNavigatorFormat'
import LeftArrowIcon from 'assets/icons/ico/left-arrow.svg' import LeftArrowIcon from 'assets/icons/ico/left-arrow.svg'
...@@ -43,10 +43,7 @@ const DateNavigator: React.FC<DateNavigatorProps> = ({ ...@@ -43,10 +43,7 @@ const DateNavigator: React.FC<DateNavigatorProps> = ({
const disableNext: boolean = currentAnalysisDate const disableNext: boolean = currentAnalysisDate
? isLastDateReached(currentAnalysisDate, TimeStep.MONTH) ? isLastDateReached(currentAnalysisDate, TimeStep.MONTH)
: isLastDateReached(selectedDate, currentTimeStep) : isLastDateReached(selectedDate, currentTimeStep)
const disableNextSlide: boolean = isLastPeriodReached(
selectedDate,
currentTimeStep
)
const dateChartService = new DateChartService() const dateChartService = new DateChartService()
const handleClickMove = (increment: number) => { const handleClickMove = (increment: number) => {
...@@ -79,21 +76,21 @@ const DateNavigator: React.FC<DateNavigatorProps> = ({ ...@@ -79,21 +76,21 @@ const DateNavigator: React.FC<DateNavigatorProps> = ({
selectedDate, selectedDate,
currentIndex currentIndex
) )
handleClickMove(increment) if (currentAnalysisDate) {
handleClickMove(-1)
} else handleClickMove(increment)
} }
} }
const handleChangeNextIndex = () => { const handleChangeNextIndex = () => {
console.log(!isKonnectorActive(fluidStatus, FluidType.MULTIFLUID)) if (!disableNext && isKonnectorActive(fluidStatus, FluidType.MULTIFLUID)) {
if (
!disableNextSlide &&
isKonnectorActive(fluidStatus, FluidType.MULTIFLUID)
) {
const increment: number = dateChartService.defineIncrementForNextIndex( const increment: number = dateChartService.defineIncrementForNextIndex(
currentTimeStep, currentTimeStep,
selectedDate, selectedDate,
currentIndex currentIndex
) )
handleClickMove(increment) if (currentAnalysisDate) {
handleClickMove(1)
} else handleClickMove(increment)
} }
} }
......
...@@ -79,7 +79,7 @@ describe('TotalConsumption component', () => { ...@@ -79,7 +79,7 @@ describe('TotalConsumption component', () => {
.find('.euro-value') .find('.euro-value')
.first() .first()
.text() .text()
).toEqual('20,23') ).toEqual('20,38')
}) })
it('should format multifluid value', async () => { it('should format multifluid value', async () => {
const component = mount( const component = mount(
......
...@@ -126,21 +126,13 @@ describe('Consumption service', () => { ...@@ -126,21 +126,13 @@ describe('Consumption service', () => {
actualData: [ actualData: [
{ {
date: DateTime.fromISO('2020-10-01T00:00:00.000Z'), date: DateTime.fromISO('2020-10-01T00:00:00.000Z'),
value: 69.18029999999999, value: 79.131171,
valueDetail: [ valueDetail: [45.478019999999994, 0.931161, 32.72199],
45.127739999999996,
0.9048899999999999,
23.147669999999998,
],
}, },
{ {
date: DateTime.fromISO('2020-10-02T00:00:00.000Z'), date: DateTime.fromISO('2020-10-02T00:00:00.000Z'),
value: 61.65554999999999, value: 70.5240635,
valueDetail: [ valueDetail: [40.531369999999995, 0.8298785, 29.162815],
40.21918999999999,
0.8064649999999999,
20.629894999999998,
],
}, },
{ {
date: DateTime.fromISO('2020-10-03T00:00:00.000Z'), date: DateTime.fromISO('2020-10-03T00:00:00.000Z'),
...@@ -151,13 +143,13 @@ describe('Consumption service', () => { ...@@ -151,13 +143,13 @@ describe('Consumption service', () => {
comparisonData: [ comparisonData: [
{ {
date: DateTime.fromISO('2020-09-01T00:00:00.000Z'), date: DateTime.fromISO('2020-09-01T00:00:00.000Z'),
value: 54.090509999999995, value: 61.8708707,
valueDetail: [35.284358, 0.707513, 18.098639], valueDetail: [35.558234, 0.7280537, 25.584583],
}, },
{ {
date: DateTime.fromISO('2020-09-02T00:00:00.000Z'), date: DateTime.fromISO('2020-09-02T00:00:00.000Z'),
value: 56.57427, value: 64.7118939,
valueDetail: [36.904565999999996, 0.740001, 18.929703], valueDetail: [37.191018, 0.7614849, 26.759391],
}, },
{ {
date: DateTime.fromISO('2020-09-03T00:00:00.000Z'), date: DateTime.fromISO('2020-09-03T00:00:00.000Z'),
...@@ -180,21 +172,13 @@ describe('Consumption service', () => { ...@@ -180,21 +172,13 @@ describe('Consumption service', () => {
actualData: [ actualData: [
{ {
date: DateTime.fromISO('2020-10-01T00:00:00.000Z'), date: DateTime.fromISO('2020-10-01T00:00:00.000Z'),
value: 69.18029999999999, value: 79.131171,
valueDetail: [ valueDetail: [45.478019999999994, 0.931161, 32.72199],
45.127739999999996,
0.9048899999999999,
23.147669999999998,
],
}, },
{ {
date: DateTime.fromISO('2020-10-02T00:00:00.000Z'), date: DateTime.fromISO('2020-10-02T00:00:00.000Z'),
value: 61.65554999999999, value: 70.5240635,
valueDetail: [ valueDetail: [40.531369999999995, 0.8298785, 29.162815],
40.21918999999999,
0.8064649999999999,
20.629894999999998,
],
}, },
{ {
date: DateTime.fromISO('2020-10-03T00:00:00.000Z'), date: DateTime.fromISO('2020-10-03T00:00:00.000Z'),
...@@ -246,7 +230,7 @@ describe('Consumption service', () => { ...@@ -246,7 +230,7 @@ describe('Consumption service', () => {
mockFetchFluidData.mockResolvedValueOnce(mockFetchDataActual) mockFetchFluidData.mockResolvedValueOnce(mockFetchDataActual)
mockFetchFluidData.mockResolvedValueOnce(mockFetchDataComparison) mockFetchFluidData.mockResolvedValueOnce(mockFetchDataComparison)
} }
const expectedResult = 69.18029999999999 const expectedResult = 79.131171
const result = await consumptionDataManager.getMaxLoad( const result = await consumptionDataManager.getMaxLoad(
mockTimePeriod, mockTimePeriod,
TimeStep.DAY, TimeStep.DAY,
......
...@@ -24,9 +24,9 @@ describe('performanceIndicator service', () => { ...@@ -24,9 +24,9 @@ describe('performanceIndicator service', () => {
it('should return the current timePeriod and the comparison timePeriod for all timeStep', () => { it('should return the current timePeriod and the comparison timePeriod for all timeStep', () => {
let expectedResult: PerformanceIndicator = { let expectedResult: PerformanceIndicator = {
value: 4.445499999999999, value: 5.6091,
compareValue: 6.5084, compareValue: 7.30015,
percentageVariation: 0.3169596214123288, percentageVariation: 0.23164592508373127,
} }
let result = performanceIndicatorService.aggregatePerformanceIndicators( let result = performanceIndicatorService.aggregatePerformanceIndicators(
performanceIndicator performanceIndicator
...@@ -47,9 +47,9 @@ describe('performanceIndicator service', () => { ...@@ -47,9 +47,9 @@ describe('performanceIndicator service', () => {
}, },
] ]
expectedResult = { expectedResult = {
value: 1.67, value: 1.6855999999999998,
compareValue: 4.6845, compareValue: 4.72185,
percentageVariation: 0.6435051766463871, percentageVariation: 0.6430212734415537,
} }
result = performanceIndicatorService.aggregatePerformanceIndicators( result = performanceIndicatorService.aggregatePerformanceIndicators(
performanceIndicator performanceIndicator
...@@ -75,9 +75,9 @@ describe('performanceIndicator service', () => { ...@@ -75,9 +75,9 @@ describe('performanceIndicator service', () => {
}, },
] ]
expectedResult = { expectedResult = {
compareValue: 6.5084, compareValue: 7.30015,
percentageVariation: 0.5544988015487677, percentageVariation: 0.44506619726991914,
value: 2.8994999999999997, value: 4.0511,
} }
result = performanceIndicatorService.aggregatePerformanceIndicators( result = performanceIndicatorService.aggregatePerformanceIndicators(
performanceIndicator performanceIndicator
...@@ -103,7 +103,7 @@ describe('performanceIndicator service', () => { ...@@ -103,7 +103,7 @@ describe('performanceIndicator service', () => {
}, },
] ]
expectedResult = { expectedResult = {
value: 7.5375, value: 8.7251,
compareValue: 0, compareValue: 0,
percentageVariation: -Infinity, percentageVariation: -Infinity,
} }
...@@ -121,7 +121,7 @@ describe('performanceIndicator service', () => { ...@@ -121,7 +121,7 @@ describe('performanceIndicator service', () => {
}, },
] ]
expectedResult = { expectedResult = {
value: 4.638, value: 4.6739999999999995,
compareValue: 0, compareValue: 0,
percentageVariation: -Infinity, percentageVariation: -Infinity,
} }
...@@ -140,7 +140,7 @@ describe('performanceIndicator service', () => { ...@@ -140,7 +140,7 @@ describe('performanceIndicator service', () => {
] ]
expectedResult = { expectedResult = {
value: 0, value: 0,
compareValue: 2.319, compareValue: 2.3369999999999997,
percentageVariation: 1, percentageVariation: 1,
} }
result = performanceIndicatorService.aggregatePerformanceIndicators( result = performanceIndicatorService.aggregatePerformanceIndicators(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment