Skip to content

Commit

Permalink
fix: cumulative values in time/cycle viz
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Aug 11, 2023
1 parent b5f36d7 commit 90962cb
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/controllers/disbursements.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,31 @@ export class DisbursementsController {
}),
),
});
if (
data.length > 1 &&
data[data.length - 1].cumulativeChildren.length <
data[data.length - 2].cumulativeChildren.length
) {
const prev = data[data.length - 2];
const current = data[data.length - 1];
const temp = _.filter(
prev.cumulativeChildren,
(item: any) =>
_.findIndex(current.cumulativeChildren, {
name: item.name,
}) === -1,
);
data[data.length - 1].cumulativeChildren = [
...temp,
...data[data.length - 1].cumulativeChildren,
];
data[data.length - 1].cumulative += _.sumBy(temp, 'value');
data[data.length - 1].cumulativeChildren = _.orderBy(
data[data.length - 1].cumulativeChildren,
'name',
'asc',
);
}
});
return {
count: data.length,
Expand Down Expand Up @@ -384,6 +409,31 @@ export class DisbursementsController {
}),
),
});
if (
data.length > 1 &&
data[data.length - 1].cumulativeChildren.length <
data[data.length - 2].cumulativeChildren.length
) {
const prev = data[data.length - 2];
const current = data[data.length - 1];
const temp = _.filter(
prev.cumulativeChildren,
(item: any) =>
_.findIndex(current.cumulativeChildren, {
name: item.name,
}) === -1,
);
data[data.length - 1].cumulativeChildren = [
...temp,
...data[data.length - 1].cumulativeChildren,
];
data[data.length - 1].cumulative += _.sumBy(temp, 'value');
data[data.length - 1].cumulativeChildren = _.orderBy(
data[data.length - 1].cumulativeChildren,
'name',
'asc',
);
}
});
return {
count: data.length,
Expand Down Expand Up @@ -492,6 +542,32 @@ export class DisbursementsController {
}),
),
});

if (
data.length > 1 &&
data[data.length - 1].cumulativeChildren.length <
data[data.length - 2].cumulativeChildren.length
) {
const prev = data[data.length - 2];
const current = data[data.length - 1];
const temp = _.filter(
prev.cumulativeChildren,
(item: any) =>
_.findIndex(current.cumulativeChildren, {
name: item.name,
}) === -1,
);
data[data.length - 1].cumulativeChildren = [
...temp,
...data[data.length - 1].cumulativeChildren,
];
data[data.length - 1].cumulative += _.sumBy(temp, 'value');
data[data.length - 1].cumulativeChildren = _.orderBy(
data[data.length - 1].cumulativeChildren,
'name',
'asc',
);
}
});
return {
count: data.length,
Expand Down

0 comments on commit 90962cb

Please sign in to comment.