Skip to content

Commit

Permalink
feat: The graphs are ugly and non-interactive, but eh..
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Jan 6, 2024
1 parent 41e822f commit 66d91f1
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 94 deletions.
152 changes: 60 additions & 92 deletions CFLookup/Pages/MinecraftModStatsOverTime.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,112 +7,80 @@
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load('current', { packages: ['linechart'] });
google.charts.setOnLoadCallback(drawMinecraftChart);
google.charts.setOnLoadCallback(drawAllCharts);
function drawMinecraftChart() {
var data = new google.visualization.DataTable();
function drawAllCharts() {
@foreach(var stat in Model.Stats)
{
<text>drawMinecraft</text>@stat.Key<text>Chart();</text>
}
}
@foreach(var stat in Model.Stats)
{
<text>
function drawMinecraft</text>@stat.Key<text>Chart() {
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Time');
data.addColumn('string', 'Game version');
data.addColumn('number', 'Forge');
data.addColumn('number', 'Fabric');
data.addColumn('number', 'Quilt');
data.addColumn('number', 'NeoForge');
data.addColumn('datetime', 'Time');
@foreach(var gameVersion in stat.Value.FirstOrDefault().Value.Keys)
{
<text>data.addColumn('number', '@gameVersion');</text>
}
const jsonData = @Html.Raw(Json.Serialize(Model.Stats));
const jsonData = @Html.Raw(Json.Serialize(stat.Value));
for(var stat in jsonData)
{
let rowData = jsonData[stat];
for(var gameVersion in rowData)
for(var stat in jsonData)
{
let rowData = jsonData[stat];
let row = [];
row.push(new Date(stat));
row.push(gameVersion);
row.push(rowData[gameVersion]["Forge"]);
row.push(rowData[gameVersion]["Fabric"]);
row.push(rowData[gameVersion]["Quilt"]);
row.push(rowData[gameVersion]["NeoForge"]);
for(var gameVersion in rowData)
{
row.push(rowData[gameVersion]);
}
console.log(row);
data.addRow(row);
}
}
var options = {
title: 'Number of Minecraft mods per game version, per mod loader',
height: '700',
width: '100%',
isStacked: true,
legend: {
position: 'bottom',
textStyle: { color: '#6c757d' }
},
vAxis: {
title: 'Minecraft game version',
titleTextStyle: { color: '#6c757d' },
textStyle: { color: '#6c757d' },
gridlines: { color: '#787878' }
},
backgroundColor: { fill: 'transparent' },
titleTextStyle: {
color: '#fff'
},
hAxis: {
textStyle: { color: '#6c757d' },
titleTextStyle: { color: '#6c757d' },
gridlines: { color: '#787878' },
title: 'Time'
}
};
var options = {
title: 'Number of Minecraft mods per game version, @stat.Key',
height: '700',
width: '100%',
isStacked: true,
legend: {
position: 'bottom',
textStyle: { color: '#6c757d' }
},
vAxis: {
title: 'Minecraft game version',
titleTextStyle: { color: '#6c757d' },
textStyle: { color: '#6c757d' },
gridlines: { color: '#787878' }
},
backgroundColor: { fill: 'transparent' },
titleTextStyle: {
color: '#fff'
},
hAxis: {
textStyle: { color: '#6c757d' },
titleTextStyle: { color: '#6c757d' },
gridlines: { color: '#787878' },
title: 'Time'
}
};
var chart = new google.visualization.LineChart(document.getElementById('minecraft-version-modloader'));
var chart = new google.visualization.LineChart(document.getElementById('minecraft-version-modloader-@stat.Key'));
chart.draw(data, options);
chart.draw(data, options);
}
</text>
}
</script>
}

<div id="minecraft-version-modloader"></div>

<table class="table table-dark table-striped table-condensed">
<thead>
<tr>
<th scope="col">Timestamp</th>
<th scope="col" class="text-end">VersionInfo</th>
</tr>
</thead>
<tbody>
@foreach(var stat in Model.Stats)
{
<tr>
<td scope="row">@stat.Key</td>
<td>
<table class="table table-dark table-striped table-condensed">
<thead>
<tr>
<th scope="col">Game version</th>
<th scope="col">Forge</th>
<th scope="col">Fabric</th>
<th scope="col">Quilt</th>
<th scope="col">NeoForge</th>
</tr>
</thead>
<tbody>
@foreach(var gameVersion in stat.Value)
{
<tr>
<td scope="row">@gameVersion.Key</td>
<td>@gameVersion.Value["Forge"].ToString("n0")</td>
<td>@gameVersion.Value["Fabric"].ToString("n0")</td>
<td>@gameVersion.Value["Quilt"].ToString("n0")</td>
<td>@gameVersion.Value["NeoForge"].ToString("n0")</td>
</tr>
}
</tbody>
</table>
</td>
</tr>
}
</tbody>
</table>
@foreach(var stat in Model.Stats)
{
<div id="minecraft-version-modloader-@stat.Key"></div>
}
39 changes: 37 additions & 2 deletions CFLookup/Pages/MinecraftModStatsOverTime.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MinecraftModStatsOverTimeModel : PageModel
{
private readonly MSSQLDB _db;

public Dictionary<DateTimeOffset, Dictionary<string, Dictionary<string, long>>> Stats { get; set; } = new Dictionary<DateTimeOffset, Dictionary<string, Dictionary<string, long>>>();
public Dictionary<string, Dictionary<DateTimeOffset, Dictionary<string, long>>> Stats { get; set; } = new Dictionary<string, Dictionary<DateTimeOffset, Dictionary<string, long>>>();

public MinecraftModStatsOverTimeModel(MSSQLDB db)
{
Expand All @@ -18,7 +18,42 @@ public MinecraftModStatsOverTimeModel(MSSQLDB db)

public async Task OnGetAsync()
{
Stats = await SharedMethods.GetMinecraftStatsOverTime(_db);
var stats = await SharedMethods.GetMinecraftStatsOverTime(_db);

var modloaderStats = new Dictionary<string, Dictionary<DateTimeOffset, Dictionary<string, long>>>();

foreach (var stat in stats)
{
var date = stat.Key;
foreach(var modloaderHolder in stat.Value)
{
var gameVersion = modloaderHolder.Key;

if(gameVersion.Contains("Snapshot")) continue;

foreach(var gameInfo in modloaderHolder.Value)
{
var modloader = gameInfo.Key;
var count = gameInfo.Value;

if(modloader.Contains("LiteLoader")) continue;

if (!modloaderStats.ContainsKey(modloader))
{
modloaderStats[modloader] = new Dictionary<DateTimeOffset, Dictionary<string, long>>();
}

if (!modloaderStats[modloader].ContainsKey(date))
{
modloaderStats[modloader][date] = new Dictionary<string, long>();
}

modloaderStats[modloader][date][gameVersion] = count;
}
}
}

Stats = modloaderStats;
}
}
}
3 changes: 3 additions & 0 deletions CFLookup/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<li class="nav-item">
<a class="nav-link" asp-page="/MinecraftModpackStats" asp-area="" title="CFLookup - Minecraft modpack stats">Minecraft modpack stats</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-page="/MinecraftModStatsOverTime" asp-area="" title="CFLookup - Minecraft mod stats over time">Minecraft stats over time</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-page="/FileProcessingInfo" asp-area="" title="CFLookup - File processing info">File processing info</a>
</li>
Expand Down

0 comments on commit 66d91f1

Please sign in to comment.