Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.45.1](https://github.com/micronutrientsupport/api/compare/v2.45.0...v2.45.1) (2025-01-15)


### Bug Fixes

* resolve some NaN issues ([ed33e64](https://github.com/micronutrientsupport/api/commit/ed33e641830ef6cbe2954254d9d9d675e7f3a0cc))

## [2.45.0](https://github.com/micronutrientsupport/api/compare/v2.44.0...v2.45.0) (2024-12-14)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "2.45.0",
"version": "2.45.1",
"description": "MAPS Micronutrient Support Tool API",
"keywords": [
"loopback-application",
Expand Down
29 changes: 18 additions & 11 deletions patches/js-to-json-logic+0.1.3.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index de72f86..64b90ac 100644
+export function transformJS (code: string): any
+export function processNode (node: any, extraData?: any, valueOnly?: boolean, ): any;
diff --git a/node_modules/js-to-json-logic/lib/index.js b/node_modules/js-to-json-logic/lib/index.js
index c6ab89c..d495577 100644
index c6ab89c..25ef823 100644
--- a/node_modules/js-to-json-logic/lib/index.js
+++ b/node_modules/js-to-json-logic/lib/index.js
@@ -33,14 +33,14 @@ function processError ({ loc, at }, message) {
Expand Down Expand Up @@ -36,7 +36,7 @@ index c6ab89c..d495577 100644
}
}

@@ -66,6 +66,218 @@ function processNode (node, valueOnly = false) {
@@ -66,6 +66,225 @@ function processNode (node, valueOnly = false) {
}
}

Expand Down Expand Up @@ -71,9 +71,13 @@ index c6ab89c..d495577 100644
+ // console.error({key, value, sheet})
+ const regex = new RegExp(value);
+ if(sheet.match(regex)) {
+ // console.error('Matches', key)
+ console.error(sheet, 'Matches', key, '(', cell , ')')
+ // console.error(extraData[key])
+
+ if(sheet === 'IMPACT projections') {
+ // Increment letter e.g. A becomes B
+ col = String.fromCharCode(col.charCodeAt(0)+1)
+ }
+
+ switch(col) {
+ case 'D': {
Expand Down Expand Up @@ -123,10 +127,13 @@ index c6ab89c..d495577 100644
+ // typeof(extraData[key][col]),
+ // val: extraData[key][col]
+ // })
+
+ //console.log('Replace with', extraData[key][col])
+
+ return extraData[key][col]
+
+ } else {
+ //console.error('Doesnt match', sheet)
+ //console.error(sheet, 'Doesnt match', value)
+ }
+ }
+ }
Expand Down Expand Up @@ -255,7 +262,7 @@ index c6ab89c..d495577 100644
case 'Literal': {
if (node.value instanceof RegExp) {
return [node.value.source, node.value.flags]
@@ -75,7 +287,7 @@ function processNode (node, valueOnly = false) {
@@ -75,7 +294,7 @@ function processNode (node, valueOnly = false) {
}

case 'SpreadElement': {
Expand All @@ -264,7 +271,7 @@ index c6ab89c..d495577 100644
}

case 'ArrayExpression': {
@@ -83,19 +295,19 @@ function processNode (node, valueOnly = false) {
@@ -83,19 +302,19 @@ function processNode (node, valueOnly = false) {
if (node.elements.some((node) => node.type === 'SpreadElement')) {
return {
merge: [
Expand All @@ -287,7 +294,7 @@ index c6ab89c..d495577 100644
}
return result
}
@@ -107,59 +319,175 @@ function processNode (node, valueOnly = false) {
@@ -107,59 +326,175 @@ function processNode (node, valueOnly = false) {
}

case 'ExpressionStatement': {
Expand Down Expand Up @@ -479,7 +486,7 @@ index c6ab89c..d495577 100644
: node.property.name

const value = `${object}.${property}`
@@ -170,10 +498,10 @@ function processNode (node, valueOnly = false) {
@@ -170,10 +505,10 @@ function processNode (node, valueOnly = false) {
case 'IfStatement': {
return {
if: [
Expand All @@ -493,7 +500,7 @@ index c6ab89c..d495577 100644
: undefined
].filter(Boolean)
}
@@ -184,8 +512,8 @@ function processNode (node, valueOnly = false) {
@@ -184,8 +519,8 @@ function processNode (node, valueOnly = false) {
return processError(node, 'Only one-line arrow functions with implicit return are supported.')
}

Expand All @@ -504,7 +511,7 @@ index c6ab89c..d495577 100644

return !params.length || params.length > 1
? body
@@ -193,7 +521,7 @@ function processNode (node, valueOnly = false) {
@@ -193,7 +528,7 @@ function processNode (node, valueOnly = false) {
}

case 'ReturnStatement': {
Expand All @@ -513,7 +520,7 @@ index c6ab89c..d495577 100644
}

/** unsuported features */
@@ -266,4 +594,4 @@ const transformJS = (code) => {
@@ -266,4 +601,4 @@ const transformJS = (code) => {
}
}

Expand Down
44 changes: 44 additions & 0 deletions src/controllers/intervention.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
InterventionExtraCostsRepository,
InterventionFarmerAdoptionRatesRepository,
InterventionFortificationLevelSummaryRepository,
InterventionImpactProjectionsRepository,
InterventionIndustryInformationRepository,
InterventionListRepository,
InterventionMonitoringInformationRepository,
Expand All @@ -70,6 +71,7 @@ import {
InterventionStartupScaleupCostsRepository,
InterventionStatusRepository,
InterventionSummaryCostsRepository,
InterventionTargettingRepository,
InterventionTemplatesRepository,
InterventionThresholdsRepository,
InterventionVehicleStandardRepository,
Expand Down Expand Up @@ -345,6 +347,10 @@ export class InterventionController {
public interventionFortificationLevelSummaryRepository: InterventionFortificationLevelSummaryRepository,
@repository(InterventionTemplatesRepository)
public interventionTemplatesRepository: InterventionTemplatesRepository,
@repository(InterventionImpactProjectionsRepository)
public interventionImpactProjectionsRepository: InterventionImpactProjectionsRepository,
@repository(InterventionTargettingRepository)
public interventionTargettingRepository: InterventionTargettingRepository,
@repository(FortifiableFoodItemsRepository)
public fortifiableFoodItemsRepository: FortifiableFoodItemsRepository,
@repository(InterventionStatusRepository)
Expand Down Expand Up @@ -2197,6 +2203,8 @@ export class InterventionController {
(fullData as any)['regexes'] = {
premix: 'Premix - .*',
demographics: 'Demographics',
impact: 'IMPACT projections',
bioTarget: 'Biofortification targeting',
};

const premixFilter = {
Expand Down Expand Up @@ -2237,6 +2245,42 @@ export class InterventionController {
year9: 148001185,
};

const impact = await this.interventionImpactProjectionsRepository.find({
where: {
interventionId: intervention.id,
},
});

const bioTarget = await this.interventionTargettingRepository.find({
where: {
interventionId: intervention.id,
},
});

const bTTotal = bioTarget.reduce((prev, curr) => {
if (!curr.regionalSharePc) {
return prev;
}
return Number(prev) + Number(curr.regionalSharePc);
}, 0);

console.log({bTTotal});

(fullData as any)['impact'] = impact[0];

(fullData as any)['bioTarget'] = {
year0: bTTotal,
year1: bTTotal,
year2: bTTotal,
year3: bTTotal,
year4: bTTotal,
year5: bTTotal,
year6: bTTotal,
year7: bTTotal,
year8: bTTotal,
year9: bTTotal,
};

return {dataVals, fullData};
}
}
2 changes: 2 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ export * from './mn-bin-range.model';
export * from './monthly-food.model';
export * from './top-20-mn-per-country.model';
export * from './top-20-mn-per-hhsurvey.model';
export * from './intervention-impact-projections.model';
export * from './intervention-targetting.model';
Loading