Skip to content

Commit

Permalink
fix: Fetch all data, but only last post per day
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Dec 30, 2024
1 parent 7f42c5f commit 002c356
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CFLookup/Jobs/CacheMCOverTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static async Task RunAsync(PerformContext context)

var _rdb = _redis.GetDatabase(5);

var stats = await SharedMethods.GetMinecraftStatsOverTime(_db, CancellationToken.None, 24 * 60);
var stats = await SharedMethods.GetMinecraftStatsOverTime(_db, CancellationToken.None);

var renderers = new List<string>();
var ModLoaderStats = new Dictionary<string, List<Series>>();
Expand Down Expand Up @@ -110,7 +110,7 @@ public static async Task RunAsync(PerformContext context)
new XAxis
{
Type = "datetime",
MinRange = 3600000
MinRange = 24 * 3600000
}
},
Legend = new Legend
Expand Down
17 changes: 9 additions & 8 deletions CFLookup/SharedMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,18 @@ public static async Task<ConcurrentDictionary<string, long>> GetMinecraftModpack
return mcVersionModCount;
}

public static async Task<Dictionary<DateTimeOffset, Dictionary<string, Dictionary<string, long>>>> GetMinecraftStatsOverTime(MSSQLDB _db, CancellationToken cancellationToken, int? datapoints = 1000)
public static async Task<Dictionary<DateTimeOffset, Dictionary<string, Dictionary<string, long>>>> GetMinecraftStatsOverTime(MSSQLDB _db, CancellationToken cancellationToken)
{
var stats = await _db.ExecuteReader(
$@"
SELECT timestamp_utc, stats, RowNumber
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY statId DESC) AS RowNumber, *
FROM MinecraftModStatsOverTime
) AS MCStats
{(datapoints.HasValue && datapoints > 0 ? $"WHERE RowNumber <= {datapoints}" : "")}
ORDER BY RowNumber DESC
WITH DailyLatest AS (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY CAST(timestamp_utc AS DATE) ORDER BY timestamp_utc DESC) AS RowNumber
FROM MinecraftModStatsOverTime WITH(NOLOCK)
)
SELECT *
FROM DailyLatest
WHERE RowNumber = 1
");
var Stats = new Dictionary<DateTimeOffset, Dictionary<string, Dictionary<string, long>>>();
while (stats.Read())
Expand Down

0 comments on commit 002c356

Please sign in to comment.