DFY-NCSU / slash-phase6

Slash is a web application that scrapes the most popular e-commerce websites for the best deals so that you can get the best value for your money!
MIT License
3 stars 3 forks source link

`sort_by` Parameter Not Setting Expected Sort Value in `args['sort']` #12

Closed TheFatBlue closed 1 day ago

TheFatBlue commented 2 days ago

Description: There is an issue in the sorting mechanism within function scrape in src/scraper_mt.py, specifically with the sort_by value in args['sort']. The value of sort_by is not being set to 'pr' as expected when order_by_col == 'price'. This is causing the sorting function to behave incorrectly, impacting the ordering of items in the result list.

Steps to Reproduce:

  1. Set the order_by_col variable to 'price'.
  2. Pass args with the order_by_col condition as a parameter.
  3. Check the value of sort_by within the loop.

Expected Behavior: The sort_by variable in args['sort'] should be set to 'pr' when order_by_col is equal to 'price'.

Observed Behavior: The sort_by value in args['sort'] does not become 'pr' as expected. Instead, it appears to have an unexpected value, which causes the sorting logic to not work as intended.

Impact on Tests: This bug causes the test case test_api_general_sort in tests/test_features.py to fail, as it relies on correct sorting behavior.

Environment:

name: slash
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
dependencies:
  - bzip2=1.0.8=h6c40b1e_6
  - ca-certificates=2024.9.24=hecd8cb5_0
  - libffi=3.4.4=hecd8cb5_1
  - ncurses=6.4=hcec6c5f_0
  - openssl=3.0.15=h46256e1_0
  - pip=24.2=py310hecd8cb5_0
  - python=3.10.15=hce00570_1
  - readline=8.2=hca72f7f_0
  - setuptools=75.1.0=py310hecd8cb5_0
  - sqlite=3.45.3=h6c40b1e_0
  - tk=8.6.14=h4d00af3_0
  - wheel=0.44.0=py310hecd8cb5_0
  - xz=5.4.6=h6c40b1e_1
  - zlib=1.2.13=h4b97444_1
  - pip:
      - altair==4.2.2
      - anyio==3.3.4
      - appnope==0.1.4
      - asgiref==3.6.0
      - astor==0.8.1
      - attrs==23.1.0
      - base58==2.1.1
      - bcrypt==3.2.0
      - beautifulsoup4==4.10.0
      - blinker==1.6.2
      - cachetools==5.3.1
      - certifi==2021.10.8
      - cffi==1.16.0
      - charset-normalizer==2.0.7
      - click==7.1.2
      - currencyconverter==0.17.11
      - ebaysdk==2.2.0
      - ecdsa==0.18.0
      - entrypoints==0.4
      - fastapi==0.70.0
      - gitdb==4.0.10
      - gitpython==3.1.36
      - greenlet==3.0.0
      - h11==0.14.0
      - idna==3.3
      - importlib-metadata==6.8.0
      - jinja2==3.1.2
      - jsonschema==4.19.0
      - jsonschema-specifications==2023.7.1
      - lxml==4.9.3
      - markdown-it-py==3.0.0
      - markupsafe==2.1.3
      - mdurl==0.1.2
      - nest-asyncio==1.5.1
      - numpy==1.26.0
      - packaging==23.1
      - pandas==2.1.0
      - passlib==1.7.4
      - pillow==10.0.1
      - protobuf==3.20.1
      - psycopg2-binary==2.9.3
      - pyarrow==13.0.0
      - pyasn1==0.5.0
      - pycparser==2.21
      - pydantic==1.8.2
      - pydeck==0.8.1b0
      - pygments==2.16.1
      - pymysql==1.0.2
      - pyshorteners==1.0.1
      - python-dateutil==2.8.2
      - python-jose==3.3.0
      - python-multipart==0.0.5
      - pytz==2023.3.post1
      - referencing==0.30.2
      - requests==2.31.0
      - rich==13.6.0
      - rpds-py==0.10.3
      - rsa==4.9
      - six==1.16.0
      - smmap==5.0.0
      - sniffio==1.2.0
      - soupsieve==2.2.1
      - sqlalchemy==1.4.32
      - starlette==0.16.0
      - streamlit==1.27.2
      - tabulate==0.8.9
      - tenacity==8.2.3
      - toml==0.10.2
      - toolz==0.12.0
      - tornado==6.3.3
      - typing-extensions==4.8.0
      - tzdata==2023.3
      - tzlocal==5.0.1
      - urllib3==1.26.7
      - uvicorn==0.15.0
      - validators==0.22.0
      - watchdog==3.0.0
      - zipp==3.17.0

Priority: Medium

TheFatBlue commented 1 day ago

The bug caused by the value of args['sort'] has been solved in #17 . However, when I run the test case test_api_general_reverse_sort in tests/test_features.py, there's still some problem. The error message is:

>   prices = [float(result['price'].replace('$', '')) for result in results]
E   ValueError: could not convert string to float: '1,699.99'

It seems that this is related to the logic handling the price. Similarly, there's same problem in check_price of tests/test_api_walmart.py. I'll try to fix this later

TomasAndersonFang commented 1 day ago

The bug caused by the value of args['sort'] has been solved in #17 . However, when I run the test case test_api_general_reverse_sort in tests/test_features.py, there's still some problem. The error message is:

>   prices = [float(result['price'].replace('$', '')) for result in results]
E   ValueError: could not convert string to float: '1,699.99'

It seems that this is related to the logic handling the price. Similarly, there's same problem in check_price of tests/test_api_walmart.py. I'll try to fix this later

Thanks for your feedback, if you want to fix this problem, you can fix only in your implementation. When we finish all the tests, we can discuss it together and fix this bug based on dev branch.

TomasAndersonFang commented 1 day ago

The bug caused by the value of args['sort'] has been solved in #17 . However, when I run the test case test_api_general_reverse_sort in tests/test_features.py, there's still some problem. The error message is:

>   prices = [float(result['price'].replace('$', '')) for result in results]
E   ValueError: could not convert string to float: '1,699.99'

It seems that this is related to the logic handling the price. Similarly, there's same problem in check_price of tests/test_api_walmart.py. I'll try to fix this later

Thanks for your feedback, if you want to fix this problem, you can fix only in your implementation. When we finish all the tests, we can discuss it together and fix this bug based on dev branch.

So you can submit a PR first.

TheFatBlue commented 1 day ago

The bug of sort_by has been solved, and the process logic of price in tests/test_feature.py has been solved in #21 , too. The remaining problem is to fix the logic for check_price, which will be done when all the test cases are finished. For the further progress, refer to #22 . This issue is closed.