Skip to main content
Glama
summary-calculator.ts1.42 kB
import type { MonthData } from '../../types.js'; export class MonthlySummaryCalculator { calculateAverages(sortedMonths: MonthData[]): { avgIncome: number; avgExpenses: number; avgInvestments: number; avgTraditionalSavings: number; avgTotalSavings: number; avgTraditionalSavingsRate: number; avgTotalSavingsRate: number; } { const totalIncome = sortedMonths.reduce((sum, m) => sum + m.income, 0); const totalExpenses = sortedMonths.reduce((sum, m) => sum + m.expenses, 0); const totalInvestments = sortedMonths.reduce((sum, m) => sum + m.investments, 0); const monthCount = sortedMonths.length; const avgIncome = monthCount > 0 ? totalIncome / monthCount : 0; const avgExpenses = monthCount > 0 ? totalExpenses / monthCount : 0; const avgInvestments = monthCount > 0 ? totalInvestments / monthCount : 0; const avgTraditionalSavings = avgIncome - avgExpenses - avgInvestments; const avgTotalSavings = avgTraditionalSavings + avgInvestments; const avgTraditionalSavingsRate = avgIncome > 0 ? (avgTraditionalSavings / avgIncome) * 100 : 0; const avgTotalSavingsRate = avgIncome > 0 ? ((avgTraditionalSavings + avgInvestments) / avgIncome) * 100 : 0; return { avgIncome, avgExpenses, avgInvestments, avgTraditionalSavings, avgTotalSavings, avgTraditionalSavingsRate, avgTotalSavingsRate, }; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/s-stefanov/actual-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server