Weighted Shortest Job First Hub
This commit is contained in:
82
Adaptation/FileHandlers/Priority/Notification.cs
Normal file
82
Adaptation/FileHandlers/Priority/Notification.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Adaptation.FileHandlers.Priority;
|
||||
|
||||
#nullable enable
|
||||
|
||||
public class Notification
|
||||
{
|
||||
|
||||
[JsonConstructor]
|
||||
public Notification(int? fibonacci,
|
||||
int id,
|
||||
int? inverse,
|
||||
string page,
|
||||
string? remoteIpAddress,
|
||||
string? site,
|
||||
long time,
|
||||
int value)
|
||||
{
|
||||
int? i = inverse is not null ? inverse : GetInverse(value);
|
||||
Fibonacci = fibonacci is not null ? fibonacci : i is null ? null : GetFibonacci(i.Value);
|
||||
Id = id;
|
||||
Inverse = i;
|
||||
Page = page;
|
||||
RemoteIpAddress = remoteIpAddress is not null ? remoteIpAddress : null;
|
||||
Site = site is not null ? site : "MES";
|
||||
Time = time;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
[JsonPropertyName("id")] public int Id { get; }
|
||||
[JsonPropertyName("fibonacci")] public int? Fibonacci { get; }
|
||||
[JsonPropertyName("inverse")] public int? Inverse { get; }
|
||||
[JsonPropertyName("page")] public string Page { get; }
|
||||
[JsonPropertyName("RemoteIpAddress")] public string? RemoteIpAddress { get; }
|
||||
[JsonPropertyName("site")] public string? Site { get; }
|
||||
[JsonPropertyName("time")] public long Time { get; }
|
||||
[JsonPropertyName("value")] public int Value { get; }
|
||||
|
||||
internal static int? GetInverse(int value) =>
|
||||
value switch
|
||||
{
|
||||
1 => 5,
|
||||
2 => 4,
|
||||
3 => 3,
|
||||
4 => 2,
|
||||
5 => 1,
|
||||
_ => null
|
||||
};
|
||||
|
||||
private static int? GetFibonacci(int value) =>
|
||||
value switch
|
||||
{
|
||||
9 => 55,
|
||||
8 => 34,
|
||||
7 => 21,
|
||||
6 => 13,
|
||||
5 => 8,
|
||||
4 => 5,
|
||||
3 => 3,
|
||||
2 => 2,
|
||||
1 => 1,
|
||||
_ => null
|
||||
};
|
||||
|
||||
internal static Notification GetNotification(Notification notification, string? remoteIpAddress, string? connectionId) =>
|
||||
new(notification.Fibonacci,
|
||||
notification.Id,
|
||||
notification.Inverse,
|
||||
notification.Page,
|
||||
remoteIpAddress ?? connectionId,
|
||||
notification.Site,
|
||||
notification.Time,
|
||||
notification.Value);
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Notification))]
|
||||
public partial class NotificationSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user