1
0
mirror of synced 2024-12-18 09:15:54 +01:00

Add random play_num_rank for testing

This commit is contained in:
Yuchen Ji 2022-06-10 00:48:03 +08:00
parent 9fad46fb08
commit 4730846674
4 changed files with 120 additions and 4 deletions

View File

@ -7,6 +7,7 @@ using EmbedIO.Routing;
using EmbedIO.WebApi;
using GCLocalServerRewrite.common;
using GCLocalServerRewrite.models;
using SQLite.Net2;
using Swan;
using Swan.Logging;
// ReSharper disable UnusedMember.Global
@ -15,6 +16,16 @@ namespace GCLocalServerRewrite.controllers;
public class RankController : WebApiController
{
private readonly SQLiteConnection cardSqLiteConnection;
private readonly SQLiteConnection musicSqLiteConnection;
public RankController()
{
cardSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.SETTINGS.CardDbName);
musicSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.SETTINGS.MusicDbName);
}
[Route(HttpVerbs.Get, "/ranking.php")]
public string Rank([QueryField("cmd_type")] int type)
{
@ -24,7 +35,7 @@ public class RankController : WebApiController
if (!Enum.IsDefined(typeof(RankType), type))
{
throw new ArgumentOutOfRangeException(nameof(type));
throw new ArgumentOutOfRangeException(nameof(type), type, "Rank type out of range");
}
var requestType = (RankType)type;
@ -41,7 +52,7 @@ public class RankController : WebApiController
case RankType.PlayNumRank:
$"Getting rank request, type is {requestType}".Info();
return ConstructResponse(RankTemp("play_num_rank"));
return ConstructResponse(PlayNumRank());
case RankType.EventRank:
$"Getting rank request, type is {requestType}".Info();
@ -97,6 +108,63 @@ public class RankController : WebApiController
return stringWriter.ToString();
}
private string PlayNumRank()
{
var rankStatus = new RankStatus
{
Rows = 30,
TableName = "play_num_rank",
Status = 1
};
var playNumRankContainer = new PlayNumRankContainer
{
PlayNumRankRecords = GetPlayNumRankRecords(),
RankStatus = rankStatus
};
var sb = new StringBuilder();
using (var writer = new ChoXmlWriter<PlayNumRankContainer>(sb))
{
writer.Configuration.UseXmlSerialization = true;
writer.Configuration.OmitXmlDeclaration = false;
writer.Configuration.IgnoreRootName = true;
writer.Write(playNumRankContainer);
}
return sb.ToString();
}
private List<PlayNumRankRecord> GetPlayNumRankRecords()
{
var records = new List<PlayNumRankRecord>();
var musics = musicSqLiteConnection.Table<Music>().ToList().OrderBy(arg => Guid.NewGuid()).Take(30).ToList();
for (var i = 0; i < musics.Count; i++)
{
var music = musics[i];
var index = i + 1;
var record = new PlayNumRankRecord
{
Id = index,
Rank = index,
Rank2 = index + 1,
PrevRank = musics.Count - i,
PrevRank2 = index + 1,
Artist = music.Artist,
Pcol1 = music.MusicId,
ScoreBi1 = index,
Title = music.Title
};
records.Add(record);
}
return records;
}
private enum RankType
{
GlobalRank = 4119,

View File

@ -0,0 +1,13 @@
using System.Xml.Serialization;
namespace GCLocalServerRewrite.models;
[XmlRoot("root")]
public class PlayNumRankContainer
{
[XmlArray("play_num_rank")]
public List<PlayNumRankRecord> PlayNumRankRecords { get; set; } = new();
[XmlElement("ranking_status")]
public RankStatus? RankStatus { get; set; }
}

View File

@ -0,0 +1,34 @@
using System.Xml.Serialization;
namespace GCLocalServerRewrite.models;
[XmlType("record")]
public class PlayNumRankRecord
{
[XmlAttribute(AttributeName = "id")]
public int Id { get; set; }
[XmlElement("rank")]
public int Rank { get; set; }
[XmlElement("rank2")]
public int Rank2 { get; set; }
[XmlElement("prev_rank")]
public int PrevRank { get; set; }
[XmlElement("prev_rank2")]
public int PrevRank2 { get; set; }
[XmlElement("pcol1")]
public int Pcol1 { get; set; }
[XmlElement("score_bi1")]
public int ScoreBi1 { get; set; }
[XmlElement("title")]
public string? Title { get; set; }
[XmlElement("artist")]
public string? Artist { get; set; }
}

View File

@ -2,16 +2,17 @@
namespace GCLocalServerRewrite.models;
[XmlType("ranking_status")]
public class RankStatus
{
[XmlElement("table_name")]
public string? TableName { get; set; }
[XmlElement("start_date")]
public string StartDate { get; set; } = "2017-05-30";
public string StartDate { get; set; } = "2021-05-30 08:00:00";
[XmlElement("end_date")]
public string EndDate { get; set; } = "2018-05-30";
public string EndDate { get; set; } = "2022-06-08 08:00:00";
[XmlElement("status")]
public int Status { get; set; }