From 781dcd5007f4de2cab570647756b8744b066877e Mon Sep 17 00:00:00 2001 From: versx Date: Tue, 22 Nov 2022 17:38:56 -0800 Subject: [PATCH 1/2] Change alarm raid level min/max filters to list of levels --- examples/filters/default.json | 6 ++--- examples/filters/ex_raids.json | 6 ++--- examples/filters/legendary_raids.json | 6 ++--- examples/filters/mawile_raids.json | 3 +-- examples/filters/mega_raids.json | 6 ++--- examples/filters/raids.json | 6 ++--- examples/filters/shinx_raids.json | 3 +-- examples/filters/shiny_raids.json | 3 +-- examples/filters/ultra_beast_raids.json | 10 +++---- src/Defaults.cs | 9 +++++++ src/Services/Alarms/AlarmControllerService.cs | 4 +-- .../Models/IWebhookFilterPokemonDetails.cs | 6 ++--- .../Alarms/Filters/Models/WebhookFilterEgg.cs | 21 +++++++-------- .../Filters/Models/WebhookFilterPokemon.cs | 8 +++--- .../Filters/Models/WebhookFilterRaid.cs | 27 +++++++++---------- static/data/defaults.json | 2 ++ test/UnitTest1.cs | 8 +++--- 17 files changed, 62 insertions(+), 72 deletions(-) diff --git a/examples/filters/default.json b/examples/filters/default.json index bfa636cd..c51a3e60 100644 --- a/examples/filters/default.json +++ b/examples/filters/default.json @@ -57,8 +57,7 @@ "eggs": { "enabled": true, // Filter is enabled - "min_lvl": 1, // Minimum egg level to send - "max_lvl": 8, // Maximum egg level to send + "levels": [1, 2, 3, 4, 5, 6, 7, 8], // Raid levels to send "only_ex": false, // Only send ex-eligible raids. "team": "All", // All, Valor, Mystic, Instinct, Neutral "power_level": { @@ -74,8 +73,7 @@ "pokemon": [], // Raid bosses to include or none for all. "forms": ["Alola","Galar"], // List of forms for the filter or empty for all "costumes": ["Detective","Holiday"], // List of costumes for the filter or empty for all - "min_lvl": 1, // Minimum raid level to send - "max_lvl": 8, // Maximum raid level to send + "levels": [1, 2, 3, 4, 5, 6, 7, 8], // Raid levels to send "type": "Include", // Include or Exclude the `pokemon` list "only_ex": false, // Only send ex-eligible raids. "team": "All", // All, Valor, Mystic, Instinct, Nuetral diff --git a/examples/filters/ex_raids.json b/examples/filters/ex_raids.json index fa0d3b11..674ac31a 100644 --- a/examples/filters/ex_raids.json +++ b/examples/filters/ex_raids.json @@ -2,15 +2,13 @@ "eggs": { "enabled": true, - "min_lvl": 1, - "max_lvl": 8, + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "only_ex": true }, "raids": { "enabled": true, - "min_lvl": 1, - "max_lvl": 8, + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "pokemon": [], "type": "Include", "only_ex": true, diff --git a/examples/filters/legendary_raids.json b/examples/filters/legendary_raids.json index 7758f7df..790f83ee 100644 --- a/examples/filters/legendary_raids.json +++ b/examples/filters/legendary_raids.json @@ -2,14 +2,12 @@ "eggs": { "enabled": true, - "min_lvl": 5, - "max_lvl": 5 + "levels": [5, 7, 8] }, "raids": { "enabled": true, - "min_lvl": 5, - "max_lvl": 5, + "levels": [5, 7, 8], "pokemon": [], "type": "Include", "ignore_missing": false diff --git a/examples/filters/mawile_raids.json b/examples/filters/mawile_raids.json index f0a2146b..ecbe7092 100644 --- a/examples/filters/mawile_raids.json +++ b/examples/filters/mawile_raids.json @@ -2,8 +2,7 @@ "raids": { "enabled": true, - "min_lvl": 1, - "max_lvl": 5, + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "pokemon": [303], "type": "Include", "onlyEx": false, diff --git a/examples/filters/mega_raids.json b/examples/filters/mega_raids.json index 248c3f80..4990e082 100644 --- a/examples/filters/mega_raids.json +++ b/examples/filters/mega_raids.json @@ -2,14 +2,12 @@ "eggs": { "enabled": true, - "min_lvl": 6, - "max_lvl": 6 + "levels": [6] }, "raids": { "enabled": true, - "min_lvl": 6, - "max_lvl": 6, + "levels": [6], "pokemon": [], "type": "Include", "ignore_missing": false diff --git a/examples/filters/raids.json b/examples/filters/raids.json index ae43b25d..896dc43b 100644 --- a/examples/filters/raids.json +++ b/examples/filters/raids.json @@ -2,14 +2,12 @@ "eggs": { "enabled": true, - "min_lvl": 1, - "max_lvl": 4 + "levels": [1, 2, 3, 4] }, "raids": { "enabled": true, - "min_lvl": 1, - "max_lvl": 4, + "levels": [1, 2, 3, 4], "pokemon": [], "type": "Include", "ignore_missing": false diff --git a/examples/filters/shinx_raids.json b/examples/filters/shinx_raids.json index c3767757..46fc3e00 100644 --- a/examples/filters/shinx_raids.json +++ b/examples/filters/shinx_raids.json @@ -2,8 +2,7 @@ "raids": { "enabled": true, - "min_lvl": 1, - "max_lvl": 5, + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "pokemon": [403], "type": "Include", "only_ex": false, diff --git a/examples/filters/shiny_raids.json b/examples/filters/shiny_raids.json index aa604884..d04ccfd6 100644 --- a/examples/filters/shiny_raids.json +++ b/examples/filters/shiny_raids.json @@ -2,8 +2,7 @@ "raids": { "enabled": true, - "min_lvl": 1, - "max_lvl": 8, + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "pokemon": [1,4,7,10,25,26,27,32,58,74,77,81,88,90,92,96,98,104,105,127,129,133,138,140,142,144,145,146,147,152,155,158,177,179,191,198,200,204,209,225,228,249,250,261,278,296,302,303,307,315,320,333,353,355,359,361,370,374,403,425], "type": "Include", "only_ex": false, diff --git a/examples/filters/ultra_beast_raids.json b/examples/filters/ultra_beast_raids.json index 4da094a0..3856fd39 100644 --- a/examples/filters/ultra_beast_raids.json +++ b/examples/filters/ultra_beast_raids.json @@ -2,18 +2,16 @@ "eggs": { "enabled": true, - "min_lvl": 7, - "max_lvl": 8, - "only_ex": true + "levels": [7, 8], + "only_ex": false }, "raids": { "enabled": true, - "min_lvl": 7, - "max_lvl": 8, + "levels": [7, 8], "pokemon": [], "type": "Include", - "only_ex": true, + "only_ex": false, "ignore_missing": false } } \ No newline at end of file diff --git a/src/Defaults.cs b/src/Defaults.cs index 86deaf33..a6591018 100644 --- a/src/Defaults.cs +++ b/src/Defaults.cs @@ -31,6 +31,15 @@ public class Defaults [JsonPropertyName("pvp")] public IReadOnlyDictionary Pvp { get; set; } + + // Default raid/egg settings + [JsonPropertyName("min_raid_level")] + public ushort MinimumRaidLevel { get; set; } + + [JsonPropertyName("max_raid_level")] + public ushort MaximumRaidLevel { get; set; } + + // Webhook and subscription queue settings [JsonPropertyName("max_queue_batch_size")] public ushort MaximumQueueBatchSize { get; set; } diff --git a/src/Services/Alarms/AlarmControllerService.cs b/src/Services/Alarms/AlarmControllerService.cs index fa5a3878..2ef3e01b 100644 --- a/src/Services/Alarms/AlarmControllerService.cs +++ b/src/Services/Alarms/AlarmControllerService.cs @@ -248,7 +248,7 @@ public void ProcessRaidAlarms(RaidData raid) continue; } - if (!(raid.Level >= alarm.Filters.Eggs.MinimumLevel && raid.Level <= alarm.Filters.Eggs.MaximumLevel)) + if (!alarm.Filters.Eggs.Levels.Contains(raid.Level)) { //_logger.LogDebug($"[{alarm.Name}] [{geofence.Name}] Skipping level {raid.Level} raid egg: '{raid.Level}' does not meet the MinimumLevel={alarm.Filters.Eggs.MinimumLevel} and MaximumLevel={alarm.Filters.Eggs.MaximumLevel} filters."); continue; @@ -283,7 +283,7 @@ public void ProcessRaidAlarms(RaidData raid) continue; } - if (!(raid.Level >= alarm.Filters.Raids.MinimumLevel && raid.Level <= alarm.Filters.Raids.MaximumLevel)) + if (!alarm.Filters.Raids.Levels.Contains(raid.Level)) { //_logger.LogDebug($"[{alarm.Name}] [{geofence.Name}] Skipping level {raid.Level} raid {raid.PokemonId}: '{raid.Level}' does not meet the MinimumLevel={alarm.Filters.Raids.MinimumLevel} and MaximumLevel={alarm.Filters.Raids.MaximumLevel} filters."); continue; diff --git a/src/Services/Alarms/Filters/Models/IWebhookFilterPokemonDetails.cs b/src/Services/Alarms/Filters/Models/IWebhookFilterPokemonDetails.cs index 17a48413..526ee4da 100644 --- a/src/Services/Alarms/Filters/Models/IWebhookFilterPokemonDetails.cs +++ b/src/Services/Alarms/Filters/Models/IWebhookFilterPokemonDetails.cs @@ -4,11 +4,11 @@ public interface IWebhookFilterPokemonDetails { - List Pokemon { get; } + IReadOnlyList Pokemon { get; } - List Forms { get; } + IReadOnlyList Forms { get; } - List Costumes { get; } + IReadOnlyList Costumes { get; } FilterType FilterType { get; } } diff --git a/src/Services/Alarms/Filters/Models/WebhookFilterEgg.cs b/src/Services/Alarms/Filters/Models/WebhookFilterEgg.cs index 54efa847..01d3553e 100644 --- a/src/Services/Alarms/Filters/Models/WebhookFilterEgg.cs +++ b/src/Services/Alarms/Filters/Models/WebhookFilterEgg.cs @@ -1,5 +1,8 @@ namespace WhMgr.Services.Alarms.Filters.Models { + using System; + using System.Collections.Generic; + using System.Linq; using System.Text.Json.Serialization; using WhMgr.Common; @@ -16,16 +19,10 @@ public class WebhookFilterEgg public bool Enabled { get; set; } /// - /// Minimum raid egg level + /// List of raid egg levels /// - [JsonPropertyName("min_lvl")] - public uint MinimumLevel { get; set; } - - /// - /// Maximum raid egg level - /// - [JsonPropertyName("max_lvl")] - public uint MaximumLevel { get; set; } + [JsonPropertyName("levels")] + public IReadOnlyList Levels { get; set; } /// /// Only ex-eligible raids @@ -50,9 +47,9 @@ public class WebhookFilterEgg /// public WebhookFilterEgg() { - MinimumLevel = 1; - MaximumLevel = 8; - + Levels = Enumerable.Range(Strings.Defaults.MinimumRaidLevel, Strings.Defaults.MaximumRaidLevel) + .Select(Convert.ToUInt16) + .ToList(); Team = PokemonTeam.All; } } diff --git a/src/Services/Alarms/Filters/Models/WebhookFilterPokemon.cs b/src/Services/Alarms/Filters/Models/WebhookFilterPokemon.cs index 06f4d8d4..26476f46 100644 --- a/src/Services/Alarms/Filters/Models/WebhookFilterPokemon.cs +++ b/src/Services/Alarms/Filters/Models/WebhookFilterPokemon.cs @@ -20,19 +20,19 @@ public class WebhookFilterPokemon : IWebhookFilterPokemonDetails /// Gets or sets the list of pokemon pokedex IDs to filter against /// [JsonPropertyName("pokemon")] - public List Pokemon { get; set; } + public IReadOnlyList Pokemon { get; set; } /// /// Gets or sets the list of pokemon Form strings to filter against /// [JsonPropertyName("forms")] - public List Forms { get; set; } + public IReadOnlyList Forms { get; set; } /// /// Gets or sets the list of Pokemon costume strings to filter against /// [JsonPropertyName("costumes")] - public List Costumes { get; set; } + public IReadOnlyList Costumes { get; set; } /// /// Gets or sets the minimum IV value to report @@ -86,7 +86,7 @@ public class WebhookFilterPokemon : IWebhookFilterPokemonDetails /// Gets or sets the Pokemon eligible PvP ranking filtering /// [JsonPropertyName("pvp")] - public Dictionary Pvp { get; set; } + public IReadOnlyDictionary Pvp { get; set; } /// /// Gets or sets a value determining if webhook Pokemon filter has PvP ranking filters diff --git a/src/Services/Alarms/Filters/Models/WebhookFilterRaid.cs b/src/Services/Alarms/Filters/Models/WebhookFilterRaid.cs index d87024e9..c48f27d5 100644 --- a/src/Services/Alarms/Filters/Models/WebhookFilterRaid.cs +++ b/src/Services/Alarms/Filters/Models/WebhookFilterRaid.cs @@ -1,6 +1,8 @@ namespace WhMgr.Services.Alarms.Filters.Models { + using System; using System.Collections.Generic; + using System.Linq; using System.Text.Json.Serialization; using WhMgr.Common; @@ -17,34 +19,28 @@ public class WebhookFilterRaid : IWebhookFilterPokemonDetails public bool Enabled { get; set; } /// - /// Gets or sets the minimum raid level + /// List of raid levels /// - [JsonPropertyName("min_lvl")] - public uint MinimumLevel { get; set; } - - /// - /// Gets or sets the maximum raid level - /// - [JsonPropertyName("max_lvl")] - public uint MaximumLevel { get; set; } + [JsonPropertyName("levels")] + public IReadOnlyList Levels { get; set; } /// /// Gets or sets the Raid boss pokedex ID list to filter against /// [JsonPropertyName("pokemon")] - public List Pokemon { get; set; } + public IReadOnlyList Pokemon { get; set; } /// /// Gets or sets the list of Raid Boss Pokemon Form strings to filter against /// [JsonPropertyName("forms")] - public List Forms { get; set; } + public IReadOnlyList Forms { get; set; } /// /// Gets or sets the list of Raid Boss Pokemon costume strings to filter against /// [JsonPropertyName("costumes")] - public List Costumes { get; set; } + public IReadOnlyList Costumes { get; set; } /// /// Gets or sets the Raid boss filter type @@ -77,15 +73,16 @@ public class WebhookFilterRaid : IWebhookFilterPokemonDetails public bool IgnoreMissing { get; set; } /// - /// Instantiate a new class + /// Instantiate a new class /// public WebhookFilterRaid() { Pokemon = new List(); Forms = new List(); Costumes = new List(); - MinimumLevel = 1; - MaximumLevel = 8; + Levels = Enumerable.Range(Strings.Defaults.MinimumRaidLevel, Strings.Defaults.MaximumRaidLevel) + .Select(Convert.ToUInt16) + .ToList(); Team = PokemonTeam.All; } } diff --git a/static/data/defaults.json b/static/data/defaults.json index 3a99bea6..a02eb6b5 100644 --- a/static/data/defaults.json +++ b/static/data/defaults.json @@ -31,6 +31,8 @@ "max_league_cp": 2500, } }, + "min_raid_level": 1, + "max_raid_level": 8, "max_queue_batch_size": 25, "max_queue_size_warning": 50, "max_queue_capacity": 4096, diff --git a/test/UnitTest1.cs b/test/UnitTest1.cs index 4a57780b..6b7257f9 100644 --- a/test/UnitTest1.cs +++ b/test/UnitTest1.cs @@ -2,11 +2,10 @@ { using System; using System.IO; - + using System.Linq; using NUnit.Framework; using WhMgr.Services; - using WhMgr.Services.Subscriptions.Models; using WhMgr.Utilities; [TestFixture] @@ -23,9 +22,10 @@ public void Setup() } [Test] - public void Test1() + public void Test_RaidLevel_Generate() { - Assert.Pass(); + var levels = Enumerable.Range(1, 8).Select(Convert.ToUInt16).ToList(); + Assert.IsTrue(levels.Count == 8); } [TestCase] From 008742464cd8a897a1afa356fd692bb43dbd4c95 Mon Sep 17 00:00:00 2001 From: versx Date: Tue, 22 Nov 2022 17:45:15 -0800 Subject: [PATCH 2/2] fix spacing with example raid filters --- examples/filters/ex_raids.json | 4 ++-- examples/filters/legendary_raids.json | 4 ++-- examples/filters/mawile_raids.json | 2 +- examples/filters/mega_raids.json | 4 ++-- examples/filters/raids.json | 4 ++-- examples/filters/shinx_raids.json | 2 +- examples/filters/shiny_raids.json | 2 +- examples/filters/ultra_beast_raids.json | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/filters/ex_raids.json b/examples/filters/ex_raids.json index 674ac31a..b370f905 100644 --- a/examples/filters/ex_raids.json +++ b/examples/filters/ex_raids.json @@ -2,13 +2,13 @@ "eggs": { "enabled": true, - "levels": [1, 2, 3, 4, 5, 6, 7, 8], + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "only_ex": true }, "raids": { "enabled": true, - "levels": [1, 2, 3, 4, 5, 6, 7, 8], + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "pokemon": [], "type": "Include", "only_ex": true, diff --git a/examples/filters/legendary_raids.json b/examples/filters/legendary_raids.json index 790f83ee..6eb10e40 100644 --- a/examples/filters/legendary_raids.json +++ b/examples/filters/legendary_raids.json @@ -2,12 +2,12 @@ "eggs": { "enabled": true, - "levels": [5, 7, 8] + "levels": [5, 7, 8] }, "raids": { "enabled": true, - "levels": [5, 7, 8], + "levels": [5, 7, 8], "pokemon": [], "type": "Include", "ignore_missing": false diff --git a/examples/filters/mawile_raids.json b/examples/filters/mawile_raids.json index ecbe7092..89e0c63c 100644 --- a/examples/filters/mawile_raids.json +++ b/examples/filters/mawile_raids.json @@ -2,7 +2,7 @@ "raids": { "enabled": true, - "levels": [1, 2, 3, 4, 5, 6, 7, 8], + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "pokemon": [303], "type": "Include", "onlyEx": false, diff --git a/examples/filters/mega_raids.json b/examples/filters/mega_raids.json index 4990e082..26af1271 100644 --- a/examples/filters/mega_raids.json +++ b/examples/filters/mega_raids.json @@ -2,12 +2,12 @@ "eggs": { "enabled": true, - "levels": [6] + "levels": [6] }, "raids": { "enabled": true, - "levels": [6], + "levels": [6], "pokemon": [], "type": "Include", "ignore_missing": false diff --git a/examples/filters/raids.json b/examples/filters/raids.json index 896dc43b..b964ada6 100644 --- a/examples/filters/raids.json +++ b/examples/filters/raids.json @@ -2,12 +2,12 @@ "eggs": { "enabled": true, - "levels": [1, 2, 3, 4] + "levels": [1, 2, 3, 4] }, "raids": { "enabled": true, - "levels": [1, 2, 3, 4], + "levels": [1, 2, 3, 4], "pokemon": [], "type": "Include", "ignore_missing": false diff --git a/examples/filters/shinx_raids.json b/examples/filters/shinx_raids.json index 46fc3e00..86eccec3 100644 --- a/examples/filters/shinx_raids.json +++ b/examples/filters/shinx_raids.json @@ -2,7 +2,7 @@ "raids": { "enabled": true, - "levels": [1, 2, 3, 4, 5, 6, 7, 8], + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "pokemon": [403], "type": "Include", "only_ex": false, diff --git a/examples/filters/shiny_raids.json b/examples/filters/shiny_raids.json index d04ccfd6..24f13791 100644 --- a/examples/filters/shiny_raids.json +++ b/examples/filters/shiny_raids.json @@ -2,7 +2,7 @@ "raids": { "enabled": true, - "levels": [1, 2, 3, 4, 5, 6, 7, 8], + "levels": [1, 2, 3, 4, 5, 6, 7, 8], "pokemon": [1,4,7,10,25,26,27,32,58,74,77,81,88,90,92,96,98,104,105,127,129,133,138,140,142,144,145,146,147,152,155,158,177,179,191,198,200,204,209,225,228,249,250,261,278,296,302,303,307,315,320,333,353,355,359,361,370,374,403,425], "type": "Include", "only_ex": false, diff --git a/examples/filters/ultra_beast_raids.json b/examples/filters/ultra_beast_raids.json index 3856fd39..23d0f555 100644 --- a/examples/filters/ultra_beast_raids.json +++ b/examples/filters/ultra_beast_raids.json @@ -2,13 +2,13 @@ "eggs": { "enabled": true, - "levels": [7, 8], + "levels": [7, 8], "only_ex": false }, "raids": { "enabled": true, - "levels": [7, 8], + "levels": [7, 8], "pokemon": [], "type": "Include", "only_ex": false,