Ranking reforge. SplitRanking is not implemented yet !!!

This commit is contained in:
2025-06-30 19:02:19 +02:00
parent 81bf37639b
commit 11e695f379
13 changed files with 218 additions and 104 deletions

View File

@ -6,37 +6,6 @@
#include "Types/Objects/DTFluxContestStorage.h"
// const FDateTime UDTFluxModelAsset::GetMassStart(const int& ContestId, const int& StageId)
// {
// }
// void UDTFluxModelAsset::InsertOrUpdateRaceData(const TSharedPtr<FJsonObject>& Response)
// {
//
// }
//
// void UDTFluxModelAsset::InsertOrUpdateContestRanking(const TSharedPtr<FJsonObject>& Response)
// {
// }
//
// void UDTFluxModelAsset::InsertOrUpdateStageRanking(const TSharedPtr<FJsonObject>& Response)
// {
// }
//
// void UDTFluxModelAsset::InsertOrUpdateSplitRanking(const TSharedPtr<FJsonObject>& Response)
// {
// }
//
// void UDTFluxModelAsset::InsertOrUpdateTeamList(const TSharedPtr<FJsonObject>& Response)
// {
// }
//
// void UDTFluxModelAsset::SplitSensorTriggered(const TSharedPtr<FJsonObject>& Response)
// {
// }
UDTFluxModelAsset::UDTFluxModelAsset(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
}
@ -93,3 +62,47 @@ bool UDTFluxModelAsset::PersonExists(const FDTFluxPerson& InPerson) const
return Person == InPerson;
});
}
FString UDTFluxModelAsset::GetContestNameForId(const int InContestID)
{
FDTFluxContest Contest;
if(!GetContestById(InContestID, Contest))
{
UE_LOG(logDTFluxCore, Warning, TEXT("GetContestNameForId(%i) [unable to find a contest] result will be empty !!!"),
InContestID);
}
return Contest.Name;
}
void UDTFluxModelAsset::AddContestRanking(const FDTFluxContestRankings& NewContestRankings)
{
ContestRankings.Add(NewContestRankings.ContestId, NewContestRankings);
}
bool UDTFluxModelAsset::UpdateStageRanking(const FDTFluxStageRankings& InStageRankings)
{
const int ContestId = InStageRankings.ContestId;
const int StageId = InStageRankings.StageId;
int Index = 0;
int StageRankingArraySize = StageRankings.Num()-1;
for(auto Ranking : StageRankings)
{
if(Ranking.ContestId == ContestId && Ranking.StageId == StageId)
{
Index++;
break;
}
Index++;
}
if(Index != StageRankingArraySize )
{
StageRankings[Index] = InStageRankings;
return true;
}
return false;
}
bool UDTFluxModelAsset::UpdateSplitRanking(const FDTFluxStageRankings& InStageRankings)
{
return true;
}

View File

@ -99,17 +99,17 @@ void UDTFluxContestStorage::AddSplit(const int InContest, const FDTFluxSplit& In
#pragma region SplitRankingRegion
void UDTFluxContestStorage::AddSplitRanking(const int InContest, const FDTFluxSplitRanking& InSplitRanking)
void UDTFluxContestStorage::AddSplitRanking(const int InContest, const FDTFluxStageRanking& InSplitRanking)
{
}
void UDTFluxContestStorage::GetSplitRankingByParticipant(const FDTFluxParticipant& InParticipant, const int InContestId,
const int InStageId, const FDTFluxSplitRanking& OutSplitRankingForBib)
const int InStageId, const FDTFluxStageRanking& OutSplitRankingForBib)
{
}
void UDTFluxContestStorage::GetSplitRankingByBib(const int InBib, const int InContestId, const int InStageId,
const FDTFluxSplitRanking& OutSplitRankingForBib)
const FDTFluxStageRanking& OutSplitRankingForBib)
{
}

View File

