From 5075cc497616a34af83f76754a9110c880928488 Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Fri, 3 Nov 2023 20:41:30 -0300 Subject: [PATCH 1/8] chore(viirs): remove outdated widgets --- .../fires-alerts-historical-old/index.js | 288 ------------------ .../fires-alerts-historical-old/selectors.js | 217 ------------- 2 files changed, 505 deletions(-) delete mode 100644 components/widgets/fires/fires-alerts-historical-old/index.js delete mode 100644 components/widgets/fires/fires-alerts-historical-old/selectors.js diff --git a/components/widgets/fires/fires-alerts-historical-old/index.js b/components/widgets/fires/fires-alerts-historical-old/index.js deleted file mode 100644 index bcf93b7b03..0000000000 --- a/components/widgets/fires/fires-alerts-historical-old/index.js +++ /dev/null @@ -1,288 +0,0 @@ -import { fetchHistoricalAlerts } from 'services/analysis-cached'; - -import getWidgetProps from './selectors'; - -export default { - widget: 'firesAlertsHistoricalOld', - title: 'Fire Alerts Count in {location}', - large: true, - categories: ['summary', 'fires'], - settingsConfig: [ - { - key: 'forestType', - label: 'Forest Type', - type: 'select', - placeholder: 'All land cover', - clearable: true, - }, - { - key: 'landCategory', - label: 'Land Category', - type: 'select', - placeholder: 'All categories', - clearable: true, - border: true, - }, - { - key: 'dataset', - label: 'fires dataset', - type: 'select', - }, - { - key: 'confidence', - label: 'Confidence level', - type: 'select', - clearable: false, - border: true, - }, - ], - refetchKeys: [ - 'forestType', - 'landCategory', - 'dataset', - 'endYear', - 'startYear', - 'confidence', - ], - visible: ['dashboard'], - types: ['country'], - admins: ['adm0', 'adm1', 'adm2'], - chartType: 'composedChart', - hideLayers: true, - dataType: 'fires', - colors: 'fires', - metaKey: 'widget_fire_alert_location', - sortOrder: { - fires: 5, - }, - settings: { - startDate: '2020-01-01', - endDate: '2020-04-01', - dataset: 'viirs', - }, - sentences: { - initial: - 'Between {start_year} and {end_year}, {location} experienced a total of {total_alerts} {dataset} fire alerts', - withInd: - 'Between {start_year} and {end_year}, {location} experienced a total of {total_alerts} {dataset} fire alerts within {indicator}', - conf: ', considering {confidence} alerts only.', - }, - whitelists: { - adm0: [ - 'AFG', - 'AGO', - 'ALB', - 'AND', - 'ANT', - 'ARE', - 'ARG', - 'ARM', - 'AUS', - 'AUT', - 'AZE', - 'BDI', - 'BEL', - 'BEN', - 'BFA', - 'BGD', - 'BGR', - 'BHR', - 'BHS', - 'BIH', - 'BLM', - 'BLR', - 'BLZ', - 'BOL', - 'BRA', - 'BRB', - 'BRN', - 'BTN', - 'BWA', - 'CAF', - 'CAN', - 'CHE', - 'CHL', - 'CHN', - 'CIV', - 'CMR', - 'COD', - 'COG', - 'COL', - 'COM', - 'CPV', - 'CRI', - 'CUB', - 'CYP', - 'CZE', - 'DEU', - 'DJI', - 'DMA', - 'DNK', - 'DOM', - 'DZA', - 'ECU', - 'EGY', - 'ERI', - 'ESP', - 'EST', - 'ETH', - 'FIN', - 'FJI', - 'FLK', - 'FRA', - 'FSM', - 'GAB', - 'GBR', - 'GEO', - 'GHA', - 'GIB', - 'GIN', - 'GLP', - 'GMB', - 'GNB', - 'GNQ', - 'GRC', - 'GRL', - 'GTM', - 'GUF', - 'GUM', - 'GUY', - 'HND', - 'HRV', - 'HTI', - 'HUN', - 'IDN', - 'IND', - 'IRL', - 'IRN', - 'IRQ', - 'ISR', - 'ITA', - 'JAM', - 'JOR', - 'JPN', - 'KAZ', - 'KEN', - 'KGZ', - 'KHM', - 'KIR', - 'KNA', - 'KOR', - 'KWT', - 'LAO', - 'LBN', - 'LBR', - 'LBY', - 'LCA', - 'LIE', - 'LKA', - 'LSO', - 'LTU', - 'LUX', - 'LVA', - 'MAR', - 'MCO', - 'MDA', - 'MDG', - 'MDV', - 'MEX', - 'MHL', - 'MKD', - 'MLI', - 'MLT', - 'MMR', - 'MNE', - 'MNG', - 'MNP', - 'MOZ', - 'MRT', - 'MSR', - 'MTQ', - 'MUS', - 'MWI', - 'MYS', - 'NAM', - 'NCL', - 'NER', - 'NGA', - 'NIC', - 'NLD', - 'NOR', - 'NPL', - 'NZL', - 'OMN', - 'PAK', - 'PAN', - 'PCN', - 'PER', - 'PHL', - 'PNG', - 'POL', - 'PRI', - 'PRK', - 'PRT', - 'PRY', - 'PSE', - 'PYF', - 'QAT', - 'REU', - 'ROU', - 'RUS', - 'RWA', - 'SAU', - 'SDN', - 'SEN', - 'SGP', - 'SLB', - 'SLE', - 'SLV', - 'SOM', - 'SRB', - 'SSD', - 'STP', - 'SUR', - 'SVK', - 'SVN', - 'SWE', - 'SWZ', - 'SYR', - 'TCD', - 'TGO', - 'THA', - 'TJK', - 'TKL', - 'TKM', - 'TLS', - 'TON', - 'TTO', - 'TUN', - 'TUR', - 'TUV', - 'TZA', - 'UGA', - 'UKR', - 'URY', - 'USA', - 'UZB', - 'VAT', - 'VEN', - 'VIR', - 'VNM', - 'VUT', - 'WSM', - 'YEM', - 'ZAF', - 'ZMB', - 'ZWE', - ], - }, - getData: (params) => - fetchHistoricalAlerts(params).then((alerts) => { - const { data } = alerts.data; - return data; - }), - getDataURL: (params) => [ - fetchHistoricalAlerts({ ...params, download: true }), - ], - getWidgetProps, -}; diff --git a/components/widgets/fires/fires-alerts-historical-old/selectors.js b/components/widgets/fires/fires-alerts-historical-old/selectors.js deleted file mode 100644 index 07d9860942..0000000000 --- a/components/widgets/fires/fires-alerts-historical-old/selectors.js +++ /dev/null @@ -1,217 +0,0 @@ -import { createSelector, createStructuredSelector } from 'reselect'; -import moment from 'moment'; -import { format } from 'd3-format'; -import isEmpty from 'lodash/isEmpty'; -import sortBy from 'lodash/sortBy'; -import sumBy from 'lodash/sumBy'; -import groupBy from 'lodash/groupBy'; - -import { getDatesData, getChartConfig } from 'components/widgets/utils/data'; - -const getAlerts = state => state.data && state.data.alerts; -const getFrequency = state => state.data && state.data.frequency; -const getColors = state => state.colors || null; -const getStartDate = state => state.settings.startDate; -const getEndDate = state => state.settings.endDate; -const getSentences = state => state.sentences || null; -const getDataset = state => state.settings.dataset || null; -const getLocationObject = state => state.location; -const getOptionsSelected = state => state.optionsSelected; -const getIndicator = state => state.indicator; - -const getDaysArray = (startDate, stopDate) => { - const dateArray = []; - let currentDate = moment(startDate); - const endDate = moment(stopDate); - while (currentDate <= endDate) { - dateArray.push(moment(currentDate).format('YYYY-MM-DD')); - currentDate = moment(currentDate).add(1, 'days'); - } - return dateArray; -}; - -export const getData = createSelector( - [getAlerts, getFrequency, getStartDate, getEndDate], - (data, frequency, startDate, endDate) => { - if (!data || isEmpty(data) || !frequency || !startDate || !endDate) { return null; } - - const startYear = moment(startDate).year(); - const endYear = moment(endDate).year(); - const years = []; - for (let i = startYear; i <= endYear; i += 1) { - years.push(i); - } - - const yearLengths = {}; - years.forEach(y => { - if (moment(`${y}-12-31`).isoWeek() === 1) { - yearLengths[y] = moment(`${y}-12-31`) - .subtract(1, 'week') - .isoWeek(); - } else { - yearLengths[y] = moment(`${y}-12-31`).isoWeek(); - } - }); - - const zeroFilledData = []; - if (frequency === 'daily') { - // why check `alert__date`? Sometimes settings change before refetching, - // and `data` is still the weekly data - - // If we are looking at daily resolution, add week and year and zero-fill - const datesArray = getDaysArray(startDate, endDate); - const dataWithYears = datesArray.map(d => { - const filteredDate = data.find(el => el.alert__date === d); - return { - date: d, - count: - filteredDate && filteredDate.alert__count > 0 - ? filteredDate.alert__count - : 0, - year: moment(d).year(), - week: moment(d).isoWeek(), - dayOfYear: moment(d).dayOfYear() // zero-filling - }; - }); - - const groupedByYear = groupBy( - sortBy(dataWithYears, ['year', 'dayOfYear']), - 'year' - ); - - years.filter(year => year === startYear).forEach(year => { - const yearDataByDay = groupBy(groupedByYear[year], 'dayOfYear'); - const maxDay = - year === moment().year() - ? Object.keys(yearDataByDay).pop() - : moment(`${year}-12-31`).dayOfYear(); - for (let i = 1; i <= maxDay; i += 1) { - zeroFilledData.push( - yearDataByDay[i] - ? yearDataByDay[i][0] - : { - alerts: 0, - count: 0, - week: moment() - .dayOfYear(i) - .isoWeek(), - year: parseInt(year, 10) - } - ); - } - }); - } else { - const groupedByYear = groupBy(sortBy(data, ['year', 'week']), 'year'); - - years.forEach(year => { - const yearDataByWeek = groupBy(groupedByYear[year], 'week'); - const maxWeek = - year === moment().year() - ? Object.keys(yearDataByWeek).pop() - : yearLengths[year]; - for (let i = 1; i <= maxWeek; i += 1) { - zeroFilledData.push( - yearDataByWeek[i] - ? yearDataByWeek[i][0] - : { alerts: 0, count: 0, week: i, year: parseInt(year, 10) } - ); - } - }); - } - return zeroFilledData; - } -); - -export const parseData = createSelector([getData], data => { - if (!data) return null; - // getDatesData: adds date and month info to data array - return getDatesData(data); -}); - -export const parseConfig = createSelector( - [getColors, getFrequency, getDataset], - (colors, frequency, dataset) => { - const tooltip = [ - { - label: 'Fire alerts' - }, - { - key: 'count', - labelKey: 'date', - labelFormat: value => moment(value).format('MMM DD YYYY'), - unit: ` ${dataset.toUpperCase()} alerts`, - color: colors.main, - unitFormat: value => - (Number.isInteger(value) ? format(',')(value) : value) - } - ]; - - return { - ...getChartConfig(colors), - tooltip, - xAxis: { - scale: 'point', - tickCount: 12, - interval: frequency === 'daily' ? 31 : undefined, - tickFormatter: t => moment(t).format('MMM-YY') - } - }; - } -); - -export const parseSentence = createSelector( - [ - parseData, - getColors, - getSentences, - getLocationObject, - getStartDate, - getEndDate, - getOptionsSelected, - getIndicator - ], - ( - data, - colors, - sentences, - location, - startDate, - endDate, - options, - indicator - ) => { - if (!data) return null; - const { dataset, confidence } = options; - const { initial, withInd, conf } = sentences; - const lastDate = data[data.length - 1] || {}; - const firstDate = data[0] || {}; - const total = sumBy( - data.filter(el => el.date >= firstDate.date && el.date <= lastDate.date), - 'count' - ); - const indicatorLabel = - indicator && indicator.label ? indicator.label : null; - const initialSentence = indicator ? withInd : initial; - const sentence = - confidence.value === 'h' ? initialSentence + conf : `${initialSentence}.`; - const params = { - confidence: confidence.value === 'h' ? 'high confidence' : '', - location: location.label || '', - indicator: indicatorLabel, - start_year: moment(startDate).format('Do of MMMM YYYY'), - end_year: moment(endDate).format('Do of MMMM YYYY'), - dataset: dataset && dataset.label, - total_alerts: { - value: total ? format(',')(total) : 0, - color: colors.main - } - }; - return { sentence, params }; - } -); - -export default createStructuredSelector({ - data: parseData, - config: parseConfig, - sentence: parseSentence -}); From ed57e3447485148d8cb919eccf50df184c2222f3 Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Fri, 3 Nov 2023 20:41:58 -0300 Subject: [PATCH 2/8] fix(viirs): add confidence default value as high --- components/widgets/fires/fires-alerts-cumulative/selectors.js | 4 +--- .../widgets/fires/fires-alerts-historical-daily/selectors.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/components/widgets/fires/fires-alerts-cumulative/selectors.js b/components/widgets/fires/fires-alerts-cumulative/selectors.js index a589cc86d0..45d8a8513e 100644 --- a/components/widgets/fires/fires-alerts-cumulative/selectors.js +++ b/components/widgets/fires/fires-alerts-cumulative/selectors.js @@ -401,7 +401,6 @@ export const parseSentence = createSelector( getDataset, getLocationName, getStartIndex, - // getEndIndex, getOptionsSelected, getIndicator, ], @@ -413,7 +412,6 @@ export const parseSentence = createSelector( dataset, location, startIndex, - // endIndex //broken? options, indicator ) => { @@ -424,7 +422,7 @@ export const parseSentence = createSelector( highConfidenceWithInd, allAlertsWithInd, } = sentences; - const { confidence } = options; + const { confidence = { value: 'h' } } = options; const indicatorLabel = indicator && indicator.label ? indicator.label : null; const start = startIndex; diff --git a/components/widgets/fires/fires-alerts-historical-daily/selectors.js b/components/widgets/fires/fires-alerts-historical-daily/selectors.js index 513777ce8b..b4a6c645ac 100644 --- a/components/widgets/fires/fires-alerts-historical-daily/selectors.js +++ b/components/widgets/fires/fires-alerts-historical-daily/selectors.js @@ -100,7 +100,7 @@ export const parseSentence = createSelector( ) => { if (!data) return null; const { initial, withInd, highConfidence } = sentences; - const { confidence, dataset } = options; + const { confidence = { value: 'h' }, dataset } = options; const indicatorLabel = indicator && indicator.label ? indicator.label : null; const total = sumBy(data, 'alert__count'); From 2c0fa1213541d85a1fc403d86c5ebdb80e400024 Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Fri, 3 Nov 2023 20:45:09 -0300 Subject: [PATCH 3/8] fix(viirs): add a new validation to show viirs widgets on the map To avoid errors between viirs layers and wigets with the new options (high confidence) we added some validations to getWhereQuery method To the future, we will need to think a better solution --- services/get-where-query.js | 43 +++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/services/get-where-query.js b/services/get-where-query.js index 30dfdb734e..b5de2ff1a7 100644 --- a/services/get-where-query.js +++ b/services/get-where-query.js @@ -13,6 +13,7 @@ export const getWHEREQuery = (params = {}) => { const allFilterOptions = forestTypes.concat(landCategories); const allowedParams = ALLOWED_PARAMS[params.dataset || 'annual']; const isTreeCoverDensity = dataset === 'treeCoverDensity'; + const isVIIRS = dataset === 'viirs'; const comparisonString = ' = '; let paramString = 'WHERE '; @@ -35,26 +36,56 @@ export const getWHEREQuery = (params = {}) => { paramKeys = paramKeys.filter((item) => item !== 'threshold'); } + /* + * Removing confidence_cat = 'false' from VIIRS request + * if the user selects 'all alerts' on the VIIRS layer, + * we don't want to add a new parameter to the query + */ + if (isVIIRS) { + if ( + typeof params?.confidence === 'boolean' && + params?.confidence === false + ) { + paramKeys = paramKeys.filter((item) => item !== 'confidence'); + } + + if (params?.confidence === 'false' || params?.confidence === 'true') { + paramKeys = paramKeys.filter((item) => item !== 'confidence'); + } + } + paramKeys.forEach((parameter, index) => { const isLastParameter = paramKeys.length - 1 === index; const hasFilterOption = ['forestType', 'landCategory'].includes(parameter); - const value = hasFilterOption ? 1 : params[parameter]; + let value = hasFilterOption ? 1 : params[parameter]; const filterOption = allFilterOptions.find( (pname) => pname.value === params[parameter] ); + /* + * when the user selects high confidence on VIIRS Layer + * the confidence option returns a string 'true' + * the right value should be 'h' + * Until we fix this return, we need to validate the parameter + */ + if (isVIIRS && parameter === 'confidence') { + if ( + typeof params?.confidence === 'boolean' && + params?.confidence === true + ) { + value = 'h'; + } + } + const tableKey = filterOption && (filterOption.tableKey || filterOption.tableKeys[dataset || 'annual']); + let isNumericValue = isNumber(value); const paramKey = translateParameterKey(parameter, params); - if (parameter === 'adm0' && type === 'wdpa') { - isNumericValue = false; - } - - if (dataset === 'net_change') { + if ((parameter === 'adm0' && type === 'wdpa') || dataset === 'net_change') { isNumericValue = false; } From c92c5ecd63aedde9d9a930477d4c28ec674d6ace Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Tue, 7 Nov 2023 12:43:27 -0300 Subject: [PATCH 4/8] fix(viirs): add getSettings to widget selectors Now we can access layer options when the widget is render on the map --- .../widgets/fires/fires-alerts-cumulative/selectors.js | 7 +++++-- .../fires/fires-alerts-historical-daily/selectors.js | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/components/widgets/fires/fires-alerts-cumulative/selectors.js b/components/widgets/fires/fires-alerts-cumulative/selectors.js index 45d8a8513e..be40a067e5 100644 --- a/components/widgets/fires/fires-alerts-cumulative/selectors.js +++ b/components/widgets/fires/fires-alerts-cumulative/selectors.js @@ -32,6 +32,7 @@ const getSentences = (state) => state.sentences || null; const getLocationName = (state) => state.locationLabel; const getOptionsSelected = (state) => state.optionsSelected; const getIndicator = (state) => state.indicator; +const getSettings = (state) => state.settings; export const getCompareYears = createSelector( [getCompareYear, getAllYears], @@ -403,6 +404,7 @@ export const parseSentence = createSelector( getStartIndex, getOptionsSelected, getIndicator, + getSettings, ], ( raw_data, @@ -413,7 +415,8 @@ export const parseSentence = createSelector( location, startIndex, options, - indicator + indicator, + settings ) => { if (!data || isEmpty(data)) return null; const { @@ -422,7 +425,7 @@ export const parseSentence = createSelector( highConfidenceWithInd, allAlertsWithInd, } = sentences; - const { confidence = { value: 'h' } } = options; + const { confidence = { value: settings.confidence } } = options; const indicatorLabel = indicator && indicator.label ? indicator.label : null; const start = startIndex; diff --git a/components/widgets/fires/fires-alerts-historical-daily/selectors.js b/components/widgets/fires/fires-alerts-historical-daily/selectors.js index b4a6c645ac..b669a02e3f 100644 --- a/components/widgets/fires/fires-alerts-historical-daily/selectors.js +++ b/components/widgets/fires/fires-alerts-historical-daily/selectors.js @@ -11,6 +11,7 @@ const getAlerts = (state) => state.data; const getColors = (state) => state.colors || null; const getStartDate = (state) => state.settings.startDate; const getEndDate = (state) => state.settings.endDate; +const getSettings = (state) => state.settings; const getSentences = (state) => state.sentences || null; const getLocationObject = (state) => state.location; const getOptionsSelected = (state) => state.optionsSelected; @@ -87,6 +88,7 @@ export const parseSentence = createSelector( getEndDate, getOptionsSelected, getIndicator, + getSettings, ], ( data, @@ -96,11 +98,13 @@ export const parseSentence = createSelector( startDate, endDate, options, - indicator + indicator, + settings ) => { if (!data) return null; const { initial, withInd, highConfidence } = sentences; - const { confidence = { value: 'h' }, dataset } = options; + const { confidence = { value: settings.confidence }, dataset } = options; + const indicatorLabel = indicator && indicator.label ? indicator.label : null; const total = sumBy(data, 'alert__count'); From a67b6ffcb0d2a09bdecf59a9116b0a5dbe2fc94d Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Tue, 7 Nov 2023 12:47:25 -0300 Subject: [PATCH 5/8] fix(viirs): add validation in fetchVIIRSAlertsSum To avoid confidence__cat = 'h' to be added on the query, since we always fetch by all alerts --- services/analysis-cached.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/services/analysis-cached.js b/services/analysis-cached.js index 0eafe2f79d..cadfcb7e27 100644 --- a/services/analysis-cached.js +++ b/services/analysis-cached.js @@ -2288,20 +2288,37 @@ export const fetchVIIRSAlertsSumOTF = (params) => { export const fetchVIIRSAlertsSum = (params) => { const { startDate, endDate, dataset } = params || {}; + /* + * Removing confidence parameter from VIIRS layer options + * for Fire Alerts widget, we always fetch all alerts + * and calculate the values directly on the selector.js + */ + const paramKeys = Object.keys(params).filter( + (param) => param !== 'confidence' + ); + const paramsWithoutConfidenceAlert = {}; + + paramKeys.forEach((parameter) => { + paramsWithoutConfidenceAlert[parameter] = params[parameter]; + }); + const url = encodeURI( `${getRequestUrl({ - ...params, + ...paramsWithoutConfidenceAlert, dataset, datasetType: 'daily', })}${SQL_QUERIES.firesDailySum}` .replace( /{select_location}/g, - getLocationSelect({ ...params, cast: false }) + getLocationSelect({ ...paramsWithoutConfidenceAlert, cast: false }) ) - .replace(/{location}/g, getLocationSelect(params)) + .replace(/{location}/g, getLocationSelect(paramsWithoutConfidenceAlert)) .replace('{startDate}', startDate) .replace('{endDate}', endDate) - .replace('{WHERE}', getWHEREQuery({ ...params, dataset: 'viirs' })) + .replace( + '{WHERE}', + getWHEREQuery({ ...paramsWithoutConfidenceAlert, dataset: 'viirs' }) + ) ); return dataRequest.get(url).then((response) => ({ From 4387ac4ff070b30efa639b884e18f9686349cab0 Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Tue, 7 Nov 2023 12:48:31 -0300 Subject: [PATCH 6/8] fix(viirs): validating the new option from the VIIRS layer to avoid errors on the query --- services/get-where-query.js | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/services/get-where-query.js b/services/get-where-query.js index b5de2ff1a7..617418e0db 100644 --- a/services/get-where-query.js +++ b/services/get-where-query.js @@ -37,46 +37,23 @@ export const getWHEREQuery = (params = {}) => { } /* - * Removing confidence_cat = 'false' from VIIRS request + * Removing confidence_cat = 'all' from VIIRS request * if the user selects 'all alerts' on the VIIRS layer, * we don't want to add a new parameter to the query */ - if (isVIIRS) { - if ( - typeof params?.confidence === 'boolean' && - params?.confidence === false - ) { - paramKeys = paramKeys.filter((item) => item !== 'confidence'); - } - if (params?.confidence === 'false' || params?.confidence === 'true') { - paramKeys = paramKeys.filter((item) => item !== 'confidence'); - } + if (isVIIRS && params?.confidence === 'all') { + paramKeys = paramKeys.filter((item) => item !== 'confidence'); } paramKeys.forEach((parameter, index) => { const isLastParameter = paramKeys.length - 1 === index; const hasFilterOption = ['forestType', 'landCategory'].includes(parameter); - let value = hasFilterOption ? 1 : params[parameter]; + const value = hasFilterOption ? 1 : params[parameter]; const filterOption = allFilterOptions.find( (pname) => pname.value === params[parameter] ); - /* - * when the user selects high confidence on VIIRS Layer - * the confidence option returns a string 'true' - * the right value should be 'h' - * Until we fix this return, we need to validate the parameter - */ - if (isVIIRS && parameter === 'confidence') { - if ( - typeof params?.confidence === 'boolean' && - params?.confidence === true - ) { - value = 'h'; - } - } - const tableKey = filterOption && (filterOption.tableKey || filterOption.tableKeys[dataset || 'annual']); From 47968e0a2ea60727ce6d3eeeed6a01a32a3b8632 Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Wed, 8 Nov 2023 14:29:15 -0300 Subject: [PATCH 7/8] fix(viirs): change confidence from Layers to confidenceToggle and set as a boolean To use this new parameter on the tile endpoint we need to use a boolean to high_confidence_only So I removed the object and set again as a boolean --- .../fires/fires-alerts-cumulative/selectors.js | 13 ++++++++++++- .../fires-alerts-historical-daily/selectors.js | 13 ++++++++++++- services/get-where-query.js | 5 ++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/components/widgets/fires/fires-alerts-cumulative/selectors.js b/components/widgets/fires/fires-alerts-cumulative/selectors.js index be40a067e5..e708b30406 100644 --- a/components/widgets/fires/fires-alerts-cumulative/selectors.js +++ b/components/widgets/fires/fires-alerts-cumulative/selectors.js @@ -419,13 +419,24 @@ export const parseSentence = createSelector( settings ) => { if (!data || isEmpty(data)) return null; + const { highConfidence, allAlerts, highConfidenceWithInd, allAlertsWithInd, } = sentences; - const { confidence = { value: settings.confidence } } = options; + const { confidenceToggle = true } = settings; + let { confidence } = options; + + /* + Validation for the Analysis + */ + if (confidenceToggle) { + confidence = + confidenceToggle === 'true' ? { value: 'h' } : { value: 'all' }; + } + const indicatorLabel = indicator && indicator.label ? indicator.label : null; const start = startIndex; diff --git a/components/widgets/fires/fires-alerts-historical-daily/selectors.js b/components/widgets/fires/fires-alerts-historical-daily/selectors.js index b669a02e3f..4152abc6a5 100644 --- a/components/widgets/fires/fires-alerts-historical-daily/selectors.js +++ b/components/widgets/fires/fires-alerts-historical-daily/selectors.js @@ -103,7 +103,18 @@ export const parseSentence = createSelector( ) => { if (!data) return null; const { initial, withInd, highConfidence } = sentences; - const { confidence = { value: settings.confidence }, dataset } = options; + const { confidenceToggle = true } = settings; + const { dataset } = options; + + let { confidence } = options; + + /* + Validation for the Analysis + */ + if (confidenceToggle) { + confidence = + confidenceToggle === 'true' ? { value: 'h' } : { value: 'all' }; + } const indicatorLabel = indicator && indicator.label ? indicator.label : null; diff --git a/services/get-where-query.js b/services/get-where-query.js index 617418e0db..b00d854c68 100644 --- a/services/get-where-query.js +++ b/services/get-where-query.js @@ -37,12 +37,11 @@ export const getWHEREQuery = (params = {}) => { } /* - * Removing confidence_cat = 'all' from VIIRS request + * Removing confidence_cat = 'false' from VIIRS request * if the user selects 'all alerts' on the VIIRS layer, * we don't want to add a new parameter to the query */ - - if (isVIIRS && params?.confidence === 'all') { + if (isVIIRS && !params?.confidenceToggle === 'false') { paramKeys = paramKeys.filter((item) => item !== 'confidence'); } From 600739befb72ea760b7165028580e4b1096c1344 Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Wed, 8 Nov 2023 14:45:15 -0300 Subject: [PATCH 8/8] fix(viirs): remove default value from confidenceToggle --- components/widgets/fires/fires-alerts-cumulative/selectors.js | 2 +- .../widgets/fires/fires-alerts-historical-daily/selectors.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/widgets/fires/fires-alerts-cumulative/selectors.js b/components/widgets/fires/fires-alerts-cumulative/selectors.js index e708b30406..3a9707015a 100644 --- a/components/widgets/fires/fires-alerts-cumulative/selectors.js +++ b/components/widgets/fires/fires-alerts-cumulative/selectors.js @@ -426,7 +426,7 @@ export const parseSentence = createSelector( highConfidenceWithInd, allAlertsWithInd, } = sentences; - const { confidenceToggle = true } = settings; + const { confidenceToggle } = settings; let { confidence } = options; /* diff --git a/components/widgets/fires/fires-alerts-historical-daily/selectors.js b/components/widgets/fires/fires-alerts-historical-daily/selectors.js index 4152abc6a5..97b82dd117 100644 --- a/components/widgets/fires/fires-alerts-historical-daily/selectors.js +++ b/components/widgets/fires/fires-alerts-historical-daily/selectors.js @@ -103,7 +103,7 @@ export const parseSentence = createSelector( ) => { if (!data) return null; const { initial, withInd, highConfidence } = sentences; - const { confidenceToggle = true } = settings; + const { confidenceToggle } = settings; const { dataset } = options; let { confidence } = options;