Skip to content

Commit

Permalink
Added a minimum IV filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcuseMi committed Aug 26, 2016
1 parent 88e8970 commit a600618
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion PogoLocationFeeder.GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
4 changes: 3 additions & 1 deletion PogoLocationFeeder.GUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion PogoLocationFeeder.GUI/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<RowDefinition Height="10" />
<RowDefinition Height="30" />
<RowDefinition Height="10" />
<RowDefinition Height="30" />
<RowDefinition Height="10" />
<RowDefinition Height="33" />
<RowDefinition Height="10" />
<RowDefinition Height="33"/>
Expand Down Expand Up @@ -123,8 +125,10 @@
<TextBox VerticalAlignment="Center" Text="{Binding NorthEast.Longitude, Mode=TwoWay}" Margin="10, 0"
PreviewTextInput="DoubleValidationTextBox" Width="100" HorizontalAlignment="Left" />
</StackPanel>
<TextBlock Grid.Row="25" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center">Minimum IV</TextBlock>
<TextBox Grid.Row="25" Grid.Column="3" HorizontalAlignment="Left" Text="{Binding MinimumIV, Mode=TwoWay}" Width="100" PreviewTextInput="NumberValidationTextBox" />

<Button Grid.Row="25" Grid.Column="3" Command="{Binding SaveCommand}">Save Settings</Button>
<Button Grid.Row="27" Grid.Column="3" Command="{Binding SaveCommand}">Save Settings</Button>

</Grid>
</UserControl>
1 change: 1 addition & 0 deletions PogoLocationFeeder/Client/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions PogoLocationFeeder/Client/FilterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static Filter Create(List<DiscordChannels> 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;
}
}
Expand Down
5 changes: 5 additions & 0 deletions PogoLocationFeeder/Config/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,6 +111,7 @@ public static GlobalSettings Load()
ShareBotCaptures = set.ShareBotCaptures;
BotWebSocketPorts = set.BotWebSocketPorts;
VerifiedOnly = set.VerifiedOnly;
MinimumIV = set.MinimumIV;
}
else
{
Expand Down Expand Up @@ -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;

}
}
11 changes: 8 additions & 3 deletions PogoLocationFeeder/Helper/SniperInfoFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ internal static List<SniperInfo> FilterUnmanaged(List<SniperInfo> 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<PokemonId> pokemonIds, bool verifiedOnly, List<Channel> channels, LatLngBounds areaBounds )
private static bool Matches(SniperInfo sniperInfo, List<PokemonId> pokemonIds, bool verifiedOnly, List<Channel> channels, LatLngBounds areaBounds, double minimumIV )
{
if (!pokemonIds.Contains(sniperInfo.Id))
{
Expand All @@ -43,6 +43,11 @@ private static bool Matches(SniperInfo sniperInfo, List<PokemonId> 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;
}

Expand Down
20 changes: 13 additions & 7 deletions PogoLocationFeeder/Server/PogoServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public class PogoServer
private WebSocketServer _webSocketServer;
private readonly SniperInfoRepository _serverRepository;
private readonly SniperInfoRepositoryManager _sniperInfoRepositoryManager;
private List<PokemonId> _pokemonIds;

private ServerUploadFilter _serverUploadFilter;
public PogoServer()
{
_serverRepository = new SniperInfoRepository();
Expand All @@ -59,10 +58,13 @@ public void Start()
_webSocketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(socketServer_NewMessageReceived);
_webSocketServer.NewSessionConnected += socketServer_NewSessionConnected;
_webSocketServer.SessionClosed += socketServer_SessionClosed;
_pokemonIds = GlobalSettings.UseFilter
? PokemonParser.ParsePokemons(new List<string>(GlobalSettings.PokekomsToFeedFilter))
: Enum.GetValues(typeof(PokemonId)).Cast<PokemonId>().ToList();

UpdateTitle();
var pokemonIds = GlobalSettings.UseFilter
? PokemonParser.ParsePokemons(new List<string>(GlobalSettings.PokekomsToFeedFilter))
: Enum.GetValues(typeof(PokemonId)).Cast<PokemonId>().ToList();
_serverUploadFilter = ServerUploadFilterFactory.Create(pokemonIds);

}

private void UpdateTitle()
Expand All @@ -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();
Expand All @@ -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");
}
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions PogoLocationFeeder/Server/ServerUploadFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion PogoLocationFeeder/Server/ServerUploadFilterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static ServerUploadFilter Create(List<PokemonId> pokemon)

serverUploadFilter.Pokemon = pokemonsBinary;
serverUploadFilter.AreaBounds = GlobalSettings.UseGeoLocationBoundsFilter ? GlobalSettings.GeoLocationBounds : null;

serverUploadFilter.MinimumIV = GlobalSettings.MinimumIV;
return serverUploadFilter;
}
}
Expand Down

0 comments on commit a600618

Please sign in to comment.