@ -20,10 +20,10 @@ void FDTFluxStageRanking::Dump() const
void FDTFluxSplitRanking::Dump() const
{
UE_LOG(logDTFluxCore, Log, TEXT("SplitGapItem"))
// Participant.Dump();
UE_LOG(logDTFluxCore, Log, TEXT("Bib %02d Rank %02d Gap %s Time %s"), Bib, Rank, *Gap, *Time);
}
// void FDTFluxSplitRanking::Dump() const
// {
// UE_LOG(logDTFluxCore, Log, TEXT("SplitGapItem"))
// // Participant.Dump();
// UE_LOG(logDTFluxCore, Log, TEXT("Bib %02d Rank %02d Gap %s Time %s"), Bib, Rank, *Gap, *Time);
// }

View File

@ -34,10 +34,13 @@ public:
TMap<FString /* ContestName */, FDTFluxContest> Contests;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
TArray<FDTFluxContestRanking> ContestRankings;
TMap<int /*ContestId*/, FDTFluxContestRankings> ContestRankings;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
TMap<FString /*ContestName*/ ,FDTFluxStageRanking> StageRankings;
TArray<FDTFluxStageRankings> StageRankings;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
TArray<FDTFluxStageRankings> SplitRankings;
UFUNCTION(BlueprintCallable, CallInEditor, Category="DTFlux|ModelAsset")
void AddContest(const FDTFluxContest &Contest);
@ -51,6 +54,18 @@ public:
UFUNCTION(BlueprintCallable, CallInEditor, Category="DTFlux|Participant")
void AddParticipant(const FDTFluxParticipant& InParticipant, const int ContestId);
UFUNCTION(BlueprintCallable, CallInEditor, Category="DTFlux|Person")
UFUNCTION(BlueprintCallable, CallInEditor, Category="DTFlux|Person|Utils")
bool PersonExists(const FDTFluxPerson& InPerson) const;
UFUNCTION(BlueprintCallable, Category="DTFlux|Contest|Utils")
FString GetContestNameForId(const int InContestID);
UFUNCTION(BlueprintCallable, Category="DTFlux|Contest|Utils")
bool UpdateStageRanking(const FDTFluxStageRankings& InStageRankings);
UFUNCTION(BlueprintCallable, Category="DTFlux|Contest|Utils")
bool UpdateSplitRanking(const FDTFluxStageRankings& InStageRankings);
UFUNCTION()
void AddContestRanking(const FDTFluxContestRankings& NewContestRankings);
};

View File

@ -88,13 +88,13 @@ public:
void AddSplit(const int InContest, const FDTFluxSplit& InSplit);
UFUNCTION(BlueprintCallable, Category="DTFlux|Contest")
void AddSplitRanking(const int InContest, const FDTFluxSplitRanking& InSplitRanking);
void AddSplitRanking(const int InContest, const FDTFluxStageRanking& InSplitRanking);
UFUNCTION(BlueprintCallable, Category="DTFlux|Contest")
void GetSplitRankingByParticipant(const FDTFluxParticipant& InParticipant, const int InContestId, const int InStageId, const FDTFluxSplitRanking& OutSplitRankingForBib);
void GetSplitRankingByParticipant(const FDTFluxParticipant& InParticipant, const int InContestId, const int InStageId, const FDTFluxStageRanking& OutSplitRankingForBib);
UFUNCTION(BlueprintCallable, Category="DTFlux|Contest")
void GetSplitRankingByBib(const int InBib, const int InContestId, const int InStageId, const FDTFluxSplitRanking& OutSplitRankingForBib);
void GetSplitRankingByBib(const int InBib, const int InContestId, const int InStageId, const FDTFluxStageRanking& OutSplitRankingForBib);
#pragma endregion
#pragma region ParticipantSection

View File

@ -23,7 +23,7 @@ public:
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
int Bib = -1;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
FDTFluxSplitRanking SplitRanking;
FDTFluxStageRanking SplitRanking;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
FDTFluxStageRanking StageRanking;
};

View File

