Files
Ez2Lazer/osu.Game/LAsEzExtensions/Analysis/XxySrDebugJson.cs
LA 0b9f9f70d6 主要为代码质量更新
1. 匹配新版按钮控件的自动宽度写法

2. 统一Ez日志写入方向

3.移除历史修改:缓存启用mod列表,切换mod时保持通用mod开启状态

4.代码格式化、

5.修改文件名称表意,更直观
2026-03-12 19:29:55 +08:00

115 lines
4.0 KiB
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Buffers;
using System.Text;
using System.Text.Json;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.LAsEzExtensions.Configuration;
namespace osu.Game.LAsEzExtensions.Analysis
{
internal static class XxySrDebugJson
{
// Performance/debugging note:
// This logging can be very spammy during song select scrolling and may impact frame times.
// Keep disabled unless actively investigating xxy_SR correctness.
private const bool enabled = false;
public static string FormatAbnormalSr(BeatmapInfo beatmap, string eventType, double? star = null, double? xxySr = null)
{
var buffer = new ArrayBufferWriter<byte>(256);
using (var writer = new Utf8JsonWriter(buffer, new JsonWriterOptions { Indented = false }))
{
writer.WriteStartObject();
// Fixed property order for stable diffs.
writer.WriteString("event", eventType);
writer.WriteString("beatmap_id", beatmap.ID.ToString());
writer.WriteString("beatmap_hash", beatmap.Hash);
// In this codebase OnlineID is an int; treat non-positive values as "no online id".
if (beatmap.OnlineID > 0)
writer.WriteNumber("beatmap_online_id", beatmap.OnlineID);
else
writer.WriteNull("beatmap_online_id");
writer.WriteString("difficulty_name", beatmap.DifficultyName);
if (beatmap.BeatmapSet != null)
{
writer.WriteString("beatmapset_id", beatmap.BeatmapSet.ID.ToString());
if (beatmap.BeatmapSet.OnlineID > 0)
writer.WriteNumber("beatmapset_online_id", beatmap.BeatmapSet.OnlineID);
else
writer.WriteNull("beatmapset_online_id");
}
else
{
writer.WriteNull("beatmapset_id");
writer.WriteNull("beatmapset_online_id");
}
writer.WriteNumber("ruleset_online_id", 3);
writer.WriteStartArray("mods");
writer.WriteEndArray();
if (star.HasValue)
writer.WriteNumber("star", star.Value);
else
writer.WriteNull("star");
if (xxySr.HasValue)
writer.WriteNumber("xxy_sr", xxySr.Value);
else
writer.WriteNull("xxy_sr");
if (star.HasValue && xxySr.HasValue)
{
double absDiff = Math.Abs(star.Value - xxySr.Value);
writer.WriteNumber("abs_diff", absDiff);
}
writer.WriteEndObject();
writer.Flush();
}
return Encoding.UTF8.GetString(buffer.WrittenSpan);
}
public static void LogAbnormalSr(BeatmapInfo? beatmap, double? star, double? xxySr, Guid beatmapId, ref Guid? loggedAbnormalId)
{
if (!enabled)
return;
if (beatmap == null || star == null)
return;
if (loggedAbnormalId == beatmapId)
return;
loggedAbnormalId = beatmapId;
if (xxySr == null)
{
Logger.Log(
FormatAbnormalSr(beatmap, "xxySR_null", null, xxySr),
Ez2ConfigManager.LOGGER_NAME,
LogLevel.Error);
}
else if (Math.Abs(star.Value - xxySr.Value) > 3)
{
Logger.Log(
FormatAbnormalSr(beatmap, "xxySR_large_diff", star, xxySr),
Ez2ConfigManager.LOGGER_NAME,
LogLevel.Error);
}
}
}
}