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 Dec 5, 2024
1 parent 6b26d88 commit aa68713
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 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 All @@ -921,7 +927,7 @@ export const getTreeCoverGainByPlantationType = (params) => {
if (download) {
const indicator = getIndicator(forestType, landCategory, ifl);
return {
name: `tree_cover_gain_by_plantation_type${
name: `tree_cover_gain_by_plantation_type_${startYear}-2020${
indicator ? `_in_${snakeCase(indicator.label)}` : ''
}__ha`,
url: getDownloadUrl(url),
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 aa68713

Please sign in to comment.