Fixed Query Filter at Replay Request

This commit is contained in:
Thorbjoern
2025-06-14 21:41:24 +02:00
parent 36bd205512
commit b4b70e2bf7
3 changed files with 9020 additions and 101 deletions
File diff suppressed because it is too large Load Diff
@@ -9,13 +9,15 @@ using Cysharp.Threading.Tasks;
using UnityEngine.Rendering.Universal; using UnityEngine.Rendering.Universal;
using System.Globalization; using System.Globalization;
using Oculus.Interaction; using Oculus.Interaction;
using System.Reactive;
using Postgrest.Interfaces;
namespace GhostSystem namespace GhostSystem
{ {
public class GhostReplayManager : MonoBehaviour public class GhostReplayManager : MonoBehaviour
{ {
[Header("Replay Settings")] [Header("Replay Settings")]
public string SceneId; public string sceneId;
public string UserFilter = null; // optional: filtere nach User-ID public string UserFilter = null; // optional: filtere nach User-ID
public bool Loop = true; public bool Loop = true;
public DateTime selectedStartTime; public DateTime selectedStartTime;
@@ -95,7 +97,7 @@ namespace GhostSystem
{ {
if (!supabaseReady || !sceneIdReady) return; if (!supabaseReady || !sceneIdReady) return;
SceneId = loadedSceneId; sceneId = loadedSceneId;
await LoadAllFrames(); await LoadAllFrames();
StartReplay(); StartReplay();
@@ -104,11 +106,12 @@ namespace GhostSystem
public async UniTask LoadAllFrames() public async UniTask LoadAllFrames()
{ {
Debug.Log("SceneId used in query: " + SceneId); Debug.Log("SceneId used in query: " + sceneId);
Debug.Log("StartTime filter: " + dateSelector.selectedDateTime().ToString("o")); Debug.Log("StartTime filter: " + dateSelector.selectedDateTime().ToString("o"));
Debug.Log("EndTime filter: " + dateSelector.EndTime().ToString("o"));
var startTime = dateSelector.selectedDateTime(); var startTime = dateSelector.selectedDateTime();
var endTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute + 15, 0, DateTimeKind.Utc); var endTime = dateSelector.EndTime();
objectTracks.Clear(); objectTracks.Clear();
int batchSize = 1000; int batchSize = 1000;
@@ -118,22 +121,28 @@ namespace GhostSystem
while (more) while (more)
{ {
List<IPostgrestQueryFilter> timestampFilter = new List<IPostgrestQueryFilter>();
timestampFilter.Add(new QueryFilter("timestamp", Postgrest.Constants.Operator.GreaterThanOrEqual, startTime.ToString("o")));
timestampFilter.Add(new QueryFilter("timestamp", Postgrest.Constants.Operator.LessThan, endTime.ToString("o")));
var query = SupabaseManager.instance.supabase var query = SupabaseManager.instance.supabase
.From<FrameModel>() .From<FrameModel>()
.Filter("scene_id", Postgrest.Constants.Operator.Equals, SceneId) .Filter("scene_id", Postgrest.Constants.Operator.Equals, sceneId)
.Filter("timestamp", Postgrest.Constants.Operator.GreaterThanOrEqual, startTime.ToString("o")) //.Where(x => x.Timestamp >= "timestamp '2025-06-14 10:27:00' and" x => x.Timestamp.timestamp <= "timestamp '2025-06-14 10:29:00'")
//.Filter("timestamp", Postgrest.Constants.Operator.GreaterThanOrEqual, startTime.ToString("o"))
.And(timestampFilter)
//.Filter("timestamp", Postgrest.Constants.Operator.LessThan, endTime.ToString("o"))
.Order("timestamp", Postgrest.Constants.Ordering.Ascending) .Order("timestamp", Postgrest.Constants.Ordering.Ascending)
.Limit(batchSize) // Limit, wie viele Frames in einem Batch geladen werden. (Standardmäßig 1000) .Limit(batchSize) // Limit, wie viele Frames in einem Batch geladen werden. (Standardmäßig 1000)
.Offset(offset); // Um zu wissen, wo der nçhste Batch anfängt .Offset(offset); // Um zu wissen, wo der nächste Batch anfängt
/*if (LimitTimeRange)
query = query.Filter("timestamp", Postgrest.Constants.Operator.LessThanOrEqual, endTime.ToString("o"));*/
if (!string.IsNullOrEmpty(UserFilter)) if (!string.IsNullOrEmpty(UserFilter))
query = query.Filter("user_id", Postgrest.Constants.Operator.Equals, UserFilter); query = query.Filter("user_id", Postgrest.Constants.Operator.Equals, UserFilter);
var result = await query.Get(); var result = await query.Get();
if (result.Models.Count == 0) break; if (result.Models.Count == 0) break;
if (result.Models[0].SceneId != sceneId) break;
Debug.LogError("Model Count: " + result.Models.Count);
allFrames.AddRange(result.Models); allFrames.AddRange(result.Models);
offset += batchSize; offset += batchSize;
more = result.Models.Count == batchSize; more = result.Models.Count == batchSize;
@@ -168,18 +177,20 @@ namespace GhostSystem
private async UniTask LoadNewFramesAfter(DateTime afterTime) // lädt einen neuen Batch nach. private async UniTask LoadNewFramesAfter(DateTime afterTime) // lädt einen neuen Batch nach.
{ {
var startTime = dateSelector.selectedDateTime(); var endTime = dateSelector.EndTime();
var endTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute + 15, 0, DateTimeKind.Utc);
List<IPostgrestQueryFilter> timestampFilter = new List<IPostgrestQueryFilter>();
timestampFilter.Add(new QueryFilter("timestamp", Postgrest.Constants.Operator.GreaterThan, afterTime.ToString("o")));
timestampFilter.Add(new QueryFilter("timestamp", Postgrest.Constants.Operator.LessThan, endTime.ToString("o")));
var query = SupabaseManager.instance.supabase var query = SupabaseManager.instance.supabase
.From<FrameModel>() .From<FrameModel>()
.Filter("scene_id", Postgrest.Constants.Operator.Equals, SceneId) .Filter("scene_id", Postgrest.Constants.Operator.Equals, sceneId)
.Filter("timestamp", Postgrest.Constants.Operator.GreaterThan, afterTime.ToString("o")) .And(timestampFilter)
//.Filter("timestamp", Postgrest.Constants.Operator.GreaterThan, afterTime.ToString("o"))
//.Filter("timestamp", Postgrest.Constants.Operator.LessThanOrEqual, endTime.ToString("o"))
.Order("timestamp", Postgrest.Constants.Ordering.Ascending); .Order("timestamp", Postgrest.Constants.Ordering.Ascending);
/*if (LimitTimeRange)
query = query.Filter("timestamp", Postgrest.Constants.Operator.LessThanOrEqual, endTime.ToString("o"));*/
if (!string.IsNullOrEmpty(UserFilter)) if (!string.IsNullOrEmpty(UserFilter))
query = query.Filter("user_id", Postgrest.Constants.Operator.Equals, UserFilter); query = query.Filter("user_id", Postgrest.Constants.Operator.Equals, UserFilter);
+13 -1
View File
@@ -10,6 +10,7 @@ public class DateSelector : MonoBehaviour
public int selectedDay; public int selectedDay;
public int selectedHour; public int selectedHour;
public int selectedMinute; public int selectedMinute;
public int duration;
public void SetYear(int yearIndex) public void SetYear(int yearIndex)
{ {
@@ -33,7 +34,12 @@ public class DateSelector : MonoBehaviour
public void SetMinute(int minuteIndex) public void SetMinute(int minuteIndex)
{ {
selectedMinute = minuteIndex * 5; // 059 selectedMinute = minuteIndex * 5; // 055 in 5er Schritten
}
public void SetDuration(int durationIndex)
{
duration = durationIndex * 5; // 055 in 5er Schritten
} }
public DateTime selectedDateTime() public DateTime selectedDateTime()
{ {
@@ -41,4 +47,10 @@ public class DateSelector : MonoBehaviour
return dateAndTime; return dateAndTime;
} }
public DateTime EndTime()
{
DateTime dateAndTime = selectedDateTime().AddMinutes(duration);
return dateAndTime;
}
} }