Track sub state

This commit is contained in:
Liza 2024-03-03 20:13:56 +01:00
parent 3125911eaf
commit 1cbe018642
Signed by: liza
GPG Key ID: 7199F8D727D55F67
5 changed files with 19 additions and 0 deletions

View File

@ -240,6 +240,7 @@ internal sealed class InfluxStatisticsClient : IDisposable
.Tag("build", sub.Build)
.Field("level", sub.Level)
.Field("predicted_level", sub.PredictedLevel)
.Field("state", (int)sub.State)
.Timestamp(date, WritePrecision.S));
}
}

View File

@ -0,0 +1,8 @@
namespace Influx.SubmarineTracker;
public enum EState
{
NoVoyage,
Returned,
Voyage,
}

View File

@ -14,6 +14,13 @@ public sealed class Submarine
{
(uint predictedLevel, double _) = ((uint, double))@delegate.GetType().GetMethod("PredictExpGrowth")!.Invoke(@delegate, Array.Empty<object?>())!;
PredictedLevel = (ushort)predictedLevel;
bool onVoyage = (bool)@delegate.GetType().GetMethod("IsOnVoyage")!.Invoke(@delegate, Array.Empty<object>())!;
bool returned = (bool)@delegate.GetType().GetMethod("IsDone")!.Invoke(@delegate, Array.Empty<object>())!;
if (onVoyage)
State = returned ? EState.Returned : EState.Voyage;
else
State = EState.NoVoyage;
}
catch (Exception)
{
@ -25,4 +32,5 @@ public sealed class Submarine
public ushort Level { get; }
public ushort PredictedLevel { get; }
public Build Build { get; }
public EState State { get; }
}

View File

@ -12,4 +12,5 @@ public sealed class SubmarineStats
public required string Bow { get; init; }
public required string Bridge { get; init; }
public required string Build { get; init; }
public required EState State { get; init; }
}

View File

@ -52,6 +52,7 @@ internal sealed class SubmarineTrackerIpc
Bow = y.Build.BowIdentifier,
Bridge = y.Build.BridgeIdentifier,
Build = y.Build.FullIdentifier,
State = y.State,
}).ToList());
}
else