Adding Status and Last server response handled but not tested

This commit is contained in:
2025-07-03 17:28:51 +02:00
parent 2855fa1e98
commit fa5493adcf
43 changed files with 2035 additions and 379 deletions

View File

@ -36,18 +36,20 @@ void UDTFluxModelAsset::AddPerson(const FDTFluxPerson& InPerson)
void UDTFluxModelAsset::AddParticipant(const FDTFluxParticipant& InParticipant, const int ContestId)
{
UE_LOG(logDTFluxCore, Error, TEXT("%i Person in Participant %i"), InParticipant.GetTeammateNum(), InParticipant.Bib);
FDTFluxContest TargetContest;
if(GetContestById(ContestId, TargetContest))
{
if(!PersonExists(InParticipant.Person1))
TArray<FDTFluxPerson> Teammate = InParticipant.Teammate;
for(auto& Person : InParticipant.Teammate)
{
AddPerson(InParticipant.Person1);
}
if(InParticipant.Person2 != 0)
{
if(!PersonExists(InParticipant.Person2))
UE_LOG(logDTFluxCore, Error, TEXT("AddParticipant() DTFlux Person %s %s %s"),
*Person.FirstName, *Person.LastName, *Person.Gender);
if(!PersonExists(Person))
{
AddPerson(InParticipant.Person2);
UE_LOG(logDTFluxCore, Error, TEXT("AddParticipant() DTFlux Person %s %s %s doesnot exists, adding..."),
*Person.FirstName, *Person.LastName, *Person.Gender);
AddPerson(Person);
}
}
Participants.Add(InParticipant.Bib, InParticipant);
@ -79,30 +81,24 @@ void UDTFluxModelAsset::AddContestRanking(const FDTFluxContestRankings& NewConte
ContestRankings.Add(NewContestRankings.ContestId, NewContestRankings);
}
bool UDTFluxModelAsset::UpdateStageRanking(const FDTFluxStageRankings& InStageRankings)
void UDTFluxModelAsset::UpdateOrCreateStageRanking(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;
FDTFluxStageKey StageKey = InStageRankings.GetCompositeKey();
StageRankings.FindOrAdd(StageKey) = InStageRankings;
}
bool UDTFluxModelAsset::UpdateSplitRanking(const FDTFluxStageRankings& InStageRankings)
void UDTFluxModelAsset::AddStageRanking(const FDTFluxStageRankings& InStageRankings)
{
return true;
StageRankings.Add(InStageRankings.GetCompositeKey(), InStageRankings);
}
void UDTFluxModelAsset::AddSplitRanking(const FDTFluxSplitRankings& InSplitRanking)
{
SplitRankings.Add(InSplitRanking.GetCompositeKey(), InSplitRanking);
}
void UDTFluxModelAsset::UpdateOrCreateSplitRanking(const FDTFluxSplitRankings& InSplitRankings)
{
FDTFluxSplitKey SplitKey = InSplitRankings.GetCompositeKey();
SplitRankings.FindOrAdd(SplitKey) = InSplitRankings;
}

View File

@ -0,0 +1,43 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Types/Objects/DTFluxPursuitManager.h"
void UDTFluxPursuitManager::InitForStage(const FDTFluxStageRankings& StageRankings)
{
}
TArray<FDTFluxPursuit> UDTFluxPursuitManager::GetNextPursuits(int MaxPursuit)
{
//TODO : Implement me !!!
return PursuitParticipants;
}
TArray<FDTFluxPursuit> UDTFluxPursuitManager::GetPursuits(int FromIndex, int MaxPursuit)
{
//TODO : Implement me !!!
return PursuitParticipants;
}
FDateTime UDTFluxPursuitManager::GetMassStart()
{
//TODO : Implement me !!!
return MassStart;
}
FText UDTFluxPursuitManager::GetFormattedName(FDTFluxPursuit& InPursuit, const int MaxChar,
const FString OverflowChar)
{
return InPursuit.GetFormattedName(MaxChar, OverflowChar);
}
FText UDTFluxPursuitManager::DisplayPursuit(FDTFluxPursuit& InPursuit, const int MaxWidth,
const FString NameOverflowChar)
{
return InPursuit.DisplayPursuit(MaxWidth, NameOverflowChar);
}
bool UDTFluxPursuitManager::IsUnique(const FDTFluxPursuit& InPursuit)
{
return InPursuit.IsUnique();
}

View File

@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Types/Objects/UDTFluxParticipantFactory.h"
bool UDTFluxParticipantFactory::CreateParticipantFomJson(const FString& JsonString, FDTFluxParticipant& OutParticipant)
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(JsonString);
if (FJsonSerializer::Deserialize(Reader, JsonObject) && JsonObject.IsValid())
{
return UDTFluxParticipantFactory::CreateFromJsonCpp(JsonObject, OutParticipant);
}
else
{
OutParticipant = FDTFluxParticipant();
return false;
}
}
bool UDTFluxParticipantFactory::CreateFromJsonCpp(const TSharedPtr<FJsonObject> JsonObject, FDTFluxParticipant& OutParticipant)
{
OutParticipant = FDTFluxParticipant::CreateFromJson(JsonObject);
return OutParticipant == 0;
}

View File

@ -0,0 +1,4 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Types/Struct/DTFluxCompositeKey.h"

View File

@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Types/Struct/DTFluxPursuitStructs.h"
FDTFluxPursuit::FDTFluxPursuit()
{
}
FDTFluxPursuit::~FDTFluxPursuit()
{
}
FText FDTFluxPursuit::GetFormattedName(const int MaxChar, const FString OverflowChar)
{
//TODO: Implement Me !!!
return Participants[0].GetConcatFormattedName(MaxChar, OverflowChar);
}
FText FDTFluxPursuit::DisplayPursuit(const int MaxWidth, const FString NameOverflowChar)
{
//TODO: Implement Me !!!
return Participants[0].GetConcatFormattedName(MaxWidth, NameOverflowChar);
}
bool FDTFluxPursuit::IsUnique() const
{
return Participants.Num() == 1;
}

View File

@ -10,13 +10,13 @@ void FDTFluxContestRanking::Dump() const
Rank, Bib, *Gap, *Time );
};
void FDTFluxStageRanking::Dump() const
{
UE_LOG(logDTFluxCore, Log, TEXT("RANKING : %02d. Participant bib %d %s %s %s %s %s"),
Rank, Bib, *Gap, *TimeSwim,
*TimeTransition, *TimeRun, *StartTime.ToString());
}
// void FDTFluxStageRanking::Dump() const
// {
// UE_LOG(logDTFluxCore, Log, TEXT("RANKING : %02d. Participant bib %d %s %s %s %s %s"),
// Rank, Bib, *Gap, *TimeSwim,
// *TimeTransition, *TimeRun, *StartTime.ToString());
// }
//