@ -23,7 +23,7 @@ public:
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model", EditAnywhere)
FString Name;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|model", EditAnywhere)
TArray<FDTFluxSplitRanking> SplitRankings;
TArray<FDTFluxStageRanking> SplitRankings;
// void Dump() const;
// // void InsertOrReplace(const FDTFluxStageRankingResponseItem& SplitRankingItemResp);
// void SortByRank();

View File

@ -16,25 +16,43 @@ struct DTFLUXCORE_API FDTFluxContestRanking
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
int Bib;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
int Rank;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
FString Gap;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
FString Time;
UPROPERTY();
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere);
FString SpeedSwimAverage;
UPROPERTY();
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere);
FString SpeedRunningAverage;
UPROPERTY();
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere);
FString SpeedTotalAverage;
void Dump () const;
};
USTRUCT(BlueprintType)
struct FDTFluxContestRankings
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite,Category="DTFlux|Model|Ranking", VisibleAnywhere)
TArray<FDTFluxContestRanking> Rankings;
UPROPERTY(BlueprintReadWrite,Category="DTFlux|Model|Ranking", VisibleAnywhere)
int ContestId;
//TODO check if necessary ???
UPROPERTY(BlueprintReadWrite,Category="DTFlux|Model|Ranking", VisibleAnywhere)
FString ContestName;
void SetName(const FString Name)
{
ContestName = Name;
}
};
/**
* @struct FDTFluxStageRanking
* Representing a stage ranking for a participant
@ -44,59 +62,48 @@ struct DTFLUXCORE_API FDTFluxStageRanking
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
int Bib;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
int Rank;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
FString Gap;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
FString Time;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
FString TimeSwim;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
FString TimeTransition;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
FString TimeRun;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
FString TimeStart;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
FDateTime StartTime;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
float SpeedRunning;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
float SpeedTotal;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
UPROPERTY(BlueprintReadOnly, Category="DTFlux|Model", VisibleAnywhere)
float SpeedSwim;
void Dump() const;
};
/**
* @struct FDTFluxSplitRanking
* Representing a ranking of a participant in a split
*/
USTRUCT(BlueprintType, Category="DTFlux|Model")
struct DTFLUXCORE_API FDTFluxSplitRanking
USTRUCT(BlueprintType)
struct FDTFluxStageRankings
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
int Bib;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
int ContestId = 0;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
int StageId = 0;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
int SplitId = 0;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
FString Gap;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
FString Time;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
int Rank = 0;
UPROPERTY(BlueprintReadWrite, Category="DTFlux|Model")
bool Display = false;
void Dump() const;
UPROPERTY(BlueprintReadWrite,Category="DTFlux|Model|Ranking", VisibleAnywhere)
TArray<FDTFluxStageRanking> Rankings;
UPROPERTY(BlueprintReadWrite,Category="DTFlux|Model|Ranking", VisibleAnywhere)
int ContestId;
UPROPERTY(BlueprintReadWrite,Category="DTFlux|Model|Ranking", VisibleAnywhere)
int StageId;
UPROPERTY(BlueprintReadWrite,Category="DTFlux|Model|Ranking", VisibleAnywhere)
int SplitId;
};

View File

