diff --git a/docs/config/filters.md b/docs/config/filters.md index 9a78d191..177b3794 100644 --- a/docs/config/filters.md +++ b/docs/config/filters.md @@ -25,7 +25,7 @@ Filters allow you to narrow down what is reported. All filters are optional and // depending on the interested ranks. "pvp": { // Little league rank filtering - "little": [{ + "little": { // Minimum rank of #1 for PVP rank stats "min_rank": 1, // Maximum rank of #5 for PVP rank stats @@ -40,28 +40,23 @@ Filters allow you to narrow down what is reported. All filters are optional and "max_percent": 100, // Gender filtering requirement (*, m, or f) "gender": "*" - }], + }, // Great league rank filtering - "great": [{ + "great": { "min_rank": 1, "max_rank": 5, "min_cp": 1400, "max_cp": 1500, "gender": "m" - }], + }, // Ultra league rank filtering - "ultra": [{ + "ultra": { "min_rank": 1, "max_rank": 25, "min_cp": 2400, "max_cp": 2500, "gender": "f" - },{ - "min_rank": 1, - "max_rank": 5, - "min_cp": 2300, - "max_cp": 2400 - }] + } }, "type": "Include", // Include or Exclude the `pokemon` list "is_event": false, // Only send Pokemon checked with event accounts (GoFest, etc) diff --git a/examples/filters/default.json b/examples/filters/default.json index 52dfce03..bfa636cd 100644 --- a/examples/filters/default.json +++ b/examples/filters/default.json @@ -17,7 +17,7 @@ // Add or remove any PVP league filtering keys // depending on the interested ranks // Little league rank filtering - "little": [{ + "little": { // Minimum rank of #1 for PVP rank stats "min_rank": 1, // Maximum rank of #5 for PVP rank stats @@ -34,7 +34,7 @@ "gender": "*" }], // Great league rank filtering - "great": [{ + "great": { "min_rank": 1, "max_rank": 5, "min_cp": 1400, @@ -42,18 +42,13 @@ "gender": "m" }], // Ultra league rank filtering - "ultra": [{ + "ultra": { "min_rank": 1, "max_rank": 25, "min_cp": 2400, "max_cp": 2500, "gender": "f" - },{ - "min_rank": 1, - "max_rank": 5, - "min_cp": 2300, - "max_cp": 2400 - }] + } }, "type": "Include", // Include or Exclude the `pokemon` list "is_event": false, // Only send Pokemon checked with event accounts (GoFest, etc) diff --git a/examples/filters/pvp1500cp.json b/examples/filters/pvp1500cp.json index 594e63c0..0222a18d 100644 --- a/examples/filters/pvp1500cp.json +++ b/examples/filters/pvp1500cp.json @@ -8,13 +8,13 @@ "min_cp": 0, "max_cp": 1500, "pvp": { - "great": [{ + "great": { "min_rank": 1, "max_rank": 25, "min_cp": 1400, "max_cp": 1500, "gender": "*" - }] + } }, "type": "Include", "ignore_missing": true diff --git a/examples/filters/pvp1500cp_rank1.json b/examples/filters/pvp1500cp_rank1.json index 34220ab5..baab3b61 100644 --- a/examples/filters/pvp1500cp_rank1.json +++ b/examples/filters/pvp1500cp_rank1.json @@ -8,13 +8,13 @@ "min_cp": 0, "max_cp": 1500, "pvp": { - "great": [{ + "great": { "min_rank": 1, "max_rank": 1, "min_cp": 1400, "max_cp": 1500, "gender": "*" - }] + } }, "type": "Include", "ignore_missing": true diff --git a/examples/filters/pvp1500cp_rank5.json b/examples/filters/pvp1500cp_rank5.json index 8d15fd77..4befb167 100644 --- a/examples/filters/pvp1500cp_rank5.json +++ b/examples/filters/pvp1500cp_rank5.json @@ -8,13 +8,13 @@ "min_cp": 0, "max_cp": 1500, "pvp": { - "great": [{ + "great": { "min_rank": 1, "max_rank": 5, "min_cp": 1400, "max_cp": 1500, "gender": "*" - }] + } }, "type": "Include", "ignore_missing": true diff --git a/examples/filters/pvp2500cp.json b/examples/filters/pvp2500cp.json index d714709c..c01d7357 100644 --- a/examples/filters/pvp2500cp.json +++ b/examples/filters/pvp2500cp.json @@ -8,13 +8,13 @@ "min_cp": 0, "max_cp": 2500, "pvp": { - "ultra": [{ + "ultra": { "min_rank": 1, "max_rank": 25, "min_cp": 2400, "max_cp": 2500, "gender": "*" - }] + } }, "type": "Include", "ignore_missing": true diff --git a/examples/filters/pvp2500cp_rank1.json b/examples/filters/pvp2500cp_rank1.json index d7778860..7219926c 100644 --- a/examples/filters/pvp2500cp_rank1.json +++ b/examples/filters/pvp2500cp_rank1.json @@ -8,13 +8,13 @@ "min_cp": 0, "max_cp": 2500, "pvp": { - "ultra": [{ + "ultra": { "min_rank": 1, "max_rank": 1, "min_cp": 2400, "max_cp": 2500, "gender": "*" - }] + } }, "type": "Include", "ignore_missing": true diff --git a/examples/filters/pvp2500cp_rank5.json b/examples/filters/pvp2500cp_rank5.json index 79496b2b..1e626876 100644 --- a/examples/filters/pvp2500cp_rank5.json +++ b/examples/filters/pvp2500cp_rank5.json @@ -8,13 +8,13 @@ "min_cp": 0, "max_cp": 2500, "pvp": { - "ultra": [{ + "ultra": { "min_rank": 1, "max_rank": 5, "min_cp": 2400, "max_cp": 2500, "gender": "*" - }] + } }, "type": "Include", "ignore_missing": true diff --git a/examples/filters/pvp500cp.json b/examples/filters/pvp500cp.json index fe751eaf..25cb8c28 100644 --- a/examples/filters/pvp500cp.json +++ b/examples/filters/pvp500cp.json @@ -8,13 +8,13 @@ "min_cp": 0, "max_cp": 500, "pvp": { - "little": [{ + "little": { "max_rank": 25, "min_rank": 1, "min_cp": 450, "max_cp": 500, "gender": "*" - }] + } }, "type": "Include", "ignore_missing": true diff --git a/examples/filters/pvp500cp_rank1.json b/examples/filters/pvp500cp_rank1.json index 7c4f7cca..fe29868a 100644 --- a/examples/filters/pvp500cp_rank1.json +++ b/examples/filters/pvp500cp_rank1.json @@ -8,13 +8,13 @@ "min_cp": 0, "max_cp": 500, "pvp": { - "little": [{ + "little": { "min_rank": 1, "max_rank": 1, "min_cp": 450, "max_cp": 500, "gender": "*" - }] + } }, "type": "Include", "ignore_missing": true diff --git a/examples/filters/pvp500cp_rank5.json b/examples/filters/pvp500cp_rank5.json index c492a115..9b775386 100644 --- a/examples/filters/pvp500cp_rank5.json +++ b/examples/filters/pvp500cp_rank5.json @@ -8,13 +8,13 @@ "min_cp": 0, "max_cp": 500, "pvp": { - "little": [{ + "little": { "min_rank": 1, "max_rank": 5, "min_cp": 450, "max_cp": 500, "gender": "*" - }] + } }, "type": "Include", "ignore_missing": true diff --git a/src/Controllers/AdminApiController.cs b/src/Controllers/AdminApiController.cs index 22492146..6a904ee4 100644 --- a/src/Controllers/AdminApiController.cs +++ b/src/Controllers/AdminApiController.cs @@ -640,14 +640,14 @@ public async Task CreateFilter() var filterJson = dict["filter"].ToString(); var filter = filterJson.FromJson(); - // Save json - var json = filter.ToJson(); var path = Path.Combine(Strings.FiltersFolder, name + ".json"); if (System.IO.File.Exists(path)) { return SendErrorResponse($"Failed to create filter '{name}', filter already exists."); } + // Save json + var json = filter.ToJson(); await WriteDataAsync(path, json); return new JsonResult(new diff --git a/src/Services/Alarms/AlarmControllerService.cs b/src/Services/Alarms/AlarmControllerService.cs index 20079957..604672a9 100644 --- a/src/Services/Alarms/AlarmControllerService.cs +++ b/src/Services/Alarms/AlarmControllerService.cs @@ -121,31 +121,29 @@ public void ProcessPokemonAlarms(PokemonData pokemon) { return false; } - var filterRankings = pvpPokemonFilters[league]; + var filterRanking = pvpPokemonFilters[league]; var pokemonRankings = pokemon.PvpRankings[league]; // Check if any alarm filter matches Pokemon PVP rank for each available league - var result = filterRankings.Exists(filter => - pokemonRankings.Exists(rank => - { - //var percentage = Math.Round(Convert.ToDouble(rank.Percentage) * 100.0, 2); - var matches = - ( - Filters.Filters.MatchesPvPRank(rank.Rank ?? 0, filter.MinimumRank, filter.MaximumRank) - || - Filters.Filters.MatchesPvPRank(rank.CompetitionRank, filter.MinimumRank, filter.MaximumRank) - || - Filters.Filters.MatchesPvPRank(rank.DenseRank, filter.MinimumRank, filter.MaximumRank) - || - Filters.Filters.MatchesPvPRank(rank.OrdinalRank, filter.MinimumRank, filter.MaximumRank) - ) - && - Filters.Filters.MatchesCP((uint)rank.CP, filter.MinimumCP, filter.MaximumCP) - && - Filters.Filters.MatchesGender(rank.Gender, filter.Gender); - // TODO: Reimplement rank product stat percentage filtering (filter.MinimumPercent <= rank.Percentage && filter.MaximumPercent >= rank.Percentage); - return matches; - }) - ); + var result = pokemonRankings.Exists(rank => + { + //var percentage = Math.Round(Convert.ToDouble(rank.Percentage) * 100.0, 2); + var matches = + ( + Filters.Filters.MatchesPvPRank(rank.Rank ?? 0, filterRanking.MinimumRank, filterRanking.MaximumRank) + || + Filters.Filters.MatchesPvPRank(rank.CompetitionRank, filterRanking.MinimumRank, filterRanking.MaximumRank) + || + Filters.Filters.MatchesPvPRank(rank.DenseRank, filterRanking.MinimumRank, filterRanking.MaximumRank) + || + Filters.Filters.MatchesPvPRank(rank.OrdinalRank, filterRanking.MinimumRank, filterRanking.MaximumRank) + ) + && + Filters.Filters.MatchesCP((uint)rank.CP, filterRanking.MinimumCP, filterRanking.MaximumCP) + && + Filters.Filters.MatchesGender(rank.Gender, filterRanking.Gender); + // TODO: Reimplement rank product stat percentage filtering (filter.MinimumPercent <= rank.Percentage && filter.MaximumPercent >= rank.Percentage); + return matches; + }); return result; }) ?? false; diff --git a/src/Services/Alarms/Filters/Models/WebhookFilterPokemon.cs b/src/Services/Alarms/Filters/Models/WebhookFilterPokemon.cs index b6844394..06f4d8d4 100644 --- a/src/Services/Alarms/Filters/Models/WebhookFilterPokemon.cs +++ b/src/Services/Alarms/Filters/Models/WebhookFilterPokemon.cs @@ -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 Dictionary Pvp { get; set; } /// /// Gets or sets a value determining if webhook Pokemon filter has PvP ranking filters @@ -128,7 +128,7 @@ public WebhookFilterPokemon() MaximumCP = 999999; MinimumLevel = 0; MaximumLevel = 100; // Support for when they increase level cap. :wink: - Pvp = new Dictionary>(); + Pvp = new Dictionary(); Gender = '*'; Size = PokemonSize.All; }