Commit 4118d749 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

Merge branch 'dev' of...

Merge branch 'dev' of https://forge.grandlyon.com/web-et-numerique/llle_project/ecolyo into feat/US695-rework-conso-min-elec-analysis
parents c1ebcaf1 a012c909
......@@ -49,12 +49,18 @@ const NoDataModal: React.FC<NoDataModalProps> = ({
<div className="text-16-normal">
{t('consumption_visualizer.dataModal.list_title')}
</div>
<div className="text-16-normal">
<div className="text-16-normal justified-text">
<span>&nbsp;</span>
{t('consumption_visualizer.dataModal.item1')}
</div>
<div className="text-16-normal">
<div className="text-16-normal justified-text">
<span>&nbsp;</span>
{t('consumption_visualizer.dataModal.item2')}
</div>
<div className="text-16-normal justified-text">
<span>&nbsp;</span>
{t('consumption_visualizer.dataModal.item3')}
</div>
<Button
aria-label={t('ecogesture_info_modal.button_close')}
onClick={handleCloseClick}
......
......@@ -16,4 +16,8 @@
text-align: center;
margin: 1rem 0;
}
.justified-text {
display: flex;
justify-content: start;
}
}
import mockClient from '../../../tests/__mocks__/client'
import FaqData from 'components/FAQ/FAQData'
import { allFluidPrices } from '../../../tests/__mocks__/fluidPrice.mock'
import { allLastFluidPrices } from '../../../tests/__mocks__/fluidPrice.mock'
import { FAQSection } from 'models'
jest.mock('cozy-ui/transpiled/react/I18n', () => {
......@@ -28,7 +28,7 @@ describe('FAQData', () => {
})
it('should return', async () => {
mockGetAllLastPrices.mockResolvedValue(allFluidPrices)
mockGetAllLastPrices.mockResolvedValue(allLastFluidPrices)
const result: FAQSection[] = await FaqData(mockClient)
expect(result.length).toBe(3)
})
......
......@@ -83,6 +83,66 @@
"startDate": "2021-08-01T00:00:00.000Z",
"endDate": null
},
{
"fluidType": 1,
"price": 0.0030735,
"startDate": "2012-01-01T00:00:00.000Z",
"endDate": "2012-12-31T23:59:59.000Z"
},
{
"fluidType": 1,
"price": 0.0031483,
"startDate": "2013-01-01T00:00:00.000Z",
"endDate": "2013-12-31T23:59:59.000Z"
},
{
"fluidType": 1,
"price": 0.0031381,
"startDate": "2014-01-01T00:00:00.000Z",
"endDate": "2014-12-31T23:59:59.000Z"
},
{
"fluidType": 1,
"price": 0.00307,
"startDate": "2015-01-01T00:00:00.000Z",
"endDate": "2015-12-31T23:59:59.000Z"
},
{
"fluidType": 1,
"price": 0.0031,
"startDate": "2016-01-01T00:00:00.000Z",
"endDate": "2016-12-31T23:59:59.000Z"
},
{
"fluidType": 1,
"price": 0.00311,
"startDate": "2017-01-01T00:00:00.000Z",
"endDate": "2017-12-31T23:59:59.000Z"
},
{
"fluidType": 1,
"price": 0.00313,
"startDate": "2018-01-01T00:00:00.000Z",
"endDate": "2018-12-31T23:59:59.000Z"
},
{
"fluidType": 1,
"price": 0.00313,
"startDate": "2019-01-01T00:00:00.000Z",
"endDate": "2019-12-31T23:59:59.000Z"
},
{
"fluidType": 1,
"price": 0.00315,
"startDate": "2020-01-01T00:00:00.000Z",
"endDate": "2020-12-31T23:59:59.000Z"
},
{
"fluidType": 1,
"price": 0.00319,
"startDate": "2021-01-01T00:00:00.000Z",
"endDate": null
},
{
"fluidType": 2,
"price": 0.0919,
......
......@@ -288,9 +288,10 @@
"aie": "Aïe !",
"estimated": "estimés",
"dataModal": {
"list_title": "2 raisons possibles :",
"item1": "- le lien entre Ecolyo et le fournisseur de données est rompu : une mise à jour de ce lien (en bas de la page) peut parfois résoudre ce problème.",
"item2": "- la mise à jour a été effectuée mais les données n'apparaissent toujours pas : le soucis vient du fournisseur de données (Enedis pour l'électricité, GRDF pour le gaz, Eau du Grand Lyon pour l'eau). Cela peut-être dû à un problème technique lié à votre compteur ou à leurs systèmes informatiques. Le mieux est de contacter directement ce partenaire pour tenter de régler le problème avec lui."
"list_title": "3 raisons possibles :",
"item1": "le lien entre Ecolyo et le fournisseur de données est rompu : une mise à jour de ce lien (en bas de la page) peut résoudre ce problème.",
"item2": "un problème technique chez votre gestionnaire : se connecter directement chez ce gestionnaire pour vérifier que cette donnée apparaît.",
"item3": "vous n'aviez tout simplement pas de compteur communicant à l'époque !"
},
"modal": {
"window_title": "info estimation des prix",
......
......@@ -15,11 +15,18 @@ import {
GRDF_YEAR_DOCTYPE,
ENEDIS_MONTHLY_ANALYSIS_DATA_DOCTYPE,
} from 'doctypes'
import { DataloadEntity, Profile, ProfileType, UserChallenge } from 'models'
import {
DataloadEntity,
FluidPrice,
Profile,
ProfileType,
UserChallenge,
} from 'models'
import { Client } from 'cozy-client'
import { DateTime } from 'luxon'
import { UserQuizState } from 'enum/userQuiz.enum'
import fluidsPricesData from 'db/fluidPrices.json'
import { FluidType } from 'enum/fluid.enum'
export const SCHEMA_INITIAL_VERSION = 0
......@@ -490,6 +497,28 @@ export const migrations: Migration[] = [
baseSchemaVersion: 17,
targetSchemaVersion: 18,
appVersion: '1.7.0',
description: 'Init new fluidPrices for water',
releaseNotes: null,
docTypes: FLUIDPRICES_DOCTYPE,
run: async (_client: Client, docs: any[]): Promise<any> => {
const waterPricesData: any[] = fluidsPricesData.filter(fluidPriceData => {
return fluidPriceData.fluidType === FluidType.WATER
})
const createWaterPricesData = waterPricesData.map(
(waterPriceData: any) => {
waterPriceData.createAction = true
waterPriceData.doctype = FLUIDPRICES_DOCTYPE
return waterPriceData
}
)
return createWaterPricesData
},
},
{
baseSchemaVersion: 18,
targetSchemaVersion: 19,
appVersion: '1.7.0',
description:
'Empty the doctype com.grandlyon.enedis.monthly.analysis.data, so the service will run again with the new calculation',
releaseNotes: null,
......
......@@ -87,6 +87,8 @@ async function save(_client: Client, docs: any[]): Promise<MigrationResult> {
docs.forEach(async doc => {
if (doc.deleteAction) {
await _client.destroy(doc)
} else if (doc.createAction) {
await _client.create(doc.doctype, doc)
} else {
await _client.save(doc)
}
......
......@@ -2,7 +2,10 @@ import FluidPricesService from './fluidsPrices.service'
import mockClient from '../../tests/__mocks__/client'
import { QueryResult } from 'cozy-client'
import { FluidPrice } from 'models'
import { fluidPrices } from '../../tests/__mocks__/fluidPrice.mock'
import {
fluidPrices,
allLastFluidPrices,
} from '../../tests/__mocks__/fluidPrice.mock'
import { FluidType } from 'enum/fluid.enum'
import { DateTime } from 'luxon'
......@@ -60,4 +63,59 @@ describe('FluidPrices service', () => {
expect(mockClient.query).toBeCalled()
})
})
describe('Fluid Prices - getAllLastPrices', () => {
it('should getAllLastPrice', async () => {
const mockQueryResult: QueryResult<FluidPrice[]> = {
data: fluidPrices,
bookmark: '',
next: false,
skip: 0,
}
mockClient.query.mockResolvedValueOnce(mockQueryResult)
const prices = await fluidPricesService.getAllLastPrices()
console.log('Prix reçus :', prices)
console.log('Prix attendus :', allLastFluidPrices)
expect(prices).toStrictEqual(allLastFluidPrices)
expect(mockClient.query).toBeCalled()
})
})
describe('Fluid Prices - deleteAllFluidsPrices', () => {
it('should return true when fluidsPrices stored', async () => {
const mockQueryResult: QueryResult<FluidPrice[]> = {
data: fluidPrices,
bookmark: '',
next: false,
skip: 0,
}
mockClient.query.mockResolvedValueOnce(mockQueryResult)
const result = await fluidPricesService.deleteAllFluidsPrices()
expect(mockClient.destroy).toBeCalledTimes(6)
expect(result).toBe(true)
})
it('should return true when no fluidsPrices stored', async () => {
const mockQueryResult: QueryResult<FluidPrice[]> = {
data: [],
bookmark: '',
next: false,
skip: 0,
}
mockClient.query.mockResolvedValueOnce(mockQueryResult)
const result = await fluidPricesService.deleteAllFluidsPrices()
expect(result).toBe(true)
})
it('should return false when error happened on deletion', async () => {
const mockQueryResult: QueryResult<FluidPrice[]> = {
data: fluidPrices,
bookmark: '',
next: false,
skip: 0,
}
mockClient.destroy.mockRejectedValue(new Error())
mockClient.query.mockResolvedValueOnce(mockQueryResult)
const result = await fluidPricesService.deleteAllFluidsPrices()
expect(result).toBe(false)
})
})
})
......@@ -85,4 +85,21 @@ export default class FluidPricesService {
return fluidsPrices
}
/**
* Delete all fluidPrices entities from the db
* @returns {boolean} - true when deleted with success
* @throws {Error}
*/
public async deleteAllFluidsPrices(): Promise<boolean> {
const fluidsPrices = await this.getAllPrices()
try {
for (let index = 0; index < fluidsPrices.length; index++) {
await this._client.destroy(fluidsPrices[index])
}
return true
} catch (error) {
return false
}
}
}
......@@ -6,11 +6,7 @@ import FluidPricesService from 'services/fluidsPrices.service'
import { DataloadEntity, TimePeriod } from 'models'
import ConsumptionDataManager from 'services/consumption.service'
import { TimeStep } from 'enum/timeStep.enum'
import {
ENEDIS_DAY_DOCTYPE,
ENEDIS_MINUTE_DOCTYPE,
GRDF_DAY_DOCTYPE,
} from 'doctypes'
import { ENEDIS_DAY_DOCTYPE, GRDF_DAY_DOCTYPE, EGL_DAY_DOCTYPE } from 'doctypes'
import { FluidType } from 'enum/fluid.enum'
import QueryRunner from 'services/queryRunner.service'
const log = logger.namespace('fluidPrices')
......@@ -64,7 +60,7 @@ const aggregatePrices = async (
) => {
const tsa = [TimeStep.MONTH, TimeStep.YEAR]
log('debug', `Aggregation...`)
const aggregartePromises = tsa.map(async ts => {
const aggregatePromises = tsa.map(async ts => {
return new Promise<void>(async resolve => {
let date: DateTime = DateTime.local()
Object.assign(date, firstDate)
......@@ -97,7 +93,7 @@ const aggregatePrices = async (
})
})
await Promise.all(aggregartePromises)
await Promise.all(aggregatePromises)
log('debug', `Aggregation done`)
}
......@@ -108,6 +104,9 @@ const getDoctypeTypeByFluid = (fluidType: FluidType): string => {
if (fluidType === FluidType.GAS) {
return GRDF_DAY_DOCTYPE
}
if (fluidType === FluidType.WATER) {
return EGL_DAY_DOCTYPE
}
log('error', 'Unkown FluidType')
throw new Error()
}
......@@ -116,9 +115,10 @@ const getTimeSetByFluid = (fluidType: FluidType): TimeStep[] => {
if (fluidType === FluidType.ELECTRICITY) {
return [TimeStep.DAY, TimeStep.HALF_AN_HOUR]
}
if (fluidType === FluidType.GAS) {
if (fluidType === FluidType.GAS || fluidType === FluidType.WATER) {
return [TimeStep.DAY]
}
log('error', 'Unkown FluidType')
throw new Error()
}
......@@ -204,8 +204,12 @@ const processPrices = async ({ client }: PricesProps) => {
log('info', `Electricity data done`)
log('info', `Processing gas data...`)
const gas = applyPrices(client, FluidType.GAS)
await Promise.all([elec, gas])
log('info', `Gas data done`)
log('info', `Processing water data...`)
const water = applyPrices(client, FluidType.WATER)
log('info', `Water data done`)
await Promise.all([elec, gas, water])
log('info', `processPrices done`)
}
runService(processPrices)
......@@ -17,11 +17,18 @@ export const fluidPrices: FluidPrice[] = [
},
{
_id: '03045ea1afecc7a86e5443a52e00b07d',
endDate: '2021-10-31T23:59:59.000Z',
endDate: '',
fluidType: 0,
price: 0.1329,
startDate: '2021-10-10T00:00:00.000Z',
},
{
_id: '03045ea1afecc7a86e5443a52e00b07d',
endDate: '',
fluidType: 1,
price: 0.0039,
startDate: '2013-08-01T00:00:00.000Z',
},
{
_id: '03045ea1afecc7a86e5443a52e00b07d',
endDate: '2014-10-31T23:59:59.000Z',
......@@ -29,28 +36,35 @@ export const fluidPrices: FluidPrice[] = [
price: 1.029,
startDate: '2013-08-01T00:00:00.000Z',
},
{
_id: '03045ea1afecc7a86e5443a52e00b07d',
endDate: '',
fluidType: 2,
price: 1.029,
startDate: '2014-11-01T00:00:00.000Z',
},
]
export const allFluidPrices: FluidPrice[] = [
export const allLastFluidPrices: FluidPrice[] = [
{
_id: '03045ea1afecc7a86e5443a52e00b07d',
endDate: '',
fluidType: 0,
price: 0.1429,
startDate: '2020-08-01T00:00:00.000Z',
price: 0.1329,
startDate: '2021-10-10T00:00:00.000Z',
},
{
_id: '03045ea1afecc7a86e5443a52e00b07d',
endDate: '',
fluidType: 1,
price: 0.1529,
startDate: '2021-01-01T00:00:00.000Z',
price: 0.0039,
startDate: '2013-08-01T00:00:00.000Z',
},
{
_id: '03045ea1afecc7a86e5443a52e00b07d',
endDate: '',
fluidType: 2,
price: 0.1329,
startDate: '2021-10-10T00:00:00.000Z',
price: 1.029,
startDate: '2014-11-01T00:00:00.000Z',
},
]
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