From 977b007d2cfa094fe083baad40d53b9321062941 Mon Sep 17 00:00:00 2001 From: Mitchel Sellers Date: Tue, 7 Jun 2022 02:33:15 -0500 Subject: [PATCH] Updated to resolve issues from file format change --- .../Models/GithubUsageEntry.cs | 10 +++++++-- .../Models/UsageReportViewModel.cs | 2 ++ .../Processor/GithubUsageProcessor.cs | 22 +++++++++++-------- .../Views/Home/_SummaryItems.cshtml | 21 +++++++++++++++--- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/Source/GitHubCostVisualizer.Web/Models/GithubUsageEntry.cs b/Source/GitHubCostVisualizer.Web/Models/GithubUsageEntry.cs index b4882c4..eb9d110 100644 --- a/Source/GitHubCostVisualizer.Web/Models/GithubUsageEntry.cs +++ b/Source/GitHubCostVisualizer.Web/Models/GithubUsageEntry.cs @@ -11,14 +11,20 @@ public class GithubUsageEntry public string Product { get; set; } [Name("Repository Slug")] public string Repository { get; set; } + [Name("SKU")] + public string Sku { get; set; } [Name("Quantity")] public decimal Quantity { get; set; } [Name("Unit Type")] public string UnitType { get; set; } - [Name("Price Per Unit")] - public string PricePer { get; set; } + [Name("Price Per Unit ($)")] + public decimal PricePer { get; set; } + [Name("Multiplier")] + public decimal Multiplier { get; set; } [Name("Actions Workflow")] public string ActionWorkflow { get; set; } + [Name("Username")] + public string Username { get; set; } [Name("Notes")] public string Notes { get; set; } } diff --git a/Source/GitHubCostVisualizer.Web/Models/UsageReportViewModel.cs b/Source/GitHubCostVisualizer.Web/Models/UsageReportViewModel.cs index e3e534a..2d98e7c 100644 --- a/Source/GitHubCostVisualizer.Web/Models/UsageReportViewModel.cs +++ b/Source/GitHubCostVisualizer.Web/Models/UsageReportViewModel.cs @@ -27,6 +27,8 @@ public class UsageReportViewModel public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public int TotalActionMinutesUsed { get; set; } + public int TotalBillableActionMinutes { get; set; } + public decimal TotalActionMinutesCost { get; set; } public List> ActionsSummary { get; set; } public List> ActionMinutesByRepository { get; set; } public decimal AverageDailyStorage { get; set; } diff --git a/Source/GitHubCostVisualizer.Web/Processor/GithubUsageProcessor.cs b/Source/GitHubCostVisualizer.Web/Processor/GithubUsageProcessor.cs index aa2afe8..8a11d4c 100644 --- a/Source/GitHubCostVisualizer.Web/Processor/GithubUsageProcessor.cs +++ b/Source/GitHubCostVisualizer.Web/Processor/GithubUsageProcessor.cs @@ -20,18 +20,24 @@ public UsageReportViewModel ProcessUsageReport(List entries) model.StartDate = entries.Min(i => i.Date); model.EndDate = entries.Max(i => i.Date); model.TotalActionMinutesUsed = - entries.Where(i => i.Product == "actions").Sum(i => (int)i.Quantity); - model.ActionsSummary = (from x in entries.Where(i => i.Product == "actions") - group x by x.UnitType + entries.Where(i => i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase)).Sum(i => (int)i.Quantity); + model.TotalBillableActionMinutes = entries + .Where(i => i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase)) + .Sum(i => (int)(i.Quantity * i.Multiplier)); + model.TotalActionMinutesCost = entries + .Where(i => i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase)) + .Sum(i => i.Quantity * i.Multiplier * i.PricePer); + model.ActionsSummary = (from x in entries.Where(i => i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase)) + group x by x.Sku into grp select new KeyValuePair(grp.Key, grp.Sum(i => (int)i.Quantity))) .ToList(); - model.ActionMinutesByRepository = (from x in entries.Where(i => i.Product == Constants.GitHubProducts.Actions) + model.ActionMinutesByRepository = (from x in entries.Where(i => i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase)) group x by x.Repository into grp select new KeyValuePair(grp.Key, grp.Sum(i => (int)i.Quantity))).ToList(); - model.DailyStorageSummary = (from x in entries.Where(i => i.Product == "shared storage") + model.DailyStorageSummary = (from x in entries.Where(i => i.Product.Equals(Constants.GitHubProducts.SharedStorage, StringComparison.InvariantCultureIgnoreCase)) group x by x.Date into grp select new KeyValuePair(grp.Key, grp.Sum(i => i.Quantity))) @@ -45,7 +51,7 @@ into grp model.DailyStorageSummary.Sum(i => i.Value) / model.DailyStorageSummary.Count; var totalDays = model.DailyStorageSummary.Count(); - model.AverageDailyStorageByRepo = (from x in entries.Where(i => i.Product == Constants.GitHubProducts.SharedStorage) + model.AverageDailyStorageByRepo = (from x in entries.Where(i => i.Product.Equals(Constants.GitHubProducts.SharedStorage, StringComparison.InvariantCultureIgnoreCase)) group x by x.Repository into grp select new KeyValuePair(grp.Key, grp.Sum(i => i.Quantity) / grp.Count())).ToList(); @@ -56,7 +62,7 @@ into grp private DailyStorageData GenerateStorageByDays(List entries) { - var storage = entries.Where(e => e.Product == Constants.GitHubProducts.SharedStorage).ToList(); + var storage = entries.Where(e => e.Product.Equals(Constants.GitHubProducts.SharedStorage, StringComparison.InvariantCultureIgnoreCase)).ToList(); var startDate = storage.Min(r => r.Date); var endDate = storage.Max(r => r.Date); @@ -72,8 +78,6 @@ from bd in byDay.DefaultIfEmpty() var results = q.GroupBy(k => k.Repo) .OrderBy(g => g.Key) .Select(g => new DailyStorageDataSet { Label = g.Key, Data = g.OrderBy(r => r.Date).Select(r => r.Quantity).ToList() }); - //.Select(r=>new KeyValuePair(r.Date, r.Quantity)).ToArray()); - //results.Dump(); return new DailyStorageData { diff --git a/Source/GitHubCostVisualizer.Web/Views/Home/_SummaryItems.cshtml b/Source/GitHubCostVisualizer.Web/Views/Home/_SummaryItems.cshtml index 12d410e..5837ed7 100644 --- a/Source/GitHubCostVisualizer.Web/Views/Home/_SummaryItems.cshtml +++ b/Source/GitHubCostVisualizer.Web/Views/Home/_SummaryItems.cshtml @@ -1,12 +1,12 @@ @model UsageReportViewModel
-
+
- @Model.TotalActionMinutesUsed + @Model.TotalActionMinutesUsed.ToString("N0")
Total Action Minutes
@@ -16,7 +16,22 @@
-
+
+
+
+
+
+ @Model.TotalBillableActionMinutes.ToString("N0") (@Model.TotalActionMinutesCost.ToString("C")) +
Total Billable Action Minutes
+
+
+ +
+
+
+
+
+