Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Ensure .NET Installed
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x

- name: Install GitVersion
run: dotnet tool install --global GitVersion.Tool
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Ensure .NET Installed
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x

- name: Install GitVersion
run: dotnet tool install --global GitVersion.Tool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

Expand Down
19 changes: 19 additions & 0 deletions Source/GitHubCostVisualizer.Web/Models/UsageReportViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;


namespace GitHubCostVisualizer.Web.Models
{
public class DailyStorageData
{
[JsonPropertyName("labels")]
public List<string> Labels { get; set; }
[JsonPropertyName("datasets")]
public List<DailyStorageDataSet> DataSets { get; set; }
}

public class DailyStorageDataSet
{
[JsonPropertyName("label")]
public string Label { get; set; }
[JsonPropertyName("data")]
public List<decimal> Data { get; set; }
}


public class UsageReportViewModel
{
public DateTime StartDate { get; set; }
Expand All @@ -15,5 +33,6 @@ public class UsageReportViewModel
public List<KeyValuePair<DateTime, decimal>> DailyStorageSummary { get; set; }
public List<KeyValuePair<string, decimal>> AverageDailyStorageByRepo { get; set; }

public DailyStorageData DailyStorageByRepo { get; set; }
}
}
35 changes: 33 additions & 2 deletions Source/GitHubCostVisualizer.Web/Processor/GithubUsageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,50 @@ group x by x.Date
into grp
select new KeyValuePair<DateTime, decimal>(grp.Key, grp.Sum(i => i.Quantity)))
.ToList();

model.DailyStorageByRepo = GenerateStorageByDays(entries);

if (model.DailyStorageSummary.Count > 0)
{
model.AverageDailyStorage =
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)
group x by x.Repository
group x by x.Repository
into grp
select new KeyValuePair<string, decimal>(grp.Key, grp.Sum(i => i.Quantity) / grp.Count())).ToList();
select new KeyValuePair<string, decimal>(grp.Key, grp.Sum(i => i.Quantity) / grp.Count())).ToList();
}

return model;
}

private DailyStorageData GenerateStorageByDays(List<GithubUsageEntry> entries)
{
var storage = entries.Where(e => e.Product == Constants.GitHubProducts.SharedStorage).ToList();
var startDate = storage.Min(r => r.Date);
var endDate = storage.Max(r => r.Date);

var repos = storage.Select(r => r.Repository).Distinct().OrderBy(r => r);
var dayList = Enumerable.Range(0, 1 + endDate.Subtract(startDate).Days).Select(o => startDate.AddDays(o)).ToList();

var q = from r in repos
from d in dayList
join s in storage on new { r, d } equals new { r = s.Repository, d = s.Date } into byDay
from bd in byDay.DefaultIfEmpty()
select new { Repo = r, Date = d, Quantity = bd?.Quantity ?? 0 };

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
{
Labels = dayList.Select(d=>d.ToShortDateString()).ToList(),
DataSets = results.ToList()
};
}
}
}
111 changes: 87 additions & 24 deletions Source/GitHubCostVisualizer.Web/Views/Home/_StorageDetail.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@model UsageReportViewModel
@using System.Text.Json
@model UsageReportViewModel


<div class="card">
Expand All @@ -25,6 +26,15 @@
aria-selected="False">
Chart
</a>
<a class="nav-item nav-link"
id="nav-tab-storage-repository-daily-chart-tab"
data-toggle="tab"
href="#nav-tab-storage-repository-daily-chart"
role="tab"
aria-controls="nav-tab-storage-repository-chart"
aria-selected="False">
Chart By Day
</a>
</div>
</nav>
<div class="tab-content">
Expand All @@ -50,33 +60,86 @@
<div class="tab-pane fade" id="nav-tab-storage-repository-chart" role="tabpanel" aria-labelledby="nav-tab-storage-repository-chart-tab">
<canvas id="action-storage-by-repository-chart" width="300" height="250"></canvas>
<script>
var actionStorageChartContext = $('#action-storage-by-repository-chart');
var actionStorageChart = new Chart(actionStorageChartContext,
{
type: 'pie',
data: {
datasets: [
{
data: [@Html.Raw(string.Join(", ", Model.AverageDailyStorageByRepo.Select(s => s.Value)))],
backgroundColor: getColors(@Model.AverageDailyStorageByRepo.Count, 'primary', 'dark', 'secondary', 'light')
}
],
labels: [@Html.Raw(String.Join(", ", Model.AverageDailyStorageByRepo.Select(m => $"'{m.Key}'")))]
var actionStorageChartContext = $('#action-storage-by-repository-chart');
var actionStorageChart = new Chart(actionStorageChartContext,
{
type: 'pie',
data: {
datasets: [
{
data: [@Html.Raw(string.Join(", ", Model.AverageDailyStorageByRepo.Select(s => s.Value)))],
backgroundColor: getColors(@Model.AverageDailyStorageByRepo.Count, 'primary', 'dark', 'secondary', 'light')
}
],
labels: [@Html.Raw(String.Join(", ", Model.AverageDailyStorageByRepo.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.AverageDailyStorageByRepo.Sum(d => d.Value))).toFixed(2) + '%)';
}
}

}
}
});
</script>
</div>
<div class="tab-pane fade" id="nav-tab-storage-repository-daily-chart" role="tabpanel" aria-labelledby="nav-tab-storage-repository-daily-chart-tab">
<canvas id="action-storage-by-repository-daily-chart" width="300" height="250"></canvas>
<script>
var allData = @Html.Raw(JsonSerializer.Serialize(Model.DailyStorageByRepo));
var colors = getColors(allData.datasets.length, 'primary', 'dark', 'secondary', 'light');

var ds = allData.datasets.map(function(e, i) {
return {
fill: false,
label: e.label,
data: e.data,
borderColor: colors[i]
}
});
allData.datasets = ds;
var actionStorageByDayChartContext = $('#action-storage-by-repository-daily-chart');
var actionStorageByDayChart = new Chart(actionStorageByDayChartContext,
{
type: 'line',
data: allData,

options: {
scales: {
x: {
type: "time",
display: true,
time: { unit: "day" }
},
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.AverageDailyStorageByRepo.Sum(d => d.Value))).toFixed(2) + '%)';
}
y: {
title: { display: true, text: "Storage"},
ticks: {
callback: function(val, index) {
console.log(val, index);
return val + "GB";
}

}
}
});
},
tooltips: {
enabled: true,
callbacks: {
label: function(tooltipItem, data) {
var label = data.datasets[tooltipItem.datasetIndex].label;
var val = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
return label + ':' + val + "GB";
}
}

}
}
});
</script>
</div>
</div>
Expand Down
25 changes: 0 additions & 25 deletions Source/Source.sln

This file was deleted.