From 50d1c024612010e1d154bfad69f717a31fd25aa5 Mon Sep 17 00:00:00 2001 From: git-directory-deploy <> Date: Tue, 8 Mar 2022 17:39:22 +0100 Subject: [PATCH] remove logs --- src/targets/services/fluidsPrices.ts | 71 ++++++++++------------------ 1 file changed, 24 insertions(+), 47 deletions(-) diff --git a/src/targets/services/fluidsPrices.ts b/src/targets/services/fluidsPrices.ts index bb0b4acb9..4096d459a 100644 --- a/src/targets/services/fluidsPrices.ts +++ b/src/targets/services/fluidsPrices.ts @@ -56,10 +56,7 @@ const synchroPricesToUpdate = async ( remotePrice.UpdatedAt && existingPrice.UpdatedAt < remotePrice.UpdatedAt ) { - log( - 'info', - `Price exist in db but not up to date, updating ${existingPrice}` - ) + log('info', `Price exist in db but not up to date, updating it`) //If a price has been updated, set the oldest startDate of the edited price so we can redo aggregation if (firstEditedPrice === null) { firstEditedPrice = remotePrice.startDate @@ -67,10 +64,6 @@ const synchroPricesToUpdate = async ( if (firstEditedPrice >= remotePrice.startDate) { firstEditedPrice = remotePrice.startDate } - log( - 'debug', - `firstEditedPrice ${firstEditedPrice}, fluidTypeeee : ${fluidType}` - ) //update this price in db await fps.updatePrice(existingPrice, { @@ -108,10 +101,7 @@ const price = (item: DataloadEntity): number => { } const sum = (prev: number, next: number): number => { - if (prev) { - return prev + next - } - return next + return prev + next } const getTimePeriod = async ( @@ -160,10 +150,6 @@ const aggregatePrices = async ( Object.assign(date, firstDate) try { do { - log( - 'info', - `Step: ${ts} | Fluid: ${fluidType} | Date: ${date.day}/${date.month}/${date.year}` - ) const tp = await getTimePeriod(ts, date) // Get doc for aggregation const data = await qr.fetchFluidRawDoctype( @@ -171,25 +157,14 @@ const aggregatePrices = async ( TimeStep.DAY, fluidType ) - log( - 'info', - `DATAAAAAA: ${JSON.stringify(data)} for PERIOD : ${JSON.stringify( - tp - )} Date: ${date.day}/${date.month}/${ - date.year - } for TIMESTEP ${ts}` - ) - // Get doc to update const docToUpdate = await qr.fetchFluidRawDoctype(tp, ts, fluidType) - log('info', `docToUpdateEEEE: ${JSON.stringify(docToUpdate)}`) if (docToUpdate && data && docToUpdate.data && data.data) { docToUpdate.data[0].price = data.data.map(price).reduce(sum) - // Save updated docs - await cdm.saveDocs(docToUpdate.data) } - + // Save updated docs + await cdm.saveDocs(docToUpdate.data) // Update date according to timestep if (ts === TimeStep.YEAR) { date = date.plus({ year: 1 }).startOf('month') @@ -198,7 +173,7 @@ const aggregatePrices = async ( } } while (date < today) } catch (err) { - log('error', `Error : ${err}`) + log('info', `Error : ${err}`) } finally { resolve() } @@ -242,8 +217,7 @@ const applyPrices = async (client: Client, fluidType: FluidType) => { //Synchro dbprices with remote prices const firstEditedPriceDate = await synchroPricesToUpdate(client, fluidType) - log('debug', `Startdate of First edited price: ${firstEditedPriceDate}`) - + const firstDataDate = await cdm.fetchAllFirstDateData([fluidType]) const prices = await fluidsPricesService.getAllPrices() // Prices data exsit if (prices.length > 0) { @@ -254,10 +228,15 @@ const applyPrices = async (client: Client, fluidType: FluidType) => { // const firstDoctypeData = await cdm.getFirsDataDateFromDoctype() // If there is data, update hourly data and daily data - if (firstMinuteData || firstEditedPriceDate !== null) { + if ( + firstDataDate && + firstDataDate[0] && + (firstMinuteData || firstEditedPriceDate !== null) + ) { const today = DateTime.now() const tsa = getTimeSetByFluid(fluidType) let firstDate: DateTime + if (firstMinuteData && firstEditedPriceDate) { // If there is first data without price and a price edited, set the smallest date const firstMinuteDataDate = DateTime.fromObject({ @@ -272,7 +251,11 @@ const applyPrices = async (client: Client, fluidType: FluidType) => { ).setZone('utc', { keepLocalTime: true, }) - firstDate = DateTime.min(formattedFirstEditedPrice, firstMinuteDataDate) + // we want to exclude the period with no data if the edited date is smaller than the first data date + firstDate = DateTime.min( + DateTime.max(formattedFirstEditedPrice, firstDataDate[0]), + firstMinuteDataDate + ) } else if (firstMinuteData) { firstDate = DateTime.fromObject({ year: firstMinuteData.year, @@ -282,9 +265,12 @@ const applyPrices = async (client: Client, fluidType: FluidType) => { keepLocalTime: true, }) } else if (firstEditedPriceDate) { - firstDate = DateTime.fromISO(firstEditedPriceDate).setZone('utc', { - keepLocalTime: true, - }) + firstDate = DateTime.max( + DateTime.fromISO(firstEditedPriceDate).setZone('utc', { + keepLocalTime: true, + }), + firstDataDate[0] + ) } else { firstDate = today } @@ -304,11 +290,7 @@ const applyPrices = async (client: Client, fluidType: FluidType) => { fluidType, date ) - log('info', `PRICE DATAAAAAAAA ${JSON.stringify(priceData)}`) - log('info', `DATEEEEEEE ${JSON.stringify(date)}`) const tp = await getTimePeriod(timeStep, date) - log('info', `PERIODDDDDD ${JSON.stringify(tp)}`) - // Get doc to update const data = await qr.fetchFluidRawDoctype( tp, @@ -343,12 +325,7 @@ const applyPrices = async (client: Client, fluidType: FluidType) => { }) }) ) - log( - 'info', - `SHOULD LAUNCH AGGREGATION for ${fluidType} with ${JSON.stringify( - firstDate - )}` - ) + // Call aggregation method await aggregatePrices(qr, cdm, firstDate, today, fluidType) } else log('info', `No data found for fluid ${fluidType}`) -- GitLab