private async Task <RaidOcrResult> GetRaidOcrResultAsync(Image <Rgba32> image, RaidImageConfiguration imageConfiguration, int interactiveLimit, FenceConfiguration[] fences = null) { var result = new RaidOcrResult(); var fragmentTypes = Enum.GetValues(typeof(RaidImageFragmentType)).Cast <RaidImageFragmentType>(); //foreach (var type in fragmentTypes) Parallel.ForEach(fragmentTypes, type => { using (var imageFragment = image.Clone(e => e.Crop(imageConfiguration[type]))) { switch (type) { case RaidImageFragmentType.EggTimer: result.EggTimer = GetTimerValue(imageFragment, imageConfiguration, type).Result; break; case RaidImageFragmentType.EggLevel: result.EggLevel = GetEggLevel(imageFragment, imageConfiguration).Result; break; case RaidImageFragmentType.GymName: result.Gym = GetGym(imageFragment, imageConfiguration, fences, interactiveLimit).Result; break; case RaidImageFragmentType.PokemonName: result.Pokemon = GetPokemon(imageFragment, imageConfiguration, interactiveLimit).Result; break; case RaidImageFragmentType.PokemonCp: result.PokemonCp = GetPokemonCp(imageFragment, imageConfiguration).Result; break; case RaidImageFragmentType.RaidTimer: result.RaidTimer = GetTimerValue(imageFragment, imageConfiguration, type).Result; break; } } } ); if (result.PokemonCp.IsSuccess && result.Pokemon.IsSuccess) { if (result.Pokemon.Results.Length > 1) { var pokemonWithCp = result.Pokemon.Results.Where(e => e.Value == 1d || e.Key.Raidboss.Cp == result.PokemonCp.GetFirst()) .Select(e => new KeyValuePair <RaidbossPokemon, double>(e.Key, Math.Max(e.Value * 2, 1))) .ToArray(); if (pokemonWithCp.Length > 0) { result.Pokemon = new OcrResult <RaidbossPokemon>(true, result.Pokemon.OcrValue, pokemonWithCp); } } } return(await Task.FromResult(result)); }
private async Task <ServiceResponse> ReturnTestInformation(RaidOcrResult raidOcrResult) { string message; var gym = raidOcrResult.Gym.GetFirst(); if (raidOcrResult.RaidTimer.IsSuccess) { var timer = raidOcrResult.RaidTimer.GetFirst(); var pokemon = raidOcrResult.Pokemon.GetFirst(); message = $".raids add \"{gym.Name}\" \"{pokemon.Pokemon.Name}\" {string.Concat(timer.Minutes, ":", timer.Seconds)}"; } else { var eggLevel = raidOcrResult.EggLevel.GetFirst(); var timer = raidOcrResult.EggTimer.GetFirst(); message = $".raids add \"{gym.Name}\" \"{eggLevel}\" {string.Concat(timer.Minutes, ":", timer.Seconds)}"; } var result = new ServiceResponse(true, message); return(await Task.FromResult(result)); }
private async Task <ServiceResponse> InteractivePokemonResolve(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, TimeSpan timeLeft, RaidOcrResult raidOcrResult, FenceConfiguration[] fences, int interactiveLimit) { if (UseInteractiveMode(raidOcrResult.Pokemon)) { var pokemonCallbacks = InteractiveServiceHelper.GenericCreateCallbackAsync(interactiveLimit, (selectedPokemon) => InteractiveGymResolve(textResource, requestStartInUtc, userZone, timeLeft, GetRaidbossPokemonById(selectedPokemon, raidOcrResult).Raidboss.Level, GetRaidbossPokemonById(selectedPokemon, raidOcrResult), raidOcrResult, fences, interactiveLimit), pokemon => pokemon.Pokemon.Id, (pokemon, list) => Task.FromResult(pokemon.Pokemon.Name), list => LocalizationService.Get(textResource, "Pokemon_Errors_ToManyFound", list.Count, raidOcrResult.Pokemon.OcrValue, interactiveLimit, "raidboss-"), list => LocalizationService.Get(textResource, "Pokemon_Errors_InteractiveMode", list.Count, raidOcrResult.Pokemon.OcrValue, "raidboss-"), raidOcrResult.Pokemon.Results.Select(e => e.Key).ToList()); return(await pokemonCallbacks); } var raidbossPokemon = raidOcrResult.Pokemon.GetFirst(); return(await InteractiveGymResolve(textResource, requestStartInUtc, userZone, timeLeft, raidbossPokemon.Raidboss.Level, raidbossPokemon, raidOcrResult, fences, interactiveLimit)); }
private async Task <ServiceResponse> AddRaidAsync(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, int gymId, int level, RaidbossPokemon raidbossPokemon, TimeSpan timeLeft, RaidOcrResult raidOcrResult, FenceConfiguration[] fences, int interactiveLimit) { IPokemon pokemon = null; IRaidboss raidboss = null; if (raidbossPokemon != null) { pokemon = raidbossPokemon.Pokemon; raidboss = raidbossPokemon.Raidboss; } // aka (Unit)TestMode if (!SaveDebugImages) { return(await RaidService.AddResolveGymAsync(textResource, requestStartInUtc, userZone, gymId, (byte)level, pokemon, raidboss, timeLeft, interactiveLimit, fences)); } else { return(await ReturnTestInformation(raidOcrResult)); } }
private async Task <ServiceResponse> InteractiveGymResolve(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, TimeSpan timeLeft, int level, RaidbossPokemon raidbossPokemon, RaidOcrResult raidOcrResult, FenceConfiguration[] fences, int interactiveLimit) { if (!UseInteractiveMode(raidOcrResult.Gym)) { return(await AddRaidAsync(textResource, requestStartInUtc, userZone, raidOcrResult.Gym.GetFirst().Id, level, raidbossPokemon, timeLeft, raidOcrResult, fences, interactiveLimit)); } if (raidOcrResult.Gym.Results == null || raidOcrResult.Gym.Results.Length == 0) { return(new ServiceResponse(false, LocalizationService.Get(textResource, "Gyms_Errors_NothingFound", raidOcrResult.Gym.OcrValue))); } // If the interactive response limit is reached try to select the all gyms with the same name as from the ocr result var gyms = raidOcrResult.Gym.Results.Select(e => e.Key).ToList(); if (gyms.Count > interactiveLimit) { var ocrString = raidOcrResult.Gym.OcrValue.Trim().ToLowerInvariant(); gyms = gyms.Where(e => e.Name.Trim().ToLowerInvariant() == ocrString).ToList(); // If we didn't found any return to the precious state if (gyms.Count == 0) { gyms = raidOcrResult.Gym.Results.Select(e => e.Key).ToList(); } } var gymCallbacks = InteractiveServiceHelper.GenericCreateCallbackAsync(interactiveLimit, (selectedGym) => AddRaidAsync(textResource, requestStartInUtc, userZone, selectedGym, level, raidbossPokemon, timeLeft, raidOcrResult, fences, interactiveLimit), gym => gym.Id, (gym, list) => GymService.GetGymNameWithAdditionAsync(gym, list), list => LocalizationService.Get(textResource, "Gyms_Errors_ToManyFound", list.Count, raidOcrResult.Gym.OcrValue, interactiveLimit), list => LocalizationService.Get(textResource, "Gyms_Errors_InteractiveMode", list.Count, raidOcrResult.Gym.OcrValue), gyms); return(await gymCallbacks); }
private RaidbossPokemon GetRaidbossPokemonById(int id, RaidOcrResult raidOcrResult) { return(raidOcrResult.Pokemon.Results.Where(e => e.Key.Pokemon.Id == id).Select(e => e.Key).First()); }
private async Task <ServiceResponse> InteractiveGymResolve(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, TimeSpan timeLeft, int level, RaidbossPokemon raidbossPokemon, RaidOcrResult raidOcrResult, FenceConfiguration[] fences, int interactiveLimit) { if (!InteractiveServiceHelper.UseInteractiveMode(raidOcrResult.Gym.Results)) { return(await AddRaidAsync(textResource, requestStartInUtc, userZone, raidOcrResult.Gym.GetFirst().Id, level, raidbossPokemon, timeLeft, raidOcrResult, fences, interactiveLimit)); } if (raidOcrResult.Gym.Results == null || raidOcrResult.Gym.Results.Length == 0) { return(new ServiceResponse(false, LocalizationService.Get(textResource, "Gyms_Errors_NothingFound", raidOcrResult.Gym.OcrValue))); } var gymCallbacks = InteractiveServiceHelper.GenericCreateCallbackAsync(interactiveLimit, (selectedGym) => AddRaidAsync(textResource, requestStartInUtc, userZone, selectedGym, level, raidbossPokemon, timeLeft, raidOcrResult, fences, interactiveLimit), gym => gym.Id, (gym, list) => GymService.GetGymNameWithAdditionAsync(gym, list), list => LocalizationService.Get(textResource, "Gyms_Errors_ToManyFound", list.Count, raidOcrResult.Gym.OcrValue, interactiveLimit), list => LocalizationService.Get(textResource, "Gyms_Errors_InteractiveMode", list.Count, raidOcrResult.Gym.OcrValue), raidOcrResult.Gym.Results.Select(e => e.Key).ToList()); return(await gymCallbacks); }