Skip to content

Commit

Permalink
chore(filename): add baseline year to the download filename
Browse files Browse the repository at this point in the history
  • Loading branch information
willian-viana committed Nov 27, 2024
1 parent 6b26d88 commit deb33bf
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions services/analysis-cached.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,14 @@ export const getLossFiresGrouped = (params) => {
};

export const getTreeCoverGainByPlantationType = (params) => {
const { forestType, landCategory, ifl, download, startYear, endYear } =
params;
const {
forestType,
landCategory,
ifl,
download,
startYear = 2000,
endYear,
} = params;

const requestUrl = getRequestUrl({
...params,
Expand All @@ -904,12 +910,12 @@ export const getTreeCoverGainByPlantationType = (params) => {
const sqlQuery = SQL_QUERIES.treeCoverGainByPlantationType;

const baselineYearQuery = [];
let year = parseInt(startYear, 10) || 2000;
let startYearRef = parseInt(startYear, 10);

while (year < endYear) {
const nextYear = year + 5;
baselineYearQuery.push(`${year}-${nextYear}`);
year = nextYear;
while (startYearRef < endYear) {
const nextYear = startYearRef + 5;
baselineYearQuery.push(`${startYearRef}-${nextYear}`);
startYearRef = nextYear;
}

const url = encodeURI(
Expand Down Expand Up @@ -1217,8 +1223,14 @@ export const getExtentGrouped = (params) => {

// summed gain for single location
export const getGain = (params) => {
const { forestType, landCategory, ifl, download, startYear, endYear } =
params || {};
const {
forestType,
landCategory,
ifl,
download,
startYear = 2000,
endYear,
} = params || {};

const requestUrl = getRequestUrl({
...params,
Expand All @@ -1231,12 +1243,12 @@ export const getGain = (params) => {
}

const baselineYearQuery = [];
let year = parseInt(startYear, 10) || 2000;
let startYearRef = parseInt(startYear, 10);

while (year < endYear) {
const nextYear = year + 5;
baselineYearQuery.push(`${year}-${nextYear}`);
year = nextYear;
while (startYearRef < endYear) {
const nextYear = startYearRef + 5;
baselineYearQuery.push(`${startYearRef}-${nextYear}`);
startYearRef = nextYear;
}

const url = encodeURI(
Expand All @@ -1253,7 +1265,7 @@ export const getGain = (params) => {
if (download) {
const indicator = getIndicator(forestType, landCategory, ifl);
return {
name: `treecover_gain_2000-2020${
name: `treecover_gain_${startYear}-2020${
indicator ? `_in_${snakeCase(indicator.label)}` : ''
}__ha`,
url: getDownloadUrl(url),
Expand All @@ -1274,8 +1286,14 @@ export const getGain = (params) => {

// disaggregated gain for child of location
export const getGainGrouped = (params) => {
const { forestType, landCategory, ifl, download, startYear, endYear } =
params || {};
const {
forestType,
landCategory,
ifl,
download,
startYear = 2000,
endYear,
} = params || {};

const requestUrl = getRequestUrl({
...params,
Expand All @@ -1289,12 +1307,12 @@ export const getGainGrouped = (params) => {
}

const baselineYearQuery = [];
let year = parseInt(startYear, 10) || 2000;
let startYearRef = parseInt(startYear, 10);

while (year < parseInt(endYear, 10)) {
const nextYear = year + 5;
baselineYearQuery.push(`${year}-${nextYear}`);
year = nextYear;
while (startYearRef < parseInt(endYear, 10)) {
const nextYear = startYearRef + 5;
baselineYearQuery.push(`${startYearRef}-${nextYear}`);
startYearRef = nextYear;
}

const url = encodeURI(
Expand All @@ -1311,7 +1329,7 @@ export const getGainGrouped = (params) => {
if (download) {
const indicator = getIndicator(forestType, landCategory, ifl);
return {
name: `treecover_gain_2000-2020_by_region${
name: `treecover_gain_${startYear}-2020_by_region${
indicator ? `_in_${snakeCase(indicator.label)}` : ''
}__ha`,
url: getDownloadUrl(url),
Expand Down

0 comments on commit deb33bf

Please sign in to comment.