29 lines
1,017 B
TypeScript
29 lines
1,017 B
TypeScript
|
|
import { consolidatedMonthlyCost } from './data/config.js';
|
||
|
|
import { outlaws } from './data/outlaws.js';
|
||
|
|
import { computePersonalScore, computeProjectedScore } from './scoring.js';
|
||
|
|
import type { OffRampPayload, ScoreModel } from './types.js';
|
||
|
|
|
||
|
|
export function computeOffRamp(
|
||
|
|
selectedIds: string[],
|
||
|
|
scoreModel: ScoreModel = 'weighted_average',
|
||
|
|
): OffRampPayload {
|
||
|
|
const replaceableTools = selectedIds
|
||
|
|
.map((id) => outlaws.find((o) => o.id === id))
|
||
|
|
.filter((o) => o && !o.sovereign) as typeof outlaws;
|
||
|
|
|
||
|
|
const currentScore = computePersonalScore(selectedIds, scoreModel);
|
||
|
|
const projectedScore = computeProjectedScore(selectedIds, scoreModel);
|
||
|
|
|
||
|
|
const monthlyFragmented = replaceableTools.reduce(
|
||
|
|
(sum, o) => sum + (o.monthlyCost ?? o.bounty),
|
||
|
|
0,
|
||
|
|
);
|
||
|
|
|
||
|
|
return {
|
||
|
|
replaceableTools,
|
||
|
|
projectedScore,
|
||
|
|
projectedMonthlyCost: consolidatedMonthlyCost,
|
||
|
|
monthlySavings: Math.max(0, monthlyFragmented - consolidatedMonthlyCost),
|
||
|
|
sovereigntyGain: projectedScore - currentScore,
|
||
|
|
};
|
||
|
|
}
|