Nancy
This commit is contained in:
@ -45,6 +45,7 @@ public class Aggregation
|
||||
private static ReadOnlyDictionary<int, Aggregation> GetKeyValuePairs(Settings settings, Dictionary<int, List<Notification>> keyValuePairs)
|
||||
{
|
||||
Dictionary<int, Aggregation> results = new();
|
||||
int value;
|
||||
int? inverseValue;
|
||||
double inverseAverage;
|
||||
Aggregation aggregation;
|
||||
@ -60,7 +61,9 @@ public class Aggregation
|
||||
fibonacciCollection.Clear();
|
||||
foreach (Notification notification in keyValuePair.Value)
|
||||
{
|
||||
collection.Add(notification.Value);
|
||||
if (!int.TryParse(notification.Value, out value))
|
||||
continue;
|
||||
collection.Add(value);
|
||||
if (notification.Inverse is null)
|
||||
continue;
|
||||
inverseCollection.Add(notification.Inverse.Value);
|
||||
@ -72,7 +75,7 @@ public class Aggregation
|
||||
continue;
|
||||
inverseAverage = Math.Round(inverseCollection.Average(), settings.Digits);
|
||||
averageFromInverseCeiling = (int)Math.Ceiling(inverseAverage);
|
||||
inverseValue = Notification.GetInverse(averageFromInverseCeiling);
|
||||
inverseValue = Notification.GetInverse(averageFromInverseCeiling.ToString());
|
||||
fibonacciAverage = Math.Round(fibonacciCollection.Average(), settings.Digits);
|
||||
aggregation = new(inverseAverage: inverseAverage,
|
||||
valueCount: collection.Count,
|
||||
@ -107,9 +110,9 @@ public class Aggregation
|
||||
if (string.IsNullOrEmpty(text) || text[0] == '[')
|
||||
continue;
|
||||
notification = JsonSerializer.Deserialize(text, NotificationSourceGenerationContext.Default.Notification);
|
||||
if (notification is null || notification.Id == 0)
|
||||
if (notification is null || string.IsNullOrEmpty(notification.Id))
|
||||
continue;
|
||||
key = !string.IsNullOrEmpty(notification.Username) ? notification.Username : notification.RemoteIpAddress;
|
||||
key = !string.IsNullOrEmpty(notification.Username) ? notification.Username : throw new Exception();
|
||||
if (string.IsNullOrEmpty(key))
|
||||
continue;
|
||||
if (!keyValuePairs.TryGetValue(key, out collection))
|
||||
@ -126,7 +129,7 @@ public class Aggregation
|
||||
results.Add(keyValuePair.Value[0]);
|
||||
else
|
||||
{
|
||||
notification = keyValuePair.Value.Select(record => new KeyValuePair<long, Notification>(record.Time, record)).OrderBy(pair => pair.Key).Last().Value;
|
||||
notification = keyValuePair.Value.Select(record => new KeyValuePair<string, Notification>(record.Time, record)).OrderBy(pair => pair.Key).Last().Value;
|
||||
results.Add(notification);
|
||||
}
|
||||
}
|
||||
@ -137,15 +140,18 @@ public class Aggregation
|
||||
private static ReadOnlyDictionary<int, Aggregation> GetKeyValuePairs(Settings settings, string directory)
|
||||
{
|
||||
ReadOnlyDictionary<int, Aggregation> results;
|
||||
int id;
|
||||
List<Notification>? collection;
|
||||
Dictionary<int, List<Notification>> keyValuePairs = new();
|
||||
ReadOnlyCollection<Notification> notifications = GetNotifications(settings, directory);
|
||||
foreach (Notification notification in notifications)
|
||||
{
|
||||
if (!keyValuePairs.TryGetValue(notification.Id, out collection))
|
||||
if (!int.TryParse(notification.Id, out id))
|
||||
continue;
|
||||
if (!keyValuePairs.TryGetValue(id, out collection))
|
||||
{
|
||||
keyValuePairs.Add(notification.Id, new());
|
||||
if (!keyValuePairs.TryGetValue(notification.Id, out collection))
|
||||
keyValuePairs.Add(id, new());
|
||||
if (!keyValuePairs.TryGetValue(id, out collection))
|
||||
throw new Exception();
|
||||
}
|
||||
collection.Add(notification);
|
||||
@ -185,7 +191,7 @@ public class Aggregation
|
||||
internal static ReadOnlyDictionary<int, Aggregation> GetKeyValuePairs(Settings settings, Notification notification)
|
||||
{
|
||||
ReadOnlyDictionary<int, Aggregation> results;
|
||||
Dictionary<int, List<Notification>> keyValuePairs = new() { { notification.Id, new Notification[] { notification }.ToList() } };
|
||||
Dictionary<int, List<Notification>> keyValuePairs = new() { { int.Parse(notification.Id), new Notification[] { notification }.ToList() } };
|
||||
results = GetKeyValuePairs(settings, keyValuePairs);
|
||||
return results;
|
||||
}
|
||||
|
Reference in New Issue
Block a user