Skip to content

Commit

Permalink
Merge pull request #29 from globalfund/feat/DE-1462
Browse files Browse the repository at this point in the history
feat: optimise geography filtering
  • Loading branch information
stephanoshadjipetrou authored Nov 11, 2024
2 parents 0dfbf4c + b0ca4c8 commit 1b6934f
Show file tree
Hide file tree
Showing 19 changed files with 1,501 additions and 426 deletions.
1,186 changes: 1,186 additions & 0 deletions public/locations-flat.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/controllers/allocations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export class AllocationsController {
@get('/allocations/cumulative-by-cycles')
@response(200)
async cumulativeByCycles() {
let filterString = filterFinancialIndicators(
let filterString = await filterFinancialIndicators(
this.req.query,
AllocationCumulativeByCyclesFieldsMapping.urlParams,
['geography/name', 'geography/code'],
'geography/code',
'activityArea/name',
'allocation',
);
Expand Down Expand Up @@ -151,10 +151,10 @@ export class AllocationsController {
@get('/allocations/sunburst')
@response(200)
async allocationsSunburst() {
const filterString = filterFinancialIndicators(
const filterString = await filterFinancialIndicators(
this.req.query,
AllocationSunburstFieldsMapping.urlParams,
['geography/name', 'geography/code'],
'geography/code',
'activityArea/name',
'allocation',
);
Expand Down Expand Up @@ -199,10 +199,10 @@ export class AllocationsController {
urlParams = AllocationTreemapFieldsMapping.urlParams[1];
}
}
const filterString = filterFinancialIndicators(
const filterString = await filterFinancialIndicators(
this.req.query,
urlParams,
['geography/name', 'geography/code'],
'geography/code',
'activityArea/name',
'allocation',
);
Expand Down Expand Up @@ -274,10 +274,10 @@ export class AllocationsController {
@get('/allocations/table')
@response(200)
async allocationsTable() {
const filterString = filterFinancialIndicators(
const filterString = await filterFinancialIndicators(
this.req.query,
AllocationTableFieldsMapping.urlParams,
['geography/name', 'geography/code'],
'geography/code',
'activityArea/name',
'allocation',
);
Expand Down Expand Up @@ -353,17 +353,17 @@ export class AllocationsController {
@get('/allocations/radial')
@response(200)
async allocationsRadialChart() {
let filterString = filterFinancialIndicators(
let filterString = await filterFinancialIndicators(
this.req.query,
AllocationRadialFieldsMapping.urlParams,
['geography/name', 'geography/code'],
'geography/code',
'activityArea/name',
'allocation',
);
let filterString2 = filterFinancialIndicators(
let filterString2 = await filterFinancialIndicators(
this.req.query,
AllocationRadialFieldsMapping.countriesCountUrlParams,
['geography/name', 'geography/code'],
'geography/code',
'activityArea/name',
'allocation',
);
Expand All @@ -388,7 +388,7 @@ export class AllocationsController {
@param.path.string('countryCode') countryCode: string,
) {
const decodedCode = countryCode.replace(/\|/g, '%2F');
let filterString = filterFinancialIndicators(
let filterString = await filterFinancialIndicators(
{...this.req.query, geographies: decodedCode},
AllocationRadialFieldsMapping.urlParamsLocation,
'geography/code',
Expand All @@ -406,7 +406,7 @@ export class AllocationsController {
@get('/allocations/cycles')
@response(200)
async cycles() {
const filterString = filterFinancialIndicators(
const filterString = await filterFinancialIndicators(
this.req.query,
AllocationCyclesFieldsMapping.urlParams,
'geography/code',
Expand Down
167 changes: 56 additions & 111 deletions src/controllers/budgets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,15 @@ export class BudgetsController {
@get('/budgets/radial')
@response(200)
async radial() {
let geographyMappings = [
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
];
let geographyMappings = 'implementationPeriod/grant/geography/code';
if (this.req.query.geographyGrouping === 'Portfolio View') {
geographyMappings = [
'implementationPeriod/grant/geography_PortfolioView/name',
'implementationPeriod/grant/geography_PortfolioView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_PortfolioView/code';
} else if (this.req.query.geographyGrouping === 'Board Constituency View') {
geographyMappings = [
'implementationPeriod/grant/geography_BoardConstituencyView/name',
'implementationPeriod/grant/geography_BoardConstituencyView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_BoardConstituencyView/code';
}
const filterString = filterFinancialIndicators(
const filterString = await filterFinancialIndicators(
this.req.query,
BudgetsRadialFieldsMapping.urlParams,
geographyMappings,
Expand Down Expand Up @@ -67,22 +60,15 @@ export class BudgetsController {
@param.path.string('componentField') componentField: string,
@param.path.string('geographyGrouping') geographyGrouping: string,
) {
let geographyMappings = [
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
];
let geographyMappings = 'implementationPeriod/grant/geography/code';
if (geographyGrouping === 'Portfolio View') {
geographyMappings = [
'implementationPeriod/grant/geography_PortfolioView/name',
'implementationPeriod/grant/geography_PortfolioView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_PortfolioView/code';
} else if (geographyGrouping === 'Board Constituency View') {
geographyMappings = [
'implementationPeriod/grant/geography_BoardConstituencyView/name',
'implementationPeriod/grant/geography_BoardConstituencyView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_BoardConstituencyView/code';
}
const filterString = filterFinancialIndicators(
const filterString = await filterFinancialIndicators(
this.req.query,
BudgetsSankeyFieldsMapping.urlParams,
geographyMappings,
Expand Down Expand Up @@ -199,22 +185,15 @@ export class BudgetsController {
@param.path.string('componentField') componentField: string,
@param.path.string('geographyGrouping') geographyGrouping: string,
) {
let geographyMappings = [
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
];
let geographyMappings = 'implementationPeriod/grant/geography/code';
if (geographyGrouping === 'Portfolio View') {
geographyMappings = [
'implementationPeriod/grant/geography_PortfolioView/name',
'implementationPeriod/grant/geography_PortfolioView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_PortfolioView/code';
} else if (geographyGrouping === 'Board Constituency View') {
geographyMappings = [
'implementationPeriod/grant/geography_BoardConstituencyView/name',
'implementationPeriod/grant/geography_BoardConstituencyView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_BoardConstituencyView/code';
}
const filterString1 = filterFinancialIndicators(
const filterString1 = await filterFinancialIndicators(
this.req.query,
BudgetsTreemapFieldsMapping.urlParams1.replace(
'<componentField>',
Expand All @@ -238,7 +217,7 @@ export class BudgetsController {
);

if (componentField === 'activityAreaGroup') {
filterString2 = filterFinancialIndicators(
filterString2 = await filterFinancialIndicators(
this.req.query,
BudgetsTreemapFieldsMapping.urlParams2.replace(
'<componentField>',
Expand Down Expand Up @@ -353,20 +332,13 @@ export class BudgetsController {
@param.path.string('componentField') _componentField: string,
@param.path.string('geographyGrouping') geographyGrouping: string,
) {
let geographyMappings = [
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
];
let geographyMappings = 'implementationPeriod/grant/geography/code';
if (geographyGrouping === 'Portfolio View') {
geographyMappings = [
'implementationPeriod/grant/geography_PortfolioView/name',
'implementationPeriod/grant/geography_PortfolioView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_PortfolioView/code';
} else if (geographyGrouping === 'Board Constituency View') {
geographyMappings = [
'implementationPeriod/grant/geography_BoardConstituencyView/name',
'implementationPeriod/grant/geography_BoardConstituencyView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_BoardConstituencyView/code';
}
let urlParams = BudgetsTableFieldsMapping.urlParams;
let level1Field = BudgetsTableFieldsMapping.level1Field;
Expand All @@ -388,7 +360,7 @@ export class BudgetsController {
);
level3Field = null;
}
const filterString = filterFinancialIndicators(
const filterString = await filterFinancialIndicators(
this.req.query,
urlParams,
geographyMappings,
Expand Down Expand Up @@ -469,7 +441,7 @@ export class BudgetsController {
@get('/budgets/cycles')
@response(200)
async cycles() {
const filterString = filterFinancialIndicators(
const filterString = await filterFinancialIndicators(
this.req.query,
BudgetsCyclesMapping.urlParams,
'implementationPeriod/grant/geography/code',
Expand Down Expand Up @@ -524,24 +496,17 @@ export class BudgetsController {
@param.path.string('componentField') componentField: string,
@param.path.string('geographyGrouping') geographyGrouping: string,
) {
let geographyMappings = [
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
];
let geographyMappings = 'implementationPeriod/grant/geography/code';
if (geographyGrouping === 'Portfolio View') {
geographyMappings = [
'implementationPeriod/grant/geography_PortfolioView/name',
'implementationPeriod/grant/geography_PortfolioView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_PortfolioView/code';
} else if (geographyGrouping === 'Board Constituency View') {
geographyMappings = [
'implementationPeriod/grant/geography_BoardConstituencyView/name',
'implementationPeriod/grant/geography_BoardConstituencyView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_BoardConstituencyView/code';
}
// const years = cycle.split('-');

const filterString1 = filterFinancialIndicators(
const filterString1 = await filterFinancialIndicators(
{
...this.req.query,
cycleNames: cycle,
Expand Down Expand Up @@ -570,7 +535,7 @@ export class BudgetsController {
);

if (componentField === 'activityAreaGroup') {
filterString2 = filterFinancialIndicators(
filterString2 = await filterFinancialIndicators(
{
...this.req.query,
cycleNames: cycle,
Expand Down Expand Up @@ -672,29 +637,23 @@ export class BudgetsController {
@param.path.string('geographyGrouping') geographyGrouping: string,
) {
// (disbursement + cash balance) / budget
let geographyMappings = [
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
];
let geographyMappings = 'implementationPeriod/grant/geography/code';

if (geographyGrouping === 'Portfolio View') {
geographyMappings = [
'implementationPeriod/grant/geography_PortfolioView/name',
'implementationPeriod/grant/geography_PortfolioView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_PortfolioView/code';
} else if (geographyGrouping === 'Board Constituency View') {
geographyMappings = [
'implementationPeriod/grant/geography_BoardConstituencyView/name',
'implementationPeriod/grant/geography_BoardConstituencyView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_BoardConstituencyView/code';
}
const filterString1 = filterFinancialIndicators(
const filterString1 = await filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParams,
geographyMappings,
`implementationPeriod/grant/${componentField}/name`,
'budget',
);
const filterString2 = filterFinancialIndicators(
const filterString2 = await filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParamsOrganisations,
geographyMappings,
Expand Down Expand Up @@ -917,29 +876,22 @@ export class BudgetsController {
@param.path.string('geographyGrouping') geographyGrouping: string,
) {
// expenditure / budget
let geographyMappings = [
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
];
let geographyMappings = 'implementationPeriod/grant/geography/code';
if (geographyGrouping === 'Portfolio View') {
geographyMappings = [
'implementationPeriod/grant/geography_PortfolioView/name',
'implementationPeriod/grant/geography_PortfolioView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_PortfolioView/code';
} else if (geographyGrouping === 'Board Constituency View') {
geographyMappings = [
'implementationPeriod/grant/geography_BoardConstituencyView/name',
'implementationPeriod/grant/geography_BoardConstituencyView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_BoardConstituencyView/code';
}
const filterString1 = filterFinancialIndicators(
const filterString1 = await filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParams,
geographyMappings,
`implementationPeriod/grant/${componentField}/name`,
'budget',
);
const filterString2 = filterFinancialIndicators(
const filterString2 = await filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParamsOrganisations,
geographyMappings,
Expand Down Expand Up @@ -1117,29 +1069,22 @@ export class BudgetsController {
@param.path.string('geographyGrouping') geographyGrouping: string,
) {
// expenditure / disbursement
let geographyMappings = [
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
];
let geographyMappings = 'implementationPeriod/grant/geography/code';
if (geographyGrouping === 'Portfolio View') {
geographyMappings = [
'implementationPeriod/grant/geography_PortfolioView/name',
'implementationPeriod/grant/geography_PortfolioView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_PortfolioView/code';
} else if (geographyGrouping === 'Board Constituency View') {
geographyMappings = [
'implementationPeriod/grant/geography_BoardConstituencyView/name',
'implementationPeriod/grant/geography_BoardConstituencyView/code',
];
geographyMappings =
'implementationPeriod/grant/geography_BoardConstituencyView/code';
}
const filterString1 = filterFinancialIndicators(
const filterString1 = await filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParams,
geographyMappings,
`implementationPeriod/grant/${componentField}/name`,
'budget',
);
const filterString2 = filterFinancialIndicators(
const filterString2 = await filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParamsOrganisations,
geographyMappings,
Expand Down Expand Up @@ -1314,7 +1259,7 @@ export class BudgetsController {
@get('/financial-metrics/cycles')
@response(200)
async metricsCycles() {
const filterString = filterFinancialIndicators(
const filterString = await filterFinancialIndicators(
this.req.query,
BudgetsCyclesMapping.urlParamsMetrics,
'implementationPeriod/grant/geography/code',
Expand Down
Loading

0 comments on commit 1b6934f

Please sign in to comment.