Skip to content

Commit 5c071d4

Browse files
Merge pull request #37 from nivedithaj1/Show-pricing-per-repository#28
Show pricing per repository #28
2 parents b0ee28f + 4251eb2 commit 5c071d4

File tree

3 files changed

+77
-52
lines changed

3 files changed

+77
-52
lines changed

src/GitHubCostVisualizer.Web/Models/UsageReportViewModel.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@ public class UsageReportViewModel
3030
public int TotalBillableActionMinutes { get; set; }
3131
public decimal TotalActionMinutesCost { get; set; }
3232
public List<KeyValuePair<string, int>> ActionsSummary { get; set; }
33-
public List<KeyValuePair<string, int>> ActionMinutesByRepository { get; set; }
34-
public List<KeyValuePair<string, int>> ActionMinutesByWorkflow { get; set; }
33+
public List<ActionMinutesItem> ActionMinutesByRepository { get; set; }
34+
public List<ActionMinutesItem> ActionMinutesByWorkflow { get; set; }
3535
public decimal AverageDailyStorage { get; set; }
3636
public List<KeyValuePair<DateTime, decimal>> DailyStorageSummary { get; set; }
3737
public List<KeyValuePair<string, decimal>> AverageDailyStorageByRepo { get; set; }
38-
3938
public DailyStorageData DailyStorageByRepo { get; set; }
4039
}
40+
41+
public class ActionMinutesItem
42+
{
43+
public string Label { get; set; }
44+
public decimal Minutes { get; set; }
45+
public decimal TotalCost { get; set; }
46+
}
47+
4148
}

