Skip to content

Commit

Permalink
Add total cost in timeframe to output formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
camieleggermont committed May 31, 2024
1 parent b1edc74 commit ce77905
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/OutputFormatters/ConsoleOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public override Task WriteAccumulatedCost(AccumulatedCostSettings settings,
var costLastThirtyDays = accumulatedCostDetails.Costs.Where(x => x.Date >= todaysDate.AddDays(-30))
.Sum(a => settings.UseUSD ? a.CostUsd : a.Cost);

var totalCostInTimeframe = accumulatedCostDetails.Costs.Sum(a => settings.UseUSD ? a.CostUsd : a.Cost);

var currency = settings.UseUSD ? "USD" : accumulatedCostDetails.Costs.FirstOrDefault()?.Currency;

// Header
Expand Down Expand Up @@ -84,6 +86,7 @@ public override Task WriteAccumulatedCost(AccumulatedCostSettings settings,
new Money(costSinceStartOfCurrentMonth, currency));
table.AddRow(new Markup("[yellow bold]Last 7 days:[/]"), new Money(costLastSevenDays, currency));
table.AddRow(new Markup("[yellow bold]Last 30 days:[/]"), new Money(costLastThirtyDays, currency));
table.AddRow(new Markup("[yellow bold]Total in timeframe:[/]"), new Money(totalCostInTimeframe, currency));

var accumulatedCostChart = new BarChart()
.Width(60)
Expand Down
1 change: 1 addition & 0 deletions src/OutputFormatters/JsonOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public override Task WriteAccumulatedCost(AccumulatedCostSettings settings,Accum
.Sum(a => settings.UseUSD ? a.CostUsd : a.Cost),
lastThirtyDaysCost = accumulatedCostDetails.Costs.Where(a => a.Date >= DateOnly.FromDateTime(DateTime.UtcNow.AddDays(-30)))
.Sum(a => settings.UseUSD ? a.CostUsd : a.Cost),
totalCostInTimeframe = accumulatedCostDetails.Costs.Sum(a => settings.UseUSD ? a.CostUsd : a.Cost)
},
cost = accumulatedCostDetails.Costs.OrderBy(a => a.Date).Select(a => new { a.Date, a.Cost, a.Currency, a.CostUsd }),
forecastedCosts = accumulatedCostDetails.ForecastedCosts.OrderByDescending(a => a.Date)
Expand Down
2 changes: 2 additions & 0 deletions src/OutputFormatters/MarkdownOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public override Task WriteAccumulatedCost(AccumulatedCostSettings settings,Accum
.Sum(a => settings.UseUSD ? a.CostUsd :a.Cost),
lastThirtyDaysCost = accumulatedCostDetails.Costs.Where(a => a.Date >= DateOnly.FromDateTime(DateTime.UtcNow.AddDays(-30)))
.Sum(a => settings.UseUSD ? a.CostUsd :a.Cost),
totalCostInTimeframe = accumulatedCostDetails.Costs.Sum(a => settings.UseUSD ? a.CostUsd : a.Cost)
},
};

Expand All @@ -47,6 +48,7 @@ public override Task WriteAccumulatedCost(AccumulatedCostSettings settings,Accum
Console.WriteLine($"|Yesterday|{output.costs.yesterdayCost:N2} {currency}|");
Console.WriteLine($"|Last 7 days|{output.costs.lastSevenDaysCost:N2} {currency}|");
Console.WriteLine($"|Last 30 days|{output.costs.lastThirtyDaysCost:N2} {currency}|");
Console.WriteLine($"|Total cost in timeframe|{output.costs.totalCostInTimeframe:N2} {currency}|");

// Generate a gantt chart using mermaidjs
Console.WriteLine();
Expand Down
4 changes: 3 additions & 1 deletion src/OutputFormatters/TextOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public override Task WriteAccumulatedCost(AccumulatedCostSettings settings, Accu
.Sum(a => settings.UseUSD ? a.CostUsd : a.Cost),
lastThirtyDaysCost = accumulatedCostDetails.Costs.Where(a => a.Date >= DateOnly.FromDateTime(DateTime.UtcNow.AddDays(-30)))
.Sum(a => settings.UseUSD ? a.CostUsd : a.Cost),
totalCostInTimeframe = accumulatedCostDetails.Costs.Sum(a => settings.UseUSD ? a.CostUsd : a.Cost)
},
};

Expand All @@ -40,7 +41,8 @@ public override Task WriteAccumulatedCost(AccumulatedCostSettings settings, Accu
Console.WriteLine($" Yesterday: {output.costs.yesterdayCost:N2} {currency}");
Console.WriteLine($" Last 7 days: {output.costs.lastSevenDaysCost:N2} {currency}");
Console.WriteLine($" Last 30 days: {output.costs.lastThirtyDaysCost:N2} {currency}");

Console.WriteLine($" Total cost in timeframe: {output.costs.totalCostInTimeframe:N2} {currency}");

Console.WriteLine();
Console.WriteLine("By Service Name:");
foreach (var cost in accumulatedCostDetails.ByServiceNameCosts.TrimList(threshold: settings.OthersCutoff))
Expand Down

0 comments on commit ce77905

Please sign in to comment.