2025-06-29 19:04:36 +02:00
|
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Assets/DTFluxModelAsset.h"
|
|
|
|
|
|
#include "DTFluxCoreModule.h"
|
|
|
|
|
|
#include "Types/Objects/DTFluxContestStorage.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UDTFluxModelAsset::UDTFluxModelAsset(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-08 16:50:31 +02:00
|
|
|
|
void UDTFluxModelAsset::AddContest(const FDTFluxContest& Contest)
|
2025-06-29 19:04:36 +02:00
|
|
|
|
{
|
|
|
|
|
|
Contests.Add(Contest.Name, Contest);
|
2025-07-14 15:40:03 +02:00
|
|
|
|
// initialisation
|
|
|
|
|
|
for (const auto& Stage : Contest.Stages)
|
|
|
|
|
|
{
|
|
|
|
|
|
FinishedStagesCache.Add(FDTFluxStageKey(Contest.ContestId, Stage.StageId), Stage.IsFinished());
|
2025-07-15 07:59:45 +02:00
|
|
|
|
for (const auto&Split : Contest.Splits)
|
|
|
|
|
|
{
|
|
|
|
|
|
// init Cached SplitSensorInfo
|
|
|
|
|
|
SplitSensorInfoCache.Add(FDTFluxSplitSensorKey(Contest.ContestId, Stage.StageId, Split.SplitId, -1),
|
|
|
|
|
|
FDTFluxSplitSensorInfo(Split.Name));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-14 15:40:03 +02:00
|
|
|
|
}
|
2025-07-15 07:59:45 +02:00
|
|
|
|
TArray<FDTFluxSplit> Splits = Contest.Splits;
|
|
|
|
|
|
Splits.Sort([](const FDTFluxSplit& A, const FDTFluxSplit& B)
|
|
|
|
|
|
{
|
|
|
|
|
|
return A.SplitId < B.SplitId;
|
|
|
|
|
|
});
|
|
|
|
|
|
// last and Penultimate split cache for contest
|
|
|
|
|
|
LastSplitIdCache.Add(Contest.ContestId, Splits.Pop().SplitId);
|
|
|
|
|
|
PenultimateSplitIdCache.Add(Contest.ContestId, Splits.Pop().SplitId);
|
|
|
|
|
|
|
2025-06-29 19:04:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool UDTFluxModelAsset::GetContestById(const int InContestId, FDTFluxContest& OutContest)
|
|
|
|
|
|
{
|
2025-07-08 16:50:31 +02:00
|
|
|
|
for (auto& ContestItem : Contests)
|
2025-06-29 19:04:36 +02:00
|
|
|
|
{
|
2025-07-08 16:50:31 +02:00
|
|
|
|
if (ContestItem.Value.ContestId == InContestId)
|
2025-06-29 19:04:36 +02:00
|
|
|
|
{
|
|
|
|
|
|
OutContest = ContestItem.Value;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2025-07-08 16:50:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2025-06-29 19:04:36 +02:00
|
|
|
|
|
2025-07-08 16:50:31 +02:00
|
|
|
|
bool UDTFluxModelAsset::GetStage(FDTFluxStageKey StageKey, FDTFluxStage& OutStage)
|
|
|
|
|
|
{
|
|
|
|
|
|
FDTFluxContest TargetContest;
|
|
|
|
|
|
int TargetStageId = StageKey.StageId;
|
|
|
|
|
|
if (GetContestById(StageKey.ContestId, TargetContest))
|
|
|
|
|
|
{
|
|
|
|
|
|
return TargetContest.GetStage(TargetStageId, OutStage);
|
2025-06-29 19:04:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDTFluxModelAsset::AddPerson(const FDTFluxPerson& InPerson)
|
|
|
|
|
|
{
|
|
|
|
|
|
Persons.Add(InPerson);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDTFluxModelAsset::AddParticipant(const FDTFluxParticipant& InParticipant, const int ContestId)
|
|
|
|
|
|
{
|
2025-07-08 16:50:31 +02:00
|
|
|
|
UE_LOG(logDTFluxCore, Error, TEXT("%i Person in Participant %i"), InParticipant.GetTeammateNum(),
|
|
|
|
|
|
InParticipant.Bib);
|
2025-06-29 19:04:36 +02:00
|
|
|
|
FDTFluxContest TargetContest;
|
2025-07-08 16:50:31 +02:00
|
|
|
|
if (GetContestById(ContestId, TargetContest))
|
2025-06-29 19:04:36 +02:00
|
|
|
|
{
|
2025-07-03 17:28:51 +02:00
|
|
|
|
TArray<FDTFluxPerson> Teammate = InParticipant.Teammate;
|
2025-07-08 16:50:31 +02:00
|
|
|
|
for (auto& Person : InParticipant.Teammate)
|
2025-06-29 19:04:36 +02:00
|
|
|
|
{
|
2025-07-03 17:28:51 +02:00
|
|
|
|
UE_LOG(logDTFluxCore, Error, TEXT("AddParticipant() DTFlux Person %s %s %s"),
|
2025-07-08 16:50:31 +02:00
|
|
|
|
*Person.FirstName, *Person.LastName, *Person.Gender);
|
|
|
|
|
|
if (!PersonExists(Person))
|
2025-06-29 19:04:36 +02:00
|
|
|
|
{
|
2025-07-03 17:28:51 +02:00
|
|
|
|
UE_LOG(logDTFluxCore, Error, TEXT("AddParticipant() DTFlux Person %s %s %s doesnot exists, adding..."),
|
2025-07-08 16:50:31 +02:00
|
|
|
|
*Person.FirstName, *Person.LastName, *Person.Gender);
|
2025-07-03 17:28:51 +02:00
|
|
|
|
AddPerson(Person);
|
2025-06-29 19:04:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Participants.Add(InParticipant.Bib, InParticipant);
|
|
|
|
|
|
TargetContest.ParticipantsBib.Add(InParticipant.Bib);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool UDTFluxModelAsset::PersonExists(const FDTFluxPerson& InPerson) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Persons.ContainsByPredicate([InPerson](const FDTFluxPerson& Person)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Person == InPerson;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-06-30 19:02:19 +02:00
|
|
|
|
|
|
|
|
|
|
FString UDTFluxModelAsset::GetContestNameForId(const int InContestID)
|
|
|
|
|
|
{
|
|
|
|
|
|
FDTFluxContest Contest;
|
2025-07-08 16:50:31 +02:00
|
|
|
|
if (!GetContestById(InContestID, Contest))
|
2025-06-30 19:02:19 +02:00
|
|
|
|
{
|
2025-07-08 16:50:31 +02:00
|
|
|
|
UE_LOG(logDTFluxCore, Warning,
|
|
|
|
|
|
TEXT("GetContestNameForId(%i) [unable to find a contest] result will be empty !!!"),
|
|
|
|
|
|
InContestID);
|
2025-06-30 19:02:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
return Contest.Name;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDTFluxModelAsset::AddContestRanking(const FDTFluxContestRankings& NewContestRankings)
|
|
|
|
|
|
{
|
|
|
|
|
|
ContestRankings.Add(NewContestRankings.ContestId, NewContestRankings);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-04 01:13:07 +02:00
|
|
|
|
void UDTFluxModelAsset::UpdateParticipant(const FDTFluxParticipant& Participant)
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO : If update is on Bib we are totally lost as we search by bib.
|
|
|
|
|
|
int Bib = Participant.Bib;
|
2025-07-08 16:50:31 +02:00
|
|
|
|
if (Participants.Contains(Bib))
|
2025-07-04 01:13:07 +02:00
|
|
|
|
{
|
|
|
|
|
|
TArray<FDTFluxPerson> InTeammate = Participant.Teammate;
|
|
|
|
|
|
Participants[Bib].Elite = Participant.Elite;
|
|
|
|
|
|
Participants[Bib].ContestId = Participant.ContestId;
|
|
|
|
|
|
Participants[Bib].Club = Participant.Club;
|
|
|
|
|
|
Participants[Bib].Category = Participant.Category;
|
|
|
|
|
|
Participants[Bib].Team = Participant.Team;
|
|
|
|
|
|
Participants[Bib].Status = Participant.Status;
|
|
|
|
|
|
//TODO : Update Person
|
2025-07-08 16:50:31 +02:00
|
|
|
|
for (const auto& Person : InTeammate)
|
2025-07-04 01:13:07 +02:00
|
|
|
|
{
|
|
|
|
|
|
//Don't know what to do...
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDTFluxModelAsset::UpdateParticipantStatus(const FDTFluxTeamStatusUpdate& NewParticipantStatus)
|
|
|
|
|
|
{
|
2025-07-08 16:50:31 +02:00
|
|
|
|
if (Participants.Contains(NewParticipantStatus.Bib))
|
2025-07-04 01:13:07 +02:00
|
|
|
|
{
|
|
|
|
|
|
Participants[NewParticipantStatus.Bib].Status = NewParticipantStatus.Status;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-08 16:50:31 +02:00
|
|
|
|
bool UDTFluxModelAsset::GetParticipantByBib(int Bib, FDTFluxParticipant& OutParticipant)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Participants.Contains(Bib))
|
|
|
|
|
|
{
|
|
|
|
|
|
OutParticipant = Participants[Bib];
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-14 15:40:03 +02:00
|
|
|
|
bool UDTFluxModelAsset::IsStageFinished(FDTFluxStageKey StageKey)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!FinishedStagesCache.Contains(StageKey))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (FinishedStagesCache[StageKey])
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
//maybe stage is finished because we have not be able to set it ?
|
|
|
|
|
|
return CheckStageIsFinished(StageKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-15 07:59:45 +02:00
|
|
|
|
void UDTFluxModelAsset::CacheSplitSensorInfo(const FDTFluxSplitSensorKey SplitSensorKey,
|
|
|
|
|
|
const FDTFluxSplitSensorInfo& SplitSensorInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
SplitSensorInfoCache.Add(SplitSensorKey, SplitSensorInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-14 15:40:03 +02:00
|
|
|
|
|
|
|
|
|
|
bool UDTFluxModelAsset::CheckStageIsFinished(FDTFluxStageKey StageKey)
|
|
|
|
|
|
{
|
|
|
|
|
|
FDTFluxStage Stage;
|
|
|
|
|
|
if (GetStage(StageKey, Stage))
|
|
|
|
|
|
{
|
|
|
|
|
|
FinishedStagesCache.Add(StageKey, Stage.IsFinished());
|
|
|
|
|
|
return FinishedStagesCache[StageKey];
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-08 16:50:31 +02:00
|
|
|
|
|
2025-07-03 17:28:51 +02:00
|
|
|
|
void UDTFluxModelAsset::UpdateOrCreateStageRanking(const FDTFluxStageRankings& InStageRankings)
|
2025-06-30 19:02:19 +02:00
|
|
|
|
{
|
2025-07-03 17:28:51 +02:00
|
|
|
|
FDTFluxStageKey StageKey = InStageRankings.GetCompositeKey();
|
|
|
|
|
|
StageRankings.FindOrAdd(StageKey) = InStageRankings;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDTFluxModelAsset::AddStageRanking(const FDTFluxStageRankings& InStageRankings)
|
|
|
|
|
|
{
|
|
|
|
|
|
StageRankings.Add(InStageRankings.GetCompositeKey(), InStageRankings);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDTFluxModelAsset::AddSplitRanking(const FDTFluxSplitRankings& InSplitRanking)
|
|
|
|
|
|
{
|
|
|
|
|
|
SplitRankings.Add(InSplitRanking.GetCompositeKey(), InSplitRanking);
|
2025-06-30 19:02:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-03 17:28:51 +02:00
|
|
|
|
void UDTFluxModelAsset::UpdateOrCreateSplitRanking(const FDTFluxSplitRankings& InSplitRankings)
|
2025-06-30 19:02:19 +02:00
|
|
|
|
{
|
2025-07-03 17:28:51 +02:00
|
|
|
|
FDTFluxSplitKey SplitKey = InSplitRankings.GetCompositeKey();
|
|
|
|
|
|
SplitRankings.FindOrAdd(SplitKey) = InSplitRankings;
|
2025-06-30 19:02:19 +02:00
|
|
|
|
}
|