-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REG-2230 Bot Segment List Support + REG-2231 Saving the results] (#375)
Co-authored-by: RG-nAmKcAz <[email protected]>
- Loading branch information
Showing
13 changed files
with
372 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 83 additions & 22 deletions
105
...sion.unity.bots/Runtime/Scripts/StateRecorder/BotSegments/BotSegmentsPlaybackContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,130 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using RegressionGames.StateRecorder.BotSegments.Models; | ||
using StateRecorder.BotSegments.Models; | ||
using StateRecorder.BotSegments.Models.SegmentValidations; | ||
|
||
namespace RegressionGames.StateRecorder.BotSegments | ||
{ | ||
|
||
public class BotSegmentsPlaybackContainer | ||
{ | ||
private readonly List<BotSegment> _botSegments; | ||
|
||
private readonly List<BotSegmentList> _botSegmentLists; | ||
private int _botSegmentListIndex = 0; | ||
private int _botSegmentIndex = 0; | ||
|
||
/** | ||
* A top-level set of validations to run for an entire sequence of segments | ||
*/ | ||
public readonly List<SegmentValidation> Validations; | ||
|
||
public readonly string SessionId; | ||
|
||
public BotSegmentsPlaybackContainer(IEnumerable<BotSegment> segments, IEnumerable<SegmentValidation> validations, string sessionId = null) | ||
public BotSegmentsPlaybackContainer(IEnumerable<BotSegmentList> segmentLists, IEnumerable<SegmentValidation> validations, string sessionId = null) | ||
{ | ||
var replayNumber = 1; // 1 to align with the actual numbers in the recording | ||
_botSegments = new(segments); | ||
_botSegmentLists = new(segmentLists); | ||
_botSegmentLists.ForEach(a => a.segments.ForEach(b => b.Replay_SegmentNumber = replayNumber++)); | ||
Validations = new(validations); | ||
_botSegments.ForEach(a => a.Replay_SegmentNumber = replayNumber++); | ||
this.SessionId = sessionId ?? Guid.NewGuid().ToString("n"); | ||
} | ||
|
||
public void Reset() | ||
{ | ||
// sets indexes back to 0 | ||
_botSegmentIndex = 0; | ||
_botSegmentListIndex = 0; | ||
|
||
// reset all the tracking flags | ||
foreach (var botSegment in _botSegments) | ||
// reset all the tracking flags in the segmentlists / segments | ||
_botSegmentLists.ForEach(a => | ||
{ | ||
botSegment.ReplayReset(); | ||
} | ||
|
||
// reset all the top-level validations | ||
a.segments.ForEach(b => b.ReplayReset()); // This also handles resetting that segments validations | ||
a.validations.ForEach(b => b.ReplayReset()); | ||
}); | ||
|
||
// reset all the top-level sequence validations | ||
foreach (var validation in Validations) | ||
{ | ||
validation.ReplayReset(); | ||
} | ||
|
||
} | ||
|
||
public BotSegment DequeueBotSegment() | ||
/** | ||
* Returns the next bot segment and validations to evaluate and also provides the current segmentList level validations | ||
*/ | ||
public (BotSegment, List<SegmentValidation>)? DequeueBotSegment() | ||
{ | ||
if (_botSegmentIndex < _botSegments.Count) | ||
while (_botSegmentListIndex < _botSegmentLists.Count) | ||
{ | ||
return _botSegments[_botSegmentIndex++]; | ||
} | ||
var segmentList = _botSegmentLists[_botSegmentListIndex]; | ||
if (_botSegmentIndex < segmentList.segments.Count) | ||
{ | ||
var segment = segmentList.segments[_botSegmentIndex++]; | ||
var segmentListValidations = segmentList.validations; | ||
return (segment, segmentListValidations); | ||
} | ||
else | ||
{ | ||
// move to the next segmentlist starting on the 0th segment in that list | ||
_botSegmentIndex = 0; | ||
++_botSegmentListIndex; | ||
} | ||
|
||
} | ||
|
||
return null; | ||
} | ||
|
||
public BotSegment PeekBotSegment() | ||
|
||
|
||
/** | ||
* <summary>Collects all of the results from the top-level validations and individual bot segments</summary> | ||
*/ | ||
public List<SegmentValidationResultSetContainer> GetAllValidationResults() | ||
{ | ||
if (_botSegmentIndex < _botSegments.Count) | ||
|
||
// First add all the top level results | ||
var results = Validations.Select(validation => validation.data.GetResults()).ToList(); | ||
|
||
// Then add the validations from bot segment lists and individual bot segment results | ||
foreach (var botSegmentList in _botSegmentLists) | ||
{ | ||
// do not update index | ||
return _botSegments[_botSegmentIndex]; | ||
results.AddRange(botSegmentList.validations.Select(v => v.data.GetResults())); | ||
|
||
foreach (var botSegment in botSegmentList.segments) | ||
{ | ||
results.AddRange(botSegment.validations.Select(v => v.data.GetResults())); | ||
} | ||
} | ||
|
||
return null; | ||
return results; | ||
} | ||
|
||
/** | ||
* <summary> | ||
* This will request to stop all validations in the container, including sequence validations, bot | ||
* segment list validations, and individual bot segment validations. | ||
* </summary> | ||
*/ | ||
public void StopAllValidations(int segmentNumber) | ||
{ | ||
// First stop the sequence validations | ||
foreach (var validation in Validations) | ||
{ | ||
validation.StopValidation(segmentNumber); | ||
} | ||
|
||
// Then stop the segment list validations and bot segment validations | ||
foreach (var botSegmentList in _botSegmentLists) | ||
{ | ||
botSegmentList.validations.ForEach(v => v.StopValidation(segmentNumber)); | ||
foreach (var botSegment in botSegmentList.segments) | ||
{ | ||
botSegment.validations.ForEach(v => v.StopValidation(segmentNumber)); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.