Skip to content

Commit

Permalink
Updated to resolve issues from file format change
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelsellers committed Jun 7, 2022
1 parent bcafd63 commit 977b007
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
10 changes: 8 additions & 2 deletions Source/GitHubCostVisualizer.Web/Models/GithubUsageEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyValuePair<string, int>> ActionsSummary { get; set; }
public List<KeyValuePair<string, int>> ActionMinutesByRepository { get; set; }
public decimal AverageDailyStorage { get; set; }
Expand Down
22 changes: 13 additions & 9 deletions Source/GitHubCostVisualizer.Web/Processor/GithubUsageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ public UsageReportViewModel ProcessUsageReport(List<GithubUsageEntry> 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<string, int>(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<string, int>(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<DateTime, decimal>(grp.Key, grp.Sum(i => i.Quantity)))
Expand All @@ -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<string, decimal>(grp.Key, grp.Sum(i => i.Quantity) / grp.Count())).ToList();
Expand All @@ -56,7 +62,7 @@ into grp

private DailyStorageData GenerateStorageByDays(List<GithubUsageEntry> 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);

Expand All @@ -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<DateTime, decimal>(r.Date, r.Quantity)).ToArray());
//results.Dump();

return new DailyStorageData
{
Expand Down
21 changes: 18 additions & 3 deletions Source/GitHubCostVisualizer.Web/Views/Home/_SummaryItems.cshtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@model UsageReportViewModel

<div class="row">
<div class="col-md-4">
<div class="col-md-3">
<div class="stat-box card card-primary card-darker card-full">
<div class="card-header d-block">
<div class="row align-items-center justify-content-between flex-nowrap">
<div class="col-auto">
<span class="display-5">@Model.TotalActionMinutesUsed</span>
<span class="display-5">@Model.TotalActionMinutesUsed.ToString("N0")</span>
<h5>Total Action Minutes</h5>
</div>
<div class="col-auto">
Expand All @@ -16,7 +16,22 @@
</div>
</div>
</div>
<div class="col-md-4">
<div class="col-md-3">
<div class="stat-box card card-primary card-darker card-full">
<div class="card-header d-block">
<div class="row align-items-center justify-content-between flex-nowrap">
<div class="col-auto">
<span class="display-5">@Model.TotalBillableActionMinutes.ToString("N0") (@Model.TotalActionMinutesCost.ToString("C"))</span>
<h5>Total Billable Action Minutes</h5>
</div>
<div class="col-auto">
<i class="fas fa-stopwatch"></i>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="stat-box card card-primary card-darker card-full">
<div class="card-header d-block">
<div class="row align-items-center justify-content-between flex-nowrap">
Expand Down

0 comments on commit 977b007

Please sign in to comment.