mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-25 05:00:07 +00:00
fix duraton in session list
This commit is contained in:
@@ -1 +1 @@
|
||||
119
|
||||
121
|
||||
|
||||
@@ -419,9 +419,13 @@ namespace AutopilotMonitor.Functions.Services
|
||||
// Store accurate DurationSeconds based on first event timestamp (not registration StartedAt)
|
||||
// The agent registers before events arrive, so registration StartedAt is always earlier
|
||||
// than the actual enrollment start — using the first event gives the true enrollment duration.
|
||||
var durationStart = earliestEventTimestamp ?? currentStartedAt;
|
||||
if (durationStart < effectiveCompletedAt)
|
||||
update["DurationSeconds"] = (int)(effectiveCompletedAt - durationStart).TotalSeconds;
|
||||
// Use the effective StartedAt (already corrected by earlier batches via the StartedAt
|
||||
// alignment above), taking the minimum with the current batch's earliest timestamp.
|
||||
var effectiveStartedAt = earliestEventTimestamp.HasValue && earliestEventTimestamp.Value < currentStartedAt
|
||||
? earliestEventTimestamp.Value
|
||||
: currentStartedAt;
|
||||
if (effectiveStartedAt < effectiveCompletedAt)
|
||||
update["DurationSeconds"] = (int)(effectiveCompletedAt - effectiveStartedAt).TotalSeconds;
|
||||
}
|
||||
|
||||
// Track the most recent event timestamp for excessive data sender detection
|
||||
@@ -704,10 +708,15 @@ namespace AutopilotMonitor.Functions.Services
|
||||
Status = status,
|
||||
FailureReason = entity.GetString("FailureReason") ?? string.Empty,
|
||||
EventCount = SafeGetInt32(entity, "EventCount") ?? 0,
|
||||
DurationSeconds = SafeGetInt32(entity, "DurationSeconds")
|
||||
?? (completedAt.HasValue
|
||||
DurationSeconds = SafeGetInt32(entity, "DurationSeconds") switch
|
||||
{
|
||||
// Stored duration is valid — use it directly
|
||||
int d when d > 0 => d,
|
||||
// Duration missing or zero (bug from batch-split race) — recompute from timestamps
|
||||
_ => completedAt.HasValue
|
||||
? (int)(completedAt.Value - startedAt).TotalSeconds
|
||||
: (int)(DateTime.UtcNow - startedAt).TotalSeconds),
|
||||
: (int)(DateTime.UtcNow - startedAt).TotalSeconds
|
||||
},
|
||||
EnrollmentType = entity.GetString("EnrollmentType") ?? "v1",
|
||||
DiagnosticsBlobName = entity.GetString("DiagnosticsBlobName"),
|
||||
LastEventAt = SafeGetDateTime(entity, "LastEventAt"),
|
||||
|
||||
Reference in New Issue
Block a user