Skip to content

Commit

Permalink
Double check 100 summation
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahdigh committed Nov 18, 2024
1 parent 6f411b1 commit 4953c37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/flow/flow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import {
generateZeroMatrix,
getRankingForSetOfDampingFactors,
makeIt100,
toFixedNumber,
} from 'src/utils/mathematical-logic';
import {
Expand Down Expand Up @@ -530,7 +531,7 @@ export class FlowService {
})),
];

return ranking.sort((a, b) => a.rank - b.rank);
return makeIt100(ranking.sort((a, b) => a.rank - b.rank));
};

// getRootRanking = async (userId: number) => {
Expand Down
34 changes: 17 additions & 17 deletions src/utils/mathematical-logic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,28 @@ const validate = (input: { share: number }[]) => {
return false;
};

// export function makeIt100<T extends { share: number }>(input: T[]) {
// let result = [...input];
export function makeIt100<T extends { share: number }>(input: T[]) {
let result = [...input];

// let breakLimit = 0;
// while (!validate(result) && breakLimit < 100) {
// const sum = result.reduce((acc, curr) => (acc += curr.share), 0);
let breakLimit = 0;
while (!validate(result) && breakLimit < 100) {
const sum = result.reduce((acc, curr) => (acc += curr.share), 0);

// const temp = result.map((item) => ({
// ...item,
// share: (item.share * 1) / sum,
// }));
const temp = result.map((item) => ({
...item,
share: (item.share * 1) / sum,
}));

// result = temp.map((item) => ({
// ...item,
// share: toFixedNumber(item.share, 6),
// }));
result = temp.map((item) => ({
...item,
share: toFixedNumber(item.share, 6),
}));

// breakLimit++;
// }
breakLimit++;
}

// return result;
// }
return result;
}

export const calculateCollectionRanking = (
input: number[][],
Expand Down

0 comments on commit 4953c37

Please sign in to comment.