Sign in with a code, made-up data without Plaid, and easier everyday use
- Sign in with a code from your email (the link still works); setup item for the code email - Use made-up data: a pretend bank with three months of spending, no Plaid account needed - Is this your pay? when regular money in is filed as something else, with a one-press fix - They look right: keep every bank-given category in one press - Your week on Home, Plan in the main menu, history start per bank on Accounts - A new version of broke is ready, in the sidebar and Settings - Start skips the rebuild when nothing changed; country screen says it was guessed - Fix: skipping banks no longer sends you back to setup Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
37a97fe20a
commit
73208b79df
30 files changed
+496
-39
No files matched your search
@@ -0,0 +1,28 @@
|
||||
// Pay that landed in the wrong category: money coming in from the same name, regularly, at about the same amount,
|
||||
// filed as anything but income. Pure, no "@/" imports: `node src/lib/pay.test.ts` runs it.
|
||||
|
||||
export type PayRow = { name: string; date: string; amount: number; kind: string | null }; // amount < 0 is money in
|
||||
export type PayGuess = { name: string; typical: number; every: "week" | "2 weeks" | "month"; count: number };
|
||||
|
||||
const mid = (ns: number[]) => [...ns].sort((a, b) => a - b)[Math.floor(ns.length / 2)];
|
||||
|
||||
export function payGuess(rows: PayRow[], skip: string[] = []): PayGuess | null {
|
||||
const by = new Map<string, PayRow[]>();
|
||||
for (const r of rows) {
|
||||
if (r.amount >= -200 || r.kind === "income" || r.kind === "transfer" || skip.includes(r.name)) continue;
|
||||
by.set(r.name, [...(by.get(r.name) ?? []), r]);
|
||||
}
|
||||
const found: PayGuess[] = [];
|
||||
for (const [name, rs] of by) {
|
||||
if (rs.length < 2) continue;
|
||||
const amounts = rs.map((r) => -r.amount), typical = mid(amounts);
|
||||
if (amounts.some((a) => Math.abs(a - typical) > typical * 0.25)) continue; // pay is about the same each time
|
||||
const days = [...rs].sort((a, b) => a.date.localeCompare(b.date)).map((r) => Date.parse(r.date) / 864e5);
|
||||
const gap = mid(days.slice(1).map((d, i) => d - days[i]));
|
||||
const every = gap >= 5 && gap <= 9 ? "week" : gap >= 12 && gap <= 17 ? "2 weeks" : gap >= 26 && gap <= 35 ? "month" : null;
|
||||
if (every) found.push({ name, typical: Math.round(typical), every, count: rs.length });
|
||||
}
|
||||
// The biggest by month: that's the main pay.
|
||||
const monthly = (p: PayGuess) => p.typical * (p.every === "week" ? 52 : p.every === "2 weeks" ? 26 : 12);
|
||||
return found.sort((a, b) => monthly(b) - monthly(a))[0] ?? null;
|
||||
}
|
||||
Reference in new issue
Block a user