Add random play_num_rank for testing
This commit is contained in:
parent
9fad46fb08
commit
4730846674
@ -7,6 +7,7 @@ using EmbedIO.Routing;
|
|||||||
using EmbedIO.WebApi;
|
using EmbedIO.WebApi;
|
||||||
using GCLocalServerRewrite.common;
|
using GCLocalServerRewrite.common;
|
||||||
using GCLocalServerRewrite.models;
|
using GCLocalServerRewrite.models;
|
||||||
|
using SQLite.Net2;
|
||||||
using Swan;
|
using Swan;
|
||||||
using Swan.Logging;
|
using Swan.Logging;
|
||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
@ -15,6 +16,16 @@ namespace GCLocalServerRewrite.controllers;
|
|||||||
|
|
||||||
public class RankController : WebApiController
|
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")]
|
[Route(HttpVerbs.Get, "/ranking.php")]
|
||||||
public string Rank([QueryField("cmd_type")] int type)
|
public string Rank([QueryField("cmd_type")] int type)
|
||||||
{
|
{
|
||||||
@ -24,7 +35,7 @@ public class RankController : WebApiController
|
|||||||
|
|
||||||
if (!Enum.IsDefined(typeof(RankType), type))
|
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;
|
var requestType = (RankType)type;
|
||||||
@ -41,7 +52,7 @@ public class RankController : WebApiController
|
|||||||
case RankType.PlayNumRank:
|
case RankType.PlayNumRank:
|
||||||
$"Getting rank request, type is {requestType}".Info();
|
$"Getting rank request, type is {requestType}".Info();
|
||||||
|
|
||||||
return ConstructResponse(RankTemp("play_num_rank"));
|
return ConstructResponse(PlayNumRank());
|
||||||
case RankType.EventRank:
|
case RankType.EventRank:
|
||||||
$"Getting rank request, type is {requestType}".Info();
|
$"Getting rank request, type is {requestType}".Info();
|
||||||
|
|
||||||
@ -97,6 +108,63 @@ public class RankController : WebApiController
|
|||||||
return stringWriter.ToString();
|
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
|
private enum RankType
|
||||||
{
|
{
|
||||||
GlobalRank = 4119,
|
GlobalRank = 4119,
|
||||||
|
13
GC-local-server-rewrite/models/PlayNumRankContainer.cs
Normal file
13
GC-local-server-rewrite/models/PlayNumRankContainer.cs
Normal 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; }
|
||||||
|
}
|
34
GC-local-server-rewrite/models/PlayNumRankRecord.cs
Normal file
34
GC-local-server-rewrite/models/PlayNumRankRecord.cs
Normal 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; }
|
||||||
|
}
|
@ -2,16 +2,17 @@
|
|||||||
|
|
||||||
namespace GCLocalServerRewrite.models;
|
namespace GCLocalServerRewrite.models;
|
||||||
|
|
||||||
|
[XmlType("ranking_status")]
|
||||||
public class RankStatus
|
public class RankStatus
|
||||||
{
|
{
|
||||||
[XmlElement("table_name")]
|
[XmlElement("table_name")]
|
||||||
public string? TableName { get; set; }
|
public string? TableName { get; set; }
|
||||||
|
|
||||||
[XmlElement("start_date")]
|
[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")]
|
[XmlElement("end_date")]
|
||||||
public string EndDate { get; set; } = "2018-05-30";
|
public string EndDate { get; set; } = "2022-06-08 08:00:00";
|
||||||
|
|
||||||
[XmlElement("status")]
|
[XmlElement("status")]
|
||||||
public int Status { get; set; }
|
public int Status { get; set; }
|
||||||
|
Loading…
Reference in New Issue
Block a user