@ -46,10 +46,11 @@ void UDTFluxCoreSubsystem::RegisterDelegates()
{
NetworkSubsystem->OnReceivedRaceData().AddDynamic(this, &UDTFluxCoreSubsystem::ParseRaceData);
NetworkSubsystem->OnReceivedTeamList().AddDynamic(this, &UDTFluxCoreSubsystem::ParseTeamList);
NetworkSubsystem->OnReceivedContestRanking().AddDynamic(this, &UDTFluxCoreSubsystem::ParseContestRanking);
NetworkSubsystem->OnReceivedStageRanking().BindUFunction(this, "ParseStageOrSplitRanking");
}
}
void UDTFluxCoreSubsystem::ParseRaceData(const FDTFluxRaceData& RaceDataDefinition)
{
@ -99,6 +100,31 @@ void UDTFluxCoreSubsystem::ParseTeamList(const FDTFluxTeamListDefinition& TeamLi
}
}
void UDTFluxCoreSubsystem::ParseContestRanking(const FDTFluxContestRankings& ContestRankings)
{
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received ContestRankings with %i Items"), ContestRankings.Rankings.Num());
FDTFluxContestRankings NewContestRankings = ContestRankings;
NewContestRankings.SetName( DataStorage->GetContestNameForId(ContestRankings.ContestId));
DataStorage->AddContestRanking(NewContestRankings);
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("ContestRankings added for Contest %s"), *NewContestRankings.ContestName);
}
void UDTFluxCoreSubsystem::ParseStageOrSplitRanking(const FDTFluxStageRankings& StageOrSplitRankings)
{
if(StageOrSplitRankings.SplitId == -1)
{
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received StageRankings with %i Items"), StageOrSplitRankings.Rankings.Num());
if(!DataStorage->UpdateStageRanking(StageOrSplitRankings))
{
DataStorage->StageRankings.Add(StageOrSplitRankings);
}
}
else
{
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received SplitRankings with %i Items"), StageOrSplitRankings.Rankings.Num());
}
}
void UDTFluxCoreSubsystem::OnDataReceived()
{
}
@ -111,7 +137,6 @@ void UDTFluxCoreSubsystem::SendRequest(const FString& Message)
}
}
void UDTFluxCoreSubsystem::SendTeamListRequest()
{
if (NetworkSubsystem)
@ -166,3 +191,5 @@ void UDTFluxCoreSubsystem::RefreshStorage()
{
// TODO Implement this
}

View File

@ -31,7 +31,7 @@ public:
// TSharedPtr<FDTFluxParser> Parser;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSplitRankings, FDateTime, ReceivedAt, TArray<FDTFluxSplitRanking>, SplitRankings);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSplitRankings, FDateTime, ReceivedAt, TArray<FDTFluxStageRanking>, SplitRankings);
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
FOnSplitRankings OnSplitRankings;
@ -97,6 +97,10 @@ private:
UFUNCTION()
void ParseTeamList(const FDTFluxTeamListDefinition& TeamListDefinition);
UFUNCTION()
void ParseContestRanking(const FDTFluxContestRankings& ContestRankings);
UFUNCTION()
void ParseStageOrSplitRanking(const FDTFluxStageRankings& StageOrSplitRankings);
UFUNCTION()
void OnDataReceived();
UFUNCTION()
void SendRequest(const FString& Message);

View File

@ -11,6 +11,7 @@
#include "Struct/DTFluxServerResponseStruct.h"
#include "Struct/DTFluxRequestStructs.h"
#include "Struct/DTFluxRaceDataServerResponse.h"
#include "Struct/DTFluxRankingServerResponse.h"
#include "Struct/DTFluxTeamListServerResponse.h"
#include "Types/Struct/DTFluxRaceDataStructs.h"
@ -192,6 +193,7 @@ void UFDTFluxNetworkSubsystem::OnWebSocketClosedEvent_Subsystem(int32 StatusCode
*WsClient->GetAddress(), *Reason, StatusCode, bWasClean ? TEXT("True") : TEXT("False"));
}
//TODO reforge API to keep track of Requests
void UFDTFluxNetworkSubsystem::OnWebSocketMessageEvent_Subsystem(const FString& MessageString)
{
UE_LOG(logDTFluxNetwork, Warning, TEXT("Ws %s :\nMessage Received : %s"), *WsClient->GetAddress(), *MessageString);
@ -265,8 +267,41 @@ void UFDTFluxNetworkSubsystem::OnWebSocketMessageEvent_Subsystem(const FString&
UE_LOG(logDTFluxNetwork, Warning, TEXT("Ws Team-List Data Sent"));
return OnTeamListReceived.Broadcast(TeamListDefinition);
}
if(Response.Type.Contains("contest-ranking"))
{
UE_LOG(logDTFluxNetwork, Warning, TEXT("Ws Contest-Ranking Data"));
FDTFluxContestRankingResponse ContestRankingResponse;
FJsonObjectConverter::JsonObjectStringToUStruct<FDTFluxContestRankingResponse>(Response.RawMessage, &ContestRankingResponse);
FDTFluxContestRankings ContestRankings;
ContestRankings.ContestId = ContestRankingResponse.ContestID;
for(auto& RankingItem : ContestRankingResponse.Datas)
{
FDTFluxContestRanking Temp = RankingItem;
ContestRankings.Rankings.Add(Temp);
}
UE_LOG(logDTFluxNetwork, Warning, TEXT("Ws ContestRanking Data Sent for Contest %i"), ContestRankings.ContestId);
return OnContestRankingReceived.Broadcast(ContestRankings);
}
if(Response.Type.Contains("stage-ranking") )
{
// StageRanking
UE_LOG(logDTFluxNetwork, Warning, TEXT("Ws Stage-Ranking Data"));
FDTFluxStageRankingResponse StageRankingResponse;
FJsonObjectConverter::JsonObjectStringToUStruct<FDTFluxStageRankingResponse>(Response.RawMessage, &StageRankingResponse);
FDTFluxStageRankings StageRankings;
StageRankings.ContestId = StageRankingResponse.ContestId;
StageRankings.StageId = StageRankingResponse.StageId;
StageRankings.SplitId = StageRankingResponse.SplitId;
for(FDTFluxStageRanking& InRanking : StageRankingResponse.Datas)
{
FDTFluxStageRanking Temp = InRanking;
StageRankings.Rankings.Add(InRanking);
}
UE_LOG(logDTFluxNetwork, Warning, TEXT("Ws StageRanking Data Sent for Contest %i and Stage %i\n[Result] : %s"),
StageRankings.ContestId, StageRankings.StageId, OnStageRankingReceived.ExecuteIfBound(StageRankings) ? TEXT("Executed") : TEXT("Not Bound !!!"));
return;
}
}
UE_LOG(logDTFluxNetwork, Error, TEXT("Ws %s :\nMessage Cannot be Parsed\n%s"), *WsClient->GetAddress(), *MessageString);
}
UE_LOG(logDTFluxNetwork, Error, TEXT("Ws %s :\nMessage Received : %s Cannot be Parsed"), *WsClient->GetAddress(), *MessageString);

View File

@ -43,19 +43,15 @@ public:
};
USTRUCT(BlueprintType)
struct DTFLUXNETWORK_API FDTFluxStageRankingResponse
struct DTFLUXNETWORK_API FDTFluxStageRankingResponse : public FDTFluxStageRankings
{
GENERATED_BODY()
public:
UPROPERTY()
FString Type = "stage-ranking";
UPROPERTY()
int ContestID;
UPROPERTY()
int StageID;
UPROPERTY()
int SplitID = -1;
UPROPERTY()
// ReSharper disable once IdentifierTypo
TArray<FDTFluxStageRankingResponseItem> Datas;

View File

@ -7,6 +7,7 @@
#include "Subsystems/EngineSubsystem.h"
#include "Types/DTFluxNetworkSettingsTypes.h"
#include "Types/Enum/DTfluxCoreEnum.h"
#include "Types/Struct/DTFluxRankingStructs.h"
#include "DTFluxNetworkSubsystem.generated.h"
@ -46,6 +47,22 @@ public:
return OnTeamListReceived;
};
DECLARE_DELEGATE_OneParam(FOnStageRankingReceived, const FDTFluxStageRankings&);
FOnStageRankingReceived OnStageRankingReceived;
FOnStageRankingReceived& OnReceivedStageRanking()
{
return OnStageRankingReceived;
}
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnContestRankingReceived, const FDTFluxContestRankings&, ContestRankings);
FOnContestRankingReceived OnContestRankingReceived;
FOnContestRankingReceived& OnReceivedContestRanking()
{
return OnContestRankingReceived;
};
UFUNCTION(BlueprintCallable, Category="DTFlux|Network")
void Connect();
//