// 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) { } void UDTFluxModelAsset::AddContest(const FDTFluxContest& Contest) { Contests.Add(Contest.Name, Contest); // initialisation for (const auto& Stage : Contest.Stages) { FinishedStagesCache.Add(FDTFluxStageKey(Contest.ContestId, Stage.StageId), Stage.IsFinished()); } TArray 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); } bool UDTFluxModelAsset::GetContestById(const int InContestId, FDTFluxContest& OutContest) { for (auto& ContestItem : Contests) { if (ContestItem.Value.ContestId == InContestId) { OutContest = ContestItem.Value; return true; } } return false; } bool UDTFluxModelAsset::GetStage(FDTFluxStageKey StageKey, FDTFluxStage& OutStage) { FDTFluxContest TargetContest; int TargetStageId = StageKey.StageId; if (GetContestById(StageKey.ContestId, TargetContest)) { return TargetContest.GetStage(TargetStageId, OutStage); } return false; } void UDTFluxModelAsset::AddPerson(const FDTFluxPerson& InPerson) { Persons.Add(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)) { TArray Teammate = InParticipant.Teammate; for (auto& Person : InParticipant.Teammate) { UE_LOG(logDTFluxCore, Error, TEXT("AddParticipant() DTFlux Person %s %s %s"), *Person.FirstName, *Person.LastName, *Person.Gender); if (!PersonExists(Person)) { 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); TargetContest.ParticipantsBib.Add(InParticipant.Bib); } } bool UDTFluxModelAsset::PersonExists(const FDTFluxPerson& InPerson) const { return Persons.ContainsByPredicate([InPerson](const FDTFluxPerson& Person) { 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); } 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; if (Participants.Contains(Bib)) { TArray 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 for (const auto& Person : InTeammate) { //Don't know what to do... } } } void UDTFluxModelAsset::UpdateParticipantStatus(const FDTFluxTeamStatusUpdate& NewParticipantStatus) { if (Participants.Contains(NewParticipantStatus.Bib)) { Participants[NewParticipantStatus.Bib].Status = NewParticipantStatus.Status; } } bool UDTFluxModelAsset::GetParticipantByBib(int Bib, FDTFluxParticipant& OutParticipant) { if (Participants.Contains(Bib)) { OutParticipant = Participants[Bib]; return true; } return false; } 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; } void UDTFluxModelAsset::CacheSplitSensorInfo(const FDTFluxSplitSensorKey SplitSensorKey, const FDTFluxSplitSensorInfo& SplitSensorInfo) { SplitSensorInfoCache.Add(SplitSensorKey, SplitSensorInfo); } bool UDTFluxModelAsset::CheckStageIsFinished(FDTFluxStageKey StageKey) { FDTFluxStage Stage; if (GetStage(StageKey, Stage)) { FinishedStagesCache.Add(StageKey, Stage.IsFinished()); return FinishedStagesCache[StageKey]; } return false; } void UDTFluxModelAsset::UpdateOrCreateStageRanking(const FDTFluxStageRankings& InStageRankings) { 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); } void UDTFluxModelAsset::UpdateOrCreateSplitRanking(const FDTFluxSplitRankings& InSplitRankings) { FDTFluxSplitKey SplitKey = InSplitRankings.GetCompositeKey(); SplitRankings.FindOrAdd(SplitKey) = InSplitRankings; }