From a600618d3de91361b086aeb753e29411adf4c1bb Mon Sep 17 00:00:00 2001 From: ExcuseMi Date: Fri, 26 Aug 2016 02:09:40 +0200 Subject: [PATCH] Added a minimum IV filter --- PogoLocationFeeder.GUI/MainWindow.xaml | 2 +- .../ViewModels/MainWindowViewModel.cs | 4 +++- .../Views/SettingsView.xaml | 6 +++++- PogoLocationFeeder/Client/Filter.cs | 1 + PogoLocationFeeder/Client/FilterFactory.cs | 1 + PogoLocationFeeder/Config/Settings.cs | 5 +++++ PogoLocationFeeder/Helper/SniperInfoFilter.cs | 11 +++++++--- PogoLocationFeeder/Server/PogoServer.cs | 20 ++++++++++++------- .../Server/ServerUploadFilter.cs | 15 +++++++++++--- .../Server/ServerUploadFilterFactory.cs | 2 +- 10 files changed, 50 insertions(+), 17 deletions(-) diff --git a/PogoLocationFeeder.GUI/MainWindow.xaml b/PogoLocationFeeder.GUI/MainWindow.xaml index d334632..4636ea4 100644 --- a/PogoLocationFeeder.GUI/MainWindow.xaml +++ b/PogoLocationFeeder.GUI/MainWindow.xaml @@ -10,7 +10,7 @@ BorderBrush="{DynamicResource AccentColorBrush}" BorderThickness="1" WindowStartupLocation="CenterScreen" - Title="Location Feeder" MinHeight="500" MinWidth="800" Height="650" Width="850" + Title="Location Feeder" MinHeight="700" MinWidth="800" Height="700" Width="850" xmlns:views1="clr-namespace:PogoLocationFeeder.GUI.Views" TitleCaps="False" NonActiveWindowTitleBrush="{DynamicResource HighlightBrush}" diff --git a/PogoLocationFeeder.GUI/ViewModels/MainWindowViewModel.cs b/PogoLocationFeeder.GUI/ViewModels/MainWindowViewModel.cs index 0f3daeb..b2a64c7 100644 --- a/PogoLocationFeeder.GUI/ViewModels/MainWindowViewModel.cs +++ b/PogoLocationFeeder.GUI/ViewModels/MainWindowViewModel.cs @@ -135,7 +135,7 @@ public MainWindowViewModel() public bool UseGeoLocationBoundsFilter { get; set; } public LatLngBounds GeoLocationBounds { get; set; } public LatLngBounds LocationBoundsSettingToSave { get; set; } - + public double MinimumIV { get; set; } = 0.0; public PokemonFilterModel SelectedPokemonFilter { get; set; } public PokemonFilterModel SelectedPokemonFiltered { get; set; } public int IndexPokemonToFilter { get; set; } @@ -213,6 +213,7 @@ public void ShowSettings() VerifiedOnly = GlobalSettings.VerifiedOnly; RemoveMinutes = GlobalSettings.RemoveAfter.ToString(); UseFilter = GlobalSettings.UseFilter; + MinimumIV = GlobalSettings.MinimumIV; UseGeoLocationBoundsFilter = GlobalSettings.UseGeoLocationBoundsFilter; GeoLocationBounds = GlobalSettings.GeoLocationBounds; AppThemeText = GlobalSettings.AppTheme; @@ -239,6 +240,7 @@ public void SaveClick() GlobalSettings.VerifyOnSkiplagged = UseSkiplagged; GlobalSettings.VerifiedOnly = VerifiedOnly; GlobalSettings.UseFilter = UseFilter; + GlobalSettings.MinimumIV = MinimumIV; GlobalSettings.UseGeoLocationBoundsFilter = UseGeoLocationBoundsFilter; GlobalSettings.GeoLocationBounds = GeoLocationBounds; GlobalSettings.AppTheme = AppThemeText; diff --git a/PogoLocationFeeder.GUI/Views/SettingsView.xaml b/PogoLocationFeeder.GUI/Views/SettingsView.xaml index 92a09e5..8b4568e 100644 --- a/PogoLocationFeeder.GUI/Views/SettingsView.xaml +++ b/PogoLocationFeeder.GUI/Views/SettingsView.xaml @@ -27,6 +27,8 @@ + + @@ -123,8 +125,10 @@ + Minimum IV + - + \ No newline at end of file diff --git a/PogoLocationFeeder/Client/Filter.cs b/PogoLocationFeeder/Client/Filter.cs index 87b8bbe..8c12c0d 100644 --- a/PogoLocationFeeder/Client/Filter.cs +++ b/PogoLocationFeeder/Client/Filter.cs @@ -27,6 +27,7 @@ public class Filter public bool VerifiedOnly { get; set; } public string Version { get; set; } public LatLngBounds AreaBounds; + public double MinimumIV { get; set; } = 0.0; } public class Channel diff --git a/PogoLocationFeeder/Client/FilterFactory.cs b/PogoLocationFeeder/Client/FilterFactory.cs index 04eec0c..6094bb6 100644 --- a/PogoLocationFeeder/Client/FilterFactory.cs +++ b/PogoLocationFeeder/Client/FilterFactory.cs @@ -77,6 +77,7 @@ public static Filter Create(List discordChannels = null) filter.VerifiedOnly = GlobalSettings.VerifiedOnly; filter.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); filter.AreaBounds = GlobalSettings.UseGeoLocationBoundsFilter ? GlobalSettings.GeoLocationBounds : null; + filter.MinimumIV = GlobalSettings.MinimumIV; return filter; } } diff --git a/PogoLocationFeeder/Config/Settings.cs b/PogoLocationFeeder/Config/Settings.cs index a93c213..14f887d 100644 --- a/PogoLocationFeeder/Config/Settings.cs +++ b/PogoLocationFeeder/Config/Settings.cs @@ -49,6 +49,7 @@ public class GlobalSettings public static bool UsePokeSnipe = true; public static bool UseFilter = true; public static bool UseGeoLocationBoundsFilter = false; + public static double MinimumIV = 0.0; public static LatLngBounds GeoLocationBounds = new LatLngBounds(new GeoCoordinates(40.71461026176555, -74.033173578125), new GeoCoordinates(40.750381950874413, -73.981846826416017)); public static string AppTheme = "Dark"; public static bool IsServer = false; @@ -110,6 +111,7 @@ public static GlobalSettings Load() ShareBotCaptures = set.ShareBotCaptures; BotWebSocketPorts = set.BotWebSocketPorts; VerifiedOnly = set.VerifiedOnly; + MinimumIV = set.MinimumIV; } else { @@ -269,6 +271,9 @@ public class SettingsToSave [DefaultValue(true)] [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public bool VerifiedOnly = GlobalSettings.VerifiedOnly; + [DefaultValue(0.0)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + public double MinimumIV = GlobalSettings.MinimumIV; } } diff --git a/PogoLocationFeeder/Helper/SniperInfoFilter.cs b/PogoLocationFeeder/Helper/SniperInfoFilter.cs index af86769..55afdbd 100644 --- a/PogoLocationFeeder/Helper/SniperInfoFilter.cs +++ b/PogoLocationFeeder/Helper/SniperInfoFilter.cs @@ -16,12 +16,12 @@ internal static List FilterUnmanaged(List sniperInfos, F var pokemonIds = PokemonFilterParser.ParseBinary(filter.Pokemon); var channels = filter.Channels; var areaBounds = filter.AreaBounds; - + var minimumIV = filter.MinimumIV; return sniperInfos.Where( - s => Matches(s, pokemonIds, verifiedOnly, channels, areaBounds)).ToList(); + s => Matches(s, pokemonIds, verifiedOnly, channels, areaBounds, minimumIV)).ToList(); } - private static bool Matches(SniperInfo sniperInfo, List pokemonIds, bool verifiedOnly, List channels, LatLngBounds areaBounds ) + private static bool Matches(SniperInfo sniperInfo, List pokemonIds, bool verifiedOnly, List channels, LatLngBounds areaBounds, double minimumIV ) { if (!pokemonIds.Contains(sniperInfo.Id)) { @@ -43,6 +43,11 @@ private static bool Matches(SniperInfo sniperInfo, List pokemonIds, Log.Trace($"Skipped {sniperInfo} because the lat & long isn't the areabounds {areaBounds}"); return false; } + if (minimumIV > sniperInfo.IV) + { + Log.Trace($"Skipped {sniperInfo} because the IV was lower than {minimumIV}"); + return false; + } return true; } diff --git a/PogoLocationFeeder/Server/PogoServer.cs b/PogoLocationFeeder/Server/PogoServer.cs index 6f55015..2b3ede5 100644 --- a/PogoLocationFeeder/Server/PogoServer.cs +++ b/PogoLocationFeeder/Server/PogoServer.cs @@ -36,8 +36,7 @@ public class PogoServer private WebSocketServer _webSocketServer; private readonly SniperInfoRepository _serverRepository; private readonly SniperInfoRepositoryManager _sniperInfoRepositoryManager; - private List _pokemonIds; - + private ServerUploadFilter _serverUploadFilter; public PogoServer() { _serverRepository = new SniperInfoRepository(); @@ -59,10 +58,13 @@ public void Start() _webSocketServer.NewMessageReceived += new SessionHandler(socketServer_NewMessageReceived); _webSocketServer.NewSessionConnected += socketServer_NewSessionConnected; _webSocketServer.SessionClosed += socketServer_SessionClosed; - _pokemonIds = GlobalSettings.UseFilter - ? PokemonParser.ParsePokemons(new List(GlobalSettings.PokekomsToFeedFilter)) - : Enum.GetValues(typeof(PokemonId)).Cast().ToList(); + UpdateTitle(); + var pokemonIds = GlobalSettings.UseFilter +? PokemonParser.ParsePokemons(new List(GlobalSettings.PokekomsToFeedFilter)) +: Enum.GetValues(typeof(PokemonId)).Cast().ToList(); + _serverUploadFilter = ServerUploadFilterFactory.Create(pokemonIds); + } private void UpdateTitle() @@ -73,7 +75,7 @@ private void UpdateTitle() private void socketServer_NewSessionConnected(WebSocketSession session) { - var uploadFilter = JsonConvert.SerializeObject(ServerUploadFilterFactory.Create(_pokemonIds)); + var uploadFilter = JsonConvert.SerializeObject(_serverUploadFilter); session.Send($"{GetEpoch()}:Hello Darkness my old friend.:{uploadFilter}"); Log.Info($"[{_webSocketServer.SessionCount}:{session.SessionID}] Session started"); UpdateTitle(); @@ -99,10 +101,14 @@ private void socketServer_NewMessageReceived(WebSocketSession session, string va { foreach (SniperInfo sniperInfo in sniperInfos) { - if (_pokemonIds == null || _pokemonIds.Contains(sniperInfo.Id)) + if (_serverUploadFilter.Matches(sniperInfo)) { OnReceivedViaClients(sniperInfo); } + else + { + Log.Trace($"Not allowing upload of {sniperInfo} but it doesn't match the upload filter"); + } } } } diff --git a/PogoLocationFeeder/Server/ServerUploadFilter.cs b/PogoLocationFeeder/Server/ServerUploadFilter.cs index acc12b7..9d787a8 100644 --- a/PogoLocationFeeder/Server/ServerUploadFilter.cs +++ b/PogoLocationFeeder/Server/ServerUploadFilter.cs @@ -30,15 +30,24 @@ public class ServerUploadFilter { public string Pokemon { get; set; } public LatLngBounds AreaBounds { get; set; } + public double MinimumIV { get; set; } = 0.0; public bool Matches(SniperInfo sniperInfo) { var pokemonIds = PokemonFilterParser.ParseBinary(Pokemon); - if (pokemonIds == null || pokemonIds.Contains(sniperInfo.Id)) + if (pokemonIds != null && !pokemonIds.Contains(sniperInfo.Id)) { - return AreaBounds == null || AreaBounds.Intersects(sniperInfo.Latitude, sniperInfo.Longitude); + return false; } - return false; + if (AreaBounds != null && !AreaBounds.Intersects(sniperInfo.Latitude, sniperInfo.Longitude)) + { + return false; + } + if (MinimumIV > sniperInfo.IV) + { + return false; + } + return true; } } } diff --git a/PogoLocationFeeder/Server/ServerUploadFilterFactory.cs b/PogoLocationFeeder/Server/ServerUploadFilterFactory.cs index e7b17f5..349f910 100644 --- a/PogoLocationFeeder/Server/ServerUploadFilterFactory.cs +++ b/PogoLocationFeeder/Server/ServerUploadFilterFactory.cs @@ -32,7 +32,7 @@ public static ServerUploadFilter Create(List pokemon) serverUploadFilter.Pokemon = pokemonsBinary; serverUploadFilter.AreaBounds = GlobalSettings.UseGeoLocationBoundsFilter ? GlobalSettings.GeoLocationBounds : null; - + serverUploadFilter.MinimumIV = GlobalSettings.MinimumIV; return serverUploadFilter; } }