Skip to content

Commit

Permalink
Merge pull request #37 from nivedithaj1/Show-pricing-per-repository#28
Browse files Browse the repository at this point in the history
Show pricing per repository #28
  • Loading branch information
mitchelsellers authored Feb 20, 2024
2 parents b0ee28f + 4251eb2 commit 5c071d4
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 52 deletions.
13 changes: 10 additions & 3 deletions src/GitHubCostVisualizer.Web/Models/UsageReportViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ 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 Label { get; set; }
public decimal Minutes { get; set; }
public decimal TotalCost { 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
{
Label = 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),
Label = ($"{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.Label</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.Label}'")))]
},
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.Label</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 5c071d4

Please sign in to comment.