src/GitHubCostVisualizer.Web/Processor/GithubUsageProcessor.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,30 @@ group x by x.Sku
3131
into grp
3232
select new KeyValuePair<string, int>(grp.Key, grp.Sum(i => (int)i.Quantity)))
3333
.ToList();
34-
model.ActionMinutesByRepository = (from x in entries.Where(i => i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase))
34+
model.ActionMinutesByRepository = (from x in entries.Where(i =>
35+
i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase))
3536
group x by x.Repository
36-
into grp
37-
select new KeyValuePair<string, int>(grp.Key, grp.Sum(i => (int)i.Quantity))).ToList();
37+
into grp
38+
select new ActionMinutesItem
39+
{
40+
Label = grp.Key,
41+
Minutes = grp.Sum(i => (int)i.Quantity),
42+
TotalCost = grp.Sum(i => i.Quantity.GetValueOrDefault() * i.Multiplier.GetValueOrDefault() * i.PricePer.GetValueOrDefault())
43+
}).ToList();
44+
3845
model.ActionMinutesByWorkflow = (from x in entries.Where(i =>
39-
i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase))
40-
group x by new { x.Repository, x.TrimmedWorkflow }
41-
into grp
42-
select new KeyValuePair<string, int>($"{grp.Key.Repository} - {grp.Key.TrimmedWorkflow}",
43-
grp.Sum(i => (int)i.Quantity))).ToList();
46+
i.Product.Equals(Constants.GitHubProducts.Actions, StringComparison.InvariantCultureIgnoreCase))
47+
group x by new { x.Repository, x.TrimmedWorkflow }
48+
into grp
49+
select new ActionMinutesItem
50+
{
51+
Minutes = grp.Sum(i => (int)i.Quantity),
52+
Label = ($"{grp.Key.Repository} - {grp.Key.TrimmedWorkflow}").ToString(),
53+
TotalCost = grp.Sum(i => i.Quantity.GetValueOrDefault() * i.Multiplier.GetValueOrDefault() * i.PricePer.GetValueOrDefault())
54+
55+
}).ToList();
56+
57+
4458
model.DailyStorageSummary = (from x in entries.Where(i => i.Product.Equals(Constants.GitHubProducts.SharedStorage, StringComparison.InvariantCultureIgnoreCase))
4559
group x by x.Date
4660
into grp
@@ -73,9 +87,9 @@ into grp
7387
private DailyStorageData GenerateStorageByDays(List<GithubUsageEntry> entries)
7488
{
7589
var storage = entries.Where(e => e.Product.Equals(Constants.GitHubProducts.SharedStorage, StringComparison.InvariantCultureIgnoreCase)).ToList();
76-
if(!storage.Any())
90+
if (!storage.Any())
7791
return new DailyStorageData();
78-
92+
7993
var startDate = storage.Min(r => r.Date);
8094
var endDate = storage.Max(r => r.Date);
8195

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

95109
return new DailyStorageData
96110
{
97-
Labels = dayList.Select(d=>d.ToShortDateString()).ToList(),
111+
Labels = dayList.Select(d => d.ToShortDateString()).ToList(),
98112
DataSets = results.ToList()
99113
};
100114
}

src/GitHubCostVisualizer.Web/Views/Home/_ActionDetail.cshtml

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@
6161
<tr>
6262
<th>Repository</th>
6363
<th>Minutes</th>
64+
<th>Estimated Cost</th>
6465
</tr>
6566
</thead>
6667
<tbody>
6768
@foreach (var item in Model.ActionMinutesByRepository)
6869
{
6970
<tr>
70-
<td>@item.Key</td>
71-
<td data-sort="@item.Value">@item.Value minutes</td>
71+
<td>@item.Label</td>
72+
<td data-sort="@item.Minutes">@item.Minutes minutes</td>
73+
<td data-sort="@item.TotalCost">$@item.TotalCost</td>
7274
</tr>
7375
}
7476
</tbody>
@@ -77,51 +79,53 @@
7779
<div class="tab-pane fade" id="nav-tab-action-repository-chart" role="tabpanel" aria-labelledby="nav-tab-action-repository-chart-tab">
7880
<canvas id="action-minutes-by-repository-chart" width="300" height="250"></canvas>
7981
<script>
80-
var actionMinChartContext = $('#action-minutes-by-repository-chart');
81-
var actionMinChart = new Chart(actionMinChartContext,
82-
{
83-
type: 'pie',
84-
data: {
85-
datasets: [
86-
{
87-
data: [@Html.Raw(string.Join(", ", Model.ActionMinutesByRepository.Select(s => s.Value)))],
88-
backgroundColor: getColors(@Model.ActionMinutesByRepository.Count, 'primary', 'dark', 'secondary', 'light')
89-
}
90-
],
91-
labels: [@Html.Raw(String.Join(", ", Model.ActionMinutesByRepository.Select(m => $"'{m.Key}'")))]
92-
},
93-
options: {
94-
tooltips: {
95-
enabled: true,
96-
callbacks: {
97-
label: function(tooltipItem, data) {
98-
var label = data.labels[tooltipItem.index];
99-
var val = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
100-
return label + ':' + val + ' (' + (100 * val / @Html.Raw(Model.ActionMinutesByRepository.Sum(d => d.Value))).toFixed(2) + '%)';
82+
var actionMinChartContext = $('#action-minutes-by-repository-chart');
83+
var actionMinChart = new Chart(actionMinChartContext,
84+
{
85+
type: 'pie',
86+
data: {
87+
datasets: [
88+
{
89+
data: [@Html.Raw(string.Join(", ", Model.ActionMinutesByRepository.Select(s => s.Minutes)))],
90+
backgroundColor: getColors(@Model.ActionMinutesByRepository.Count, 'primary', 'dark', 'secondary', 'light')
91+
}
92+
],
93+
labels: [@Html.Raw(String.Join(", ", Model.ActionMinutesByRepository.Select(m => $"'{m.Label}'")))]
94+
},
95+
options: {
96+
tooltips: {
97+
enabled: true,
98+
callbacks: {
99+
label: function (tooltipItem, data) {
100+
var label = data.labels[tooltipItem.index];
101+
var val = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
102+
return label + ':' + val + ' (' + (100 * val / @Html.Raw(Model.ActionMinutesByRepository.Sum(d => d.Minutes))).toFixed(2) + '%)';
103+
}
101104
}
102-
}
103105
106+
}
104107
}
105-
}
106-
});
108+
});
107109
</script>
108110
</div>
109111
<div class="tab-pane" id="nav-tab-action-workflow-list" role="tabpanel" aria-labelledby="nav-tab-action-workflow-list-tab">
110112
<table class="display w-100">
111113
<thead>
112-
<tr>
113-
<th>Workflow (Repository - File)</th>
114-
<th>Minutes</th>
115-
</tr>
116-
</thead>
117-
<tbody>
118-
@foreach (var item in Model.ActionMinutesByWorkflow)
119-
{
120114
<tr>
121-
<td>@item.Key</td>
122-
<td data-sort="@item.Value">@item.Value minutes</td>
115+
<th>Workflow (Repository - File)</th>
116+
<th>Minutes</th>
117+
<th>Estimated Cost</th>
123118
</tr>
124-
}
119+
</thead>
120+
<tbody>
121+
@foreach (var item in Model.ActionMinutesByWorkflow)
122+
{
123+
<tr>
124+
<td>@item.Label</td>
125+
<td data-sort="@item.Minutes">@item.Minutes minutes</td>
126+
<td data-sort="@item.TotalCost">$@item.TotalCost</td>
127+
</tr>
128+
}
125129
</tbody>
126130
</table>
127131
</div>
@@ -164,7 +168,7 @@
164168
tooltips: {
165169
enabled: true,
166170
callbacks: {
167-
label: function(tooltipItem, data) {
171+
label: function (tooltipItem, data) {
168172
var label = data.labels[tooltipItem.index];
169173
var val = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
170174
return label + ':' + val + ' (' + (100 * val / @Html.Raw(Model.ActionsSummary.Sum(d => d.Value))).toFixed(2) + '%)';

0 commit comments

Comments
 (0)