Skip to content

Commit

Permalink
[REG-2230 Bot Segment List Support + REG-2231 Saving the results] (#375)
Browse files Browse the repository at this point in the history
Co-authored-by: RG-nAmKcAz <[email protected]>
  • Loading branch information
vontell and nAmKcAz authored Dec 19, 2024
1 parent ccf2ff3 commit 7bc3d56
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RGSegmentEntry : MonoBehaviour
* <summary>Indicates whether the Segment or Segment List is overridden by a local file.</summary>
*/
public bool isOverride;

/**
* UI component fields
*/
Expand All @@ -49,7 +49,7 @@ public class RGSegmentEntry : MonoBehaviour

[SerializeField]
public GameObject segmentListIndicatorComponent;

[SerializeField]
public GameObject overrideIndicator;

Expand Down Expand Up @@ -84,8 +84,8 @@ public void Start()
resourcePathComponent.gameObject.SetActive(false);
}
}
// set indicator that this Segment is being overriden by a local file, within a build

// set indicator that this Segment is being overriden by a local file, within a build
overrideIndicator.gameObject.SetActive(isOverride);

// assign values to the UI components
Expand Down Expand Up @@ -141,7 +141,8 @@ private void OnPlay()
}

// play the segment
playbackController.SetDataContainer(new BotSegmentsPlaybackContainer(segmentList.segments, new List<SegmentValidation>(), sessionId));
playbackController.SetDataContainer(new BotSegmentsPlaybackContainer(new List<BotSegmentList>() {segmentList}, new List<SegmentValidation>(), sessionId));

playbackController.Play();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using System.IO.Compression;
using System.Linq;
using Newtonsoft.Json;
using RegressionGames.StateRecorder.BotSegments.JsonConverters;
using RegressionGames.StateRecorder.BotSegments.Models;
using StateRecorder.BotSegments;

namespace RegressionGames.StateRecorder.BotSegments
{
Expand Down Expand Up @@ -66,9 +64,9 @@ public static IOrderedEnumerable<ZipArchiveEntry> OrderZipJsonEntries(IEnumerabl
return entries;
}

public static List<BotSegment> ParseBotSegmentZipFromSystemPath(string zipFilePath, out string sessionId)
public static List<BotSegmentList> ParseBotSegmentZipFromSystemPath(string zipFilePath, out string sessionId)
{
List<BotSegment> results = new();
List<BotSegmentList> results = new();

sessionId = null;

Expand Down Expand Up @@ -100,17 +98,7 @@ public static List<BotSegment> ParseBotSegmentZipFromSystemPath(string zipFilePa
break;
}

foreach (var botSegment in botSegmentList.segments)
{
botSegment.Replay_SegmentNumber = replayNumber++;

if (sessionId == null)
{
sessionId = botSegment.sessionId;
}

results.Add(botSegment);
}
results.Add(botSegmentList);
}
catch (Exception)
{
Expand All @@ -132,7 +120,16 @@ public static List<BotSegment> ParseBotSegmentZipFromSystemPath(string zipFilePa
sessionId = frameData.sessionId;
}

results.Add(frameData);
results.Add(new BotSegmentList()
{
segments = new List<BotSegment>()
{
frameData
},
name = "BotSegmentList for BotSegment - " + frameData.name,
description = "BotSegmentList for BotSegment - " + frameData.description,
validations = new()
});
}
catch (Exception ex)
{
Expand Down
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));
}
}
}

}
}
Loading

0 comments on commit 7bc3d56

Please sign in to comment.