View File

@ -0,0 +1,4 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Types/Struct/DTFluxSplitSensor.h"

View File

@ -4,104 +4,150 @@
#include "Types/Struct/DTFluxTeamListStruct.h"
bool FDTFluxParticipant::IsTeam() const
void FDTFluxParticipant::AddTeammate(const FDTFluxPerson& Person)
{
return Person2.FirstName.IsEmpty() && Person2.LastName.IsEmpty();
Teammate.Add(Person);
}
void FDTFluxParticipant::Dump() const
void FDTFluxParticipant::AddTeammate(const FString LastName, const FString FirstName, const FString Gender)
{
FString EliteStr = "NO";
if(Elite)
}
FText FDTFluxParticipant::GetFormattedName(const int MaxChar, const FString OverflowChars)
{
// Vérifie les cas limites
if (MaxChar <= 0)
{
EliteStr = "YES";
return FText::GetEmpty();
}
UE_LOG(logDTFluxCore, Log, TEXT("PARTICIPANT with bib: %03d"), Bib);
UE_LOG(logDTFluxCore, Log, TEXT("Fullname : %s %s"), *Person1.FirstName, *Person1.LastName);
FString FirstName;
FString LastName;
if(IsTeam())
{
UE_LOG(logDTFluxCore, Log, TEXT("Teamate : %s %s"), *Person2.FirstName, *Person2.LastName);
UE_LOG(logDTFluxCore, Log, TEXT("Team name : %s"), *Team);
LastName = Team;
}
UE_LOG(logDTFluxCore, Log, TEXT("Club : %s, Category : %s, IsElite : %s, Status : %s"),
*Club, *Category, *EliteStr, *UEnum::GetValueAsString(Status));
// Récupère la première lettre du prénom en majuscule
FString Initial;
if (!FirstName.IsEmpty())
{
Initial = FirstName.Left(1).ToUpper() + " ";
}
// Nom complet en majuscules
FString FormattedLastName = LastName.ToUpper();
// Construction du nom final
FString FullName = Initial + FormattedLastName;
// Tronque si nécessaire
if (FullName.Len() > MaxChar)
{
// On essaie de garder autant de caractères que possible
const int32 AvailableLength = MaxChar - Initial.Len();
if (AvailableLength <= 0)
{
// Pas assez de place pour le nom → juste l'initiale ?
return FText::FromString(Initial);
}
// Coupe le nom pour quil rentre dans la limite
const int32 TruncateLength = FMath::Min(AvailableLength, FormattedLastName.Len());
FullName = Initial + FormattedLastName.Left(TruncateLength);
// Si on a coupé trop court, on ajoute le suffixe
if (FormattedLastName.Len() > TruncateLength)
{
// On vérifie qu'il reste de la place pour le suffixe
const int32 CurrentLength = FullName.Len();
const int32 OverflowLength = OverflowChars.Len();
if (CurrentLength + OverflowLength <= MaxChar)
{
FullName += OverflowChars;
}
else
{
// Il faut tronquer davantage pour faire de la place au suffixe
const int32 RemainingSpace = MaxChar - CurrentLength;
if (RemainingSpace > 0)
{
FullName = FullName.Left(MaxChar - OverflowLength) + OverflowChars;
}
else
{
FullName = FullName.Left(MaxChar);
}
}
}
}
return FText::FromString(FullName);
}
FString FDTFluxParticipant::GetParticipantFormatedName(bool Truncate, int MaxSize) const
FText FDTFluxParticipant::GetConcatFormattedName(const int MaxChar, const FString OverflowChar)
{
FString ParticipantName;
if(Truncate)
{
if(IsTeam())
{
//Concatenate the team name;
if(Team.Len() > MaxSize - 3)
{
return Team.Left(MaxSize - 3).Append(TEXT("..."));
}
return Team;
}
if(Person1.FirstName.Contains("-") )
{
FString Formated = "";
//Compound Firstname
TArray<FString> Out;
Person1.FirstName.ParseIntoArray(Out,TEXT("-"),true);
for(const auto& Str : Out)
{
Formated.Append(Str.Left(1).ToUpper()).Append(".");
}
// TODO : Camel Case handling for LastName
Formated.Append(" ").Append(*Person1.LastName);
UE_LOG(logDTFluxCore, Log, TEXT("Firstname is with space compound. Formated Name %s length %02d MAX Size : %02d"),
*Formated, Formated.Len(), MaxSize);
if(Formated.Len() >= MaxSize)
{
UE_LOG(logDTFluxCore, Log, TEXT("Reducing %s Formated"), *Formated);
FString BibText = FString::FromInt(Bib) + " ";
FText FormattedName = GetFormattedName(MaxChar - BibText.Len(), OverflowChar );
return FText::FromString(BibText + FormattedName.ToString());
}
return Formated.Left(MaxSize - 3).Append("...");
}
return Formated;
}
if(Person1.FirstName.Contains(" "))
{
FString Formated = "";
//Compound Firstname
TArray<FString> Out;
Person1.FirstName.ParseIntoArray(Out,TEXT(" "),true);
for(const auto& Str : Out)
{
Formated.Append(Str.Left(1).ToUpper()).Append(".");
}
// TODO : Camel Case handling for LastName
Formated.Append(" ").Append(*Person1.LastName);
UE_LOG(logDTFluxCore, Log, TEXT("Firstname is with space compound. Formated Name %s length %02d MAX Size : %02d"),
*Formated, Formated.Len(), MaxSize);
if(Formated.Len() >= MaxSize)
{
UE_LOG(logDTFluxCore, Log, TEXT("Reducing %s Formated"), *Formated);
return Formated.Left(MaxSize - 3).Append("...");
}
return Formated;
}
FString Formated = Person1.FirstName.Left(1).Append(". ");
Formated.Append(Person1.LastName);
UE_LOG(logDTFluxCore, Log, TEXT("Firstname is not compound. Formated Name %s length %02d MAX Size : %02d"),
*Formated, Formated.Len(), MaxSize);
if(Formated.Len() >= MaxSize)
{
UE_LOG(logDTFluxCore, Log, TEXT("Reducing %s Formated"), *Formated);
return Formated.Left(MaxSize - 3).Append("...");
}
return Formated;
}
else
// Constructeur privé depuis JSON
FDTFluxParticipant::FDTFluxParticipant(const TSharedPtr<FJsonObject>& JsonObject)
: Bib(JsonObject->GetIntegerField(TEXT("bib")))
, ContestId(JsonObject->GetIntegerField(TEXT("contestId")))
, Category(JsonObject->GetStringField(TEXT("category")))
, Club(JsonObject->GetStringField(TEXT("club")))
, Elite(JsonObject->GetBoolField(TEXT("elite")))
, Status(static_cast<EDTFluxParticipantStatusType>(JsonObject->GetIntegerField(TEXT("status"))))
, Team(JsonObject->GetStringField(TEXT("team")))
, bIsMassStartParticipant(false)
, LastSplitId(-1)
{
UE_LOG(logDTFluxCore, Error, TEXT("Ctor with JSON Object"))
for(uint8 Index = 1; ; Index++)
{
FString FirstNameKey = Index == 1 ? "firstName" : FString::Printf(TEXT("firstName%i"), Index);
FString LastNameKey = Index == 1 ? "lastName" : FString::Printf(TEXT("lastName%i"), Index);
FString GenderKey = Index == 1 ? "gender" : FString::Printf(TEXT("gender%i"), Index);
// max 10 Persons
if(Index >= 10)
{
if(!IsTeam())
{
return FString::Printf(TEXT("%s %s"), *Person1.FirstName, *Person2.LastName);
}
return Team;
break;
}
if (!JsonObject->HasField(FirstNameKey) && !JsonObject->HasField(LastNameKey)
&& !JsonObject->HasField(GenderKey))
{
UE_LOG(logDTFluxCore, Error, TEXT("No Corresponding Field!!!"))
break;
}
const FString FirstName = JsonObject->GetStringField(FirstNameKey);
const FString LastName = JsonObject->GetStringField(LastNameKey);
const FString Gender = JsonObject->GetStringField(GenderKey);
if (FirstName.IsEmpty() && LastName.IsEmpty())
continue;
FDTFluxPerson Person;
Person.FirstName = FirstName;
Person.LastName = LastName;
Person.Gender = Gender;
Teammate.Add(Person);
}
UE_LOG(logDTFluxCore, Error, TEXT("Ctor with JSON Object Teammate is now %i long"), Teammate.Num());
}
FDTFluxParticipant FDTFluxParticipant::CreateFromJson(const TSharedPtr<FJsonObject>& JsonObject)
{
return FDTFluxParticipant(JsonObject);
}
int FDTFluxParticipant::GetTeammateNum() const
{
return Teammate.Num();
}
bool FDTFluxParticipant::IsTeam()
{
return Teammate.Num() < 1;
}