Skip to content

Commit

Permalink
Show pricing per repository IowaComputerGurus#28
Browse files Browse the repository at this point in the history
  • Loading branch information
nivedithaskywalk committed Feb 16, 2024
1 parent 136b58f commit 564e24f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 52 deletions.
15 changes: 12 additions & 3 deletions src/GitHubCostVisualizer.Web/Models/UsageReportViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ public class UsageReportViewModel
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 List<KeyValuePair<string, int>> ActionMinutesByWorkflow { get; set; }
public List<ActionMinutesItem> ActionMinutesByRepository { get; set; }
public List<ActionMinutesItem> ActionMinutesByWorkflow { get; set; }
public decimal AverageDailyStorage { get; set; }
public List<KeyValuePair<DateTime, decimal>> DailyStorageSummary { get; set; }
public List<KeyValuePair<string, decimal>> AverageDailyStorageByRepo { get; set; }

public DailyStorageData DailyStorageByRepo { get; set; }
}

public class ActionMinutesItem
{
public string Repository { get; set; }
public decimal Minutes { get; set; }
public decimal TotalCost { get; set; }
public string Workflow { get; set; }
}


}
36 changes: 25 additions & 11 deletions src/GitHubCostVisualizer.Web/Processor/GithubUsageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,30 @@ 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.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase))
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();
into grp
select new ActionMinutesItem
{
Repository = grp.Key,
Minutes = grp.Sum(i => (int)i.Quantity),
TotalCost = grp.Sum(i => i.Quantity.GetValueOrDefault() * i.Multiplier.GetValueOrDefault() * i.PricePer.GetValueOrDefault())
}).ToList();

model.ActionMinutesByWorkflow = (from x in entries.Where(i =>
i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase))
group x by new { x.Repository, x.TrimmedWorkflow }
into grp
select new KeyValuePair<string, int>($"{grp.Key.Repository} - {grp.Key.TrimmedWorkflow}",
grp.Sum(i => (int)i.Quantity))).ToList();
i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase))
group x by new { x.Repository, x.TrimmedWorkflow }
into grp
select new ActionMinutesItem
{
Minutes = grp.Sum(i => (int)i.Quantity),
Workflow = ($"{grp.Key.Repository} - {grp.Key.TrimmedWorkflow}").ToString(),
TotalCost = grp.Sum(i => i.Quantity.GetValueOrDefault() * i.Multiplier.GetValueOrDefault() * i.PricePer.GetValueOrDefault())

}).ToList();


model.DailyStorageSummary = (from x in entries.Where(i => i.Product.Equals(Constants.GitHubProducts.SharedStorage, StringComparison.InvariantCultureIgnoreCase))
group x by x.Date
into grp
Expand Down Expand Up @@ -73,9 +87,9 @@ into grp
private DailyStorageData GenerateStorageByDays(List<GithubUsageEntry> entries)
{
var storage = entries.Where(e => e.Product.Equals(Constants.GitHubProducts.SharedStorage, StringComparison.InvariantCultureIgnoreCase)).ToList();
if(!storage.Any())
if (!storage.Any())
return new DailyStorageData();

var startDate = storage.Min(r => r.Date);
var endDate = storage.Max(r => r.Date);

Expand All @@ -94,7 +108,7 @@ from bd in byDay.DefaultIfEmpty()

return new DailyStorageData
{
Labels = dayList.Select(d=>d.ToShortDateString()).ToList(),
Labels = dayList.Select(d => d.ToShortDateString()).ToList(),
DataSets = results.ToList()
};
}
Expand Down
80 changes: 42 additions & 38 deletions src/GitHubCostVisualizer.Web/Views/Home/_ActionDetail.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@
<tr>
<th>Repository</th>
<th>Minutes</th>
<th>Estimated Cost</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.ActionMinutesByRepository)
{
<tr>
<td>@item.Key</td>
<td data-sort="@item.Value">@item.Value minutes</td>
<td>@item.Repository</td>
<td data-sort="@item.Minutes">@item.Minutes minutes</td>
<td data-sort="@item.TotalCost">$@item.TotalCost</td>
</tr>
}
</tbody>
Expand All @@ -77,51 +79,53 @@
<div class="tab-pane fade" id="nav-tab-action-repository-chart" role="tabpanel" aria-labelledby="nav-tab-action-repository-chart-tab">
<canvas id="action-minutes-by-repository-chart" width="300" height="250"></canvas>
<script>
var actionMinChartContext = $('#action-minutes-by-repository-chart');
var actionMinChart = new Chart(actionMinChartContext,
{
type: 'pie',
data: {
datasets: [
{
data: [@Html.Raw(string.Join(", ", Model.ActionMinutesByRepository.Select(s => s.Value)))],
backgroundColor: getColors(@Model.ActionMinutesByRepository.Count, 'primary', 'dark', 'secondary', 'light')
}
],
labels: [@Html.Raw(String.Join(", ", Model.ActionMinutesByRepository.Select(m => $"'{m.Key}'")))]
},
options: {
tooltips: {
enabled: true,
callbacks: {
label: function(tooltipItem, data) {
var label = data.labels[tooltipItem.index];
var val = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
return label + ':' + val + ' (' + (100 * val / @Html.Raw(Model.ActionMinutesByRepository.Sum(d => d.Value))).toFixed(2) + '%)';
var actionMinChartContext = $('#action-minutes-by-repository-chart');
var actionMinChart = new Chart(actionMinChartContext,
{
type: 'pie',
data: {
datasets: [
{
data: [@Html.Raw(string.Join(", ", Model.ActionMinutesByRepository.Select(s => s.Minutes)))],
backgroundColor: getColors(@Model.ActionMinutesByRepository.Count, 'primary', 'dark', 'secondary', 'light')
}
],
labels: [@Html.Raw(String.Join(", ", Model.ActionMinutesByRepository.Select(m => $"'{m.Repository}'")))]
},
options: {
tooltips: {
enabled: true,
callbacks: {
label: function (tooltipItem, data) {
var label = data.labels[tooltipItem.index];
var val = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
return label + ':' + val + ' (' + (100 * val / @Html.Raw(Model.ActionMinutesByRepository.Sum(d => d.Minutes))).toFixed(2) + '%)';
}
}
}
}
}
}
});
});
</script>
</div>
<div class="tab-pane" id="nav-tab-action-workflow-list" role="tabpanel" aria-labelledby="nav-tab-action-workflow-list-tab">
<table class="display w-100">
<thead>
<tr>
<th>Workflow (Repository - File)</th>
<th>Minutes</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.ActionMinutesByWorkflow)
{
<tr>
<td>@item.Key</td>
<td data-sort="@item.Value">@item.Value minutes</td>
<th>Workflow (Repository - File)</th>
<th>Minutes</th>
<th>Estimated Cost</th>
</tr>
}
</thead>
<tbody>
@foreach (var item in Model.ActionMinutesByWorkflow)
{
<tr>
<td>@item.Workflow</td>
<td data-sort="@item.Minutes">@item.Minutes minutes</td>
<td data-sort="@item.TotalCost">$@item.TotalCost</td>
</tr>
}
</tbody>
</table>
</div>
Expand Down Expand Up @@ -164,7 +168,7 @@
tooltips: {
enabled: true,
callbacks: {
label: function(tooltipItem, data) {
label: function (tooltipItem, data) {
var label = data.labels[tooltipItem.index];
var val = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
return label + ':' + val + ' (' + (100 * val / @Html.Raw(Model.ActionsSummary.Sum(d => d.Value))).toFixed(2) + '%)';
Expand Down

0 comments on commit 564e24f

Please sign in to comment.