Files
sbox-public/engine/Sandbox.Services/Api/Models/PackageReviewStats.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

39 lines
877 B
C#

using System.Text.Json.Serialization;
namespace Sandbox.Services;
public class PackageReviewStats
{
public struct Group
{
public int Rating { get; set; }
public long Total { get; set; }
}
public List<Group> Scores { get; set; } = new();
[JsonIgnore]
public Group Positive => Scores.FirstOrDefault( x => x.Rating == (int)ReviewScore.Positive );
[JsonIgnore]
public Group Negative => Scores.FirstOrDefault( x => x.Rating == (int)ReviewScore.Negative );
[JsonIgnore]
public Group Promise => Scores.FirstOrDefault( x => x.Rating == (int)ReviewScore.Promise );
[JsonIgnore]
public long Count => Scores.Sum( x => x.Total );
public float ToPercentage()
{
var count = Count;
if ( count == 0 ) return 0;
float score = (Positive.Total * 100) + (Promise.Total * 50);
score /= (Positive.Total + Promise.Total + Negative.Total);
return score;
}
}