Giter Club home page Giter Club logo

Comments (7)

TheIronDev avatar TheIronDev commented on June 13, 2024

This exposes a different problem. The search to include descriptions searches for inclusiveness, not an exact match. Another example of this bug being relevant is pokemon #304, Aron (which will provide descriptions for volcarana as well.)

I'm not a python guy, so I'm a little slow in finding the pain point, but I'll submit a PR if I catch it.

from pokeapi.

phalt avatar phalt commented on June 13, 2024

@TheIronDeveloper this is exactly what is causing the issue. It's looking for values with the name of the pokémon in, so Abra will get Kadabra's name because: Kadabra.

It needs some regex magic work instead of a simple icontains

from pokeapi.

shad0wshayd3 avatar shad0wshayd3 commented on June 13, 2024

Line 46 in pokemon/api.py is where that pain point is. I could fix it if I actually knew what was doing what. (My knowledge of django is spotty)

The build_descriptions function passes "name" which is what icontains is looking for within the Description.objects.filter QuerySet. My only problem is not knowing what that QuerySet actually is.
For instance, if that QuerySet is "kadabra_gen_4", the easiest fix would just be to compare length with something like

if (len(str(Description.object.filter))-6) == len(name):
   ds = Description.objects.filter(name__icontains=name)
   lst = []
   ........

And so on. This would cause it so that only Pokemon with names the same length of as what you're looking for (subtracting 6 for the generation tag). Making Abra (4) and Kadabra (7) unable to be matched, while comparing Abra to Aron and Uxie. I figure this will work, but I have no actual means of testing it, since I have no idea what icontains is looking in and I can't get the API working outside of the stuff in dev_data.json.

from pokeapi.

phalt avatar phalt commented on June 13, 2024

This is a good starting point for the filtering: https://docs.djangoproject.com/en/1.8/ref/models/querysets/#id4

And the regex in particular: https://docs.djangoproject.com/en/1.8/ref/models/querysets/#regex

Django knowledge isn't important here, string interpolation is what will solve this. Can you write a regular expression that matches on strings correctly? The name string is always something like this:

"abra_gen_1"
"abra_gen_6"
"kadabra_gen_1"
"kadabra_gen_4"

from pokeapi.

shad0wshayd3 avatar shad0wshayd3 commented on June 13, 2024

So here's a super simple fix to the build_descriptions function. It still uses icontains, but before appending the list, it checks to see if the name matches using the same method I described above, checking to see if the name of the Pokemon it's adding to the list is the same length as the name of the Pokemon it's looking for.

Let me know if this works, and if not I'll try something else.

from pokeapi.

TheIronDev avatar TheIronDev commented on June 13, 2024

I'll need to look into the syntax of icontains, but I'd have to imagine you can do a regex like:

'/^' + name + '/'

from pokeapi.

phalt avatar phalt commented on June 13, 2024

Okay, this is the last thing I will be fixing on V1, all other features requests for V1 are being deprecated and closed.

from pokeapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.