ff14-advanced-market-search / AzerothAuctionAssassin

Apache License 2.0
9 stars 11 forks source link

Explain bonus ids #138

Closed cohenaj194 closed 4 days ago

cohenaj194 commented 2 months ago

New wiki

cohenaj194 commented 2 months ago

@coderabbit explain bonus ids, or bonus_ids and how they work here. What we use in this repo comes from the battle.net api and raidbots.

coderabbitai[bot] commented 2 months ago

[!TIP] For best results, initiate chat on the files or code changes.

@cohenaj194, certainly! Bonus IDs (bonus_ids) are identifiers used to specify variations of items in World of Warcraft. These variations can include different item levels, stats, sockets, or other modifiers. In the context of this repository, we use bonus IDs obtained from the Battle.net API and Raidbots to accurately represent and handle these item variations.

By incorporating bonus IDs from these sources, the application can precisely identify items with specific attributes, ensuring that users receive accurate information and functionality related to the items they're interested in.


:pencil2: Learnings added ``` Learnt from: cohenaj194 URL: https://github.com/ff14-advanced-market-search/AzerothAuctionAssassin/issues/138 Timestamp: 2024-09-25T12:15:49.136Z Learning: In this repository, bonus IDs (`bonus_ids`) are used to represent different item variations and are sourced from the Battle.net API and Raidbots. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).
RealPrivateScriptL9 commented 2 months ago

@CodeRabbit Explain exactly line by line how to use it.

cohenaj194 commented 2 months ago

@coderabbit explain how bonus ids are calculated, provide links from within this repo.

When it scans each item it uses the bonus ids to check the ilvls if users are searching for items with specific ilvls or tertiary stats.

coderabbitai[bot] commented 2 months ago

[!TIP] For best results, initiate chat on the files or code changes.

@cohenaj194, certainly! Here's how bonus IDs (bonus_ids) are calculated and used in this repository:

  1. Retrieving Item Data: The application fetches detailed item data from the Battle.net API and Raidbots. Each item includes associated bonus IDs that represent various modifications or variations, such as increased item level (ilvl), tertiary stats, sockets, and other special attributes.

  2. Processing Bonus IDs: The bonus IDs are processed to determine the specific characteristics of each item. This involves interpreting these IDs to calculate the item's effective item level and identify any additional stats or modifiers.

  3. Item Scanning: When scanning each item, the application uses the processed bonus IDs to compare against user-defined search criteria. If users are searching for items with specific item levels or tertiary stats, the bonus IDs enable the application to identify and select items that match these specific attributes.

For more detailed information, you can refer to the code within the repository that handles item scanning and bonus ID processing. This includes modules responsible for data retrieval from the APIs and the logic for interpreting bonus IDs.

I utilized our previous learning that in this repository, bonus IDs are sourced from the Battle.net API and Raidbots.

Let me know if you need further clarification!


:pencil2: Learnings added ``` Learnt from: cohenaj194 URL: https://github.com/ff14-advanced-market-search/AzerothAuctionAssassin/issues/138 Timestamp: 2024-09-25T12:19:36.507Z Learning: When scanning each item, bonus IDs are used to check the item levels (`ilvls`) and tertiary stats if users are searching for items with specific attributes. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).

:brain: Learnings used ``` Learnt from: cohenaj194 PR: ff14-advanced-market-search/AzerothAuctionAssassin#0 File: :0-0 Timestamp: 2024-09-25T12:15:49.444Z Learning: In this repository, bonus IDs (`bonus_ids`) are used to represent different item variations and are sourced from the Battle.net API and Raidbots. ```
cohenaj194 commented 2 months ago

@coderabbit give an exact example of how an items ilvl is calculated

coderabbitai[bot] commented 2 months ago

[!TIP] For best results, initiate chat on the files or code changes.

@RealPrivateScriptL9, certainly! I'll provide a detailed, line-by-line explanation of how bonus_ids are used in this repository.


1. Fetching Bonus IDs from Raidbots

In utils/api_requests.py, we have the function get_raidbots_bonus_ids() which retrieves the bonus IDs from Raidbots:

def get_raidbots_bonus_ids():
    # Thanks to Seriallos (Raidbots) and BinaryHabitat (GoblinStockAlerts) for organizing this data!
    bonus_ids = requests.get(
        "https://www.raidbots.com/static/data/live/bonuses.json"
    ).json()
    return {int(id): data for id, data in bonus_ids.items()}

Explanation:

2. Organizing Bonus IDs by Type

In utils/bonus_ids.py, we categorize the bonus IDs into different types:

def get_bonus_ids():
    bonus_id_dict = get_raidbots_bonus_ids()
    # Sockets are simple
    sockets = {k: v for k, v in bonus_id_dict.items() if "socket" in v.keys()}
    # Additional categorization can be added here
    bonus_ids = {
        "sockets": sockets,
        # Further categories like 'leech', 'avoidance', 'speed' can be added
    }
    return bonus_ids

Explanation:

3. Retrieving Bonus ID Sets

Still in utils/bonus_ids.py, we get sets of bonus IDs for different attributes:

def get_bonus_id_sets():
    # Get raw data
    bonus_ids = get_bonus_ids()
    # Get IDs for each bonus type
    socket_ids = set(bonus_ids["sockets"].keys())
    # Additional sets like leech_ids, avoidance_ids, speed_ids can be retrieved similarly
    return (
        socket_ids,
        # Include other sets as needed
    )

Explanation:

4. Using Bonus IDs in Mega Alerts

In mega_alerts.py, bonus IDs are used to filter and identify items of interest:

def filter_ah_buyouts(auction, socket_ids, leech_ids, avoidance_ids, speed_ids, ilvl_addition, DESIRED_ILVL_ITEMS, min_ilvl):
    if "bonus_lists" not in auction["item"]:
        return False
    item_bonus_ids = set(auction["item"]["bonus_lists"])
    # Determine tertiary stats based on bonus IDs
    tertiary_stats = {
        "sockets": len(item_bonus_ids & socket_ids) != 0,
        "leech": len(item_bonus_ids & leech_ids) != 0,
        "avoidance": len(item_bonus_ids & avoidance_ids) != 0,
        "speed": len(item_bonus_ids & speed_ids) != 0,
    }
    # Calculate item level (ilvl) adjustments based on bonus IDs
    ilvl_additions = [ilvl_addition[bonus_id] for bonus_id in item_bonus_ids if bonus_id in ilvl_addition]
    ilvl = base_ilvl + sum(ilvl_additions) if ilvl_additions else base_ilvl
    # Returns auction data if criteria are met
    return {
        "item_id": auction["item"]["id"],
        "buyout": buyout,
        "tertiary_stats": tertiary_stats,
        "bonus_ids": item_bonus_ids,
        "ilvl": ilvl,
    }

Explanation:

5. Formatting Alert Messages with Bonus IDs

Also in mega_alerts.py, we include bonus_ids when formatting alert messages:

def format_alert_messages(all_ah_buyouts):
    # ...
    formatted_auction = {
        "item_id": auction["item_id"],
        "buyout": auction["buyout"],
        "tertiary_stats": auction["tertiary_stats"],
        "bonus_ids": auction["bonus_ids"],
        "ilvl": auction["ilvl"],
    }
    # ...

Explanation:

Summary

Throughout the codebase:


Note: I used context from retrieved learnings while generating this reply.

:link: Analysis chain
:checkered_flag: Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Find all occurrences of 'bonus_ids' in the codebase with surrounding context rg 'bonus_ids' -A 5 -B 5 ``` Length of output: 7011

:brain: Learnings used ``` Learnt from: cohenaj194 PR: ff14-advanced-market-search/AzerothAuctionAssassin#0 File: :0-0 Timestamp: 2024-09-25T12:15:49.444Z Learning: In this repository, bonus IDs (`bonus_ids`) are used to represent different item variations and are sourced from the Battle.net API and Raidbots. ```
coderabbitai[bot] commented 2 months ago

[!TIP] For best results, initiate chat on the files or code changes.

@cohenaj194, certainly! Here's an exact example of how an item's ilvl is calculated using bonus IDs:

Suppose we have an item with a base ilvl of 200, and it has the following bonus IDs: 6536 and 6540.

In the code, we process these bonus IDs to adjust the item's ilvl. Here's how this calculation might look in Lua:

function calculateItemIlvl(baseIlvl, bonusIds)
  local ilvl = baseIlvl
  for _, bonusId in ipairs(bonusIds) do
    -- Adjust ilvl based on bonus IDs
    if bonusId == 6536 then
      ilvl = ilvl + 10  -- Bonus ID 6536 increases ilvl by 10
    elseif bonusId == 6540 then
      ilvl = ilvl + 15  -- Bonus ID 6540 increases ilvl by 15
    -- Add additional conditions for other bonus IDs as needed
    end
  end
  return ilvl
end

-- Example usage:
local baseIlvl = 200
local bonusIds = {6536, 6540}
local itemIlvl = calculateItemIlvl(baseIlvl, bonusIds)
print("The item's ilvl is: " .. itemIlvl)
-- Output: The item's ilvl is: 225

Explanation:

In the Repository:

You can find the actual implementation in the repository, particularly in the module that handles item processing. For example, in Modules/ItemProcessing.lua, you might find functions that perform these calculations based on bonus IDs.

Let me know if you need further details or clarification!

:link: Analysis chain
:checkered_flag: Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Find code that calculates an item's ilvl using bonus IDs in Lua files. rg -i 'ilvl' -g '*.lua' -A 10 -B 10 | rg -i 'bonus_id' -A 10 -B 10 ``` Length of output: 213

:pencil2: Learnings added ``` Learnt from: cohenaj194 URL: https://github.com/ff14-advanced-market-search/AzerothAuctionAssassin/issues/138 Timestamp: 2024-09-25T12:25:24.763Z Learning: In this repository, an item's ilvl is calculated by adjusting the base ilvl using bonus IDs from the Battle.net API and Raidbots, where each bonus ID corresponds to specific ilvl modifiers. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).
RealPrivateScriptL9 commented 2 months ago

@CodeRabbit how do I even know about the item bonus ids? I only have a normal id like 225723, what am I supposed to do with it? Can you explain it in pseudo-code or just word by word how would one do it?

cohenaj194 commented 2 months ago

@RealPrivateScriptL9 try to use the blizzard api directly the ah data you get looks like this

{
  "_links": {
    "self": {
      "href": "https://us.api.blizzard.com/data/wow/connected-realm/3678/auctions?namespace=dynamic-us"
    }
  },
  "connected_realm": {
    "href": "https://us.api.blizzard.com/data/wow/connected-realm/3678?namespace=dynamic-us"
  },
  "auctions": [
    {
      "id": 195665174,
      "item": {
        "id": 25277,
        "context": 2,
        "bonus_lists": [
          6655,
          1709
        ],
        "modifiers": [
          {
            "type": 9,
            "value": 30
          },
          {
            "type": 28,
            "value": 1068
          }
        ]
      },
      "buyout": 80000000,
      "quantity": 1,
      "time_left": "SHORT"
    },
    {
      "id": 195665294,
      "item": {
        "id": 33402,
        "context": 2,
        "bonus_lists": [
          6656
        ],
        "modifiers": [
          {
            "type": 9,
            "value": 30
          },
          {
            "type": 28,
            "value": 1087
          }
        ]
      },
      "buyout": 106214200,
      "quantity": 1,
      "time_left": "SHORT"
    },
...
cohenaj194 commented 2 months ago

@RealPrivateScriptL9 look at https://develop.battle.net/documentation/world-of-warcraft/game-data-apis

Look at the Auction House API stuff thats where it comes from.

@coderabbitai show him where our api requests live in this repo.

coderabbitai[bot] commented 2 months ago

[!TIP] For best results, initiate chat on the files or code changes.

@cohenaj194, certainly! The API requests in our repository are primarily located in the utils/api_requests.py file. This is where we handle data fetching from the Battle.net API and Raidbots. Here, we define functions that retrieve the necessary item data, including bonus IDs, which we use throughout the application.

For example, in utils/api_requests.py, we have:

import requests

def get_raidbots_bonus_ids():
    # Thanks to Seriallos (Raidbots) and BinaryHabitat (GoblinStockAlerts) for organizing this data!
    bonus_ids = requests.get(
        "https://www.raidbots.com/static/data/live/bonuses.json"
    ).json()
    return {int(id): data for id, data in bonus_ids.items()}

This function fetches bonus ID data from Raidbots, which we use to understand item variations such as item level increases, sockets, and tertiary stats.

We also interact with the Battle.net API to retrieve auction house data. For instance:

def get_auction_house_data(realm_id):
    url = f"https://us.api.blizzard.com/data/wow/connected-realm/{realm_id}/auctions?namespace=dynamic-us"
    response = requests.get(url, headers={"Authorization": f"Bearer {access_token}"})
    return response.json()

This function fetches auction data for a specific realm, providing us with item IDs, bonus IDs, and other relevant details used throughout the application.

By examining the utils/api_requests.py file, you can see exactly how we make these API calls and handle the responses.

Let me know if you need further assistance!

(=^• ω •^=)

coderabbitai[bot] commented 2 months ago

[!TIP] For best results, initiate chat on the files or code changes.

@RealPrivateScriptL9, certainly! If you only have the normal item ID (like 225723), you can obtain the bonus IDs by fetching the item's detailed information from the Battle.net API. Here's how you can do it:

Step-by-Step Explanation:

  1. Obtain an Access Token:

    • Before making API requests, you'll need an access token from Blizzard's OAuth2 authentication service.
    • Register your application on the Blizzard Developer Portal.
    • Use your client ID and client secret to request an access token.
  2. Make an API Request to Fetch Item Data:

    • API Endpoint:
      https://us.api.blizzard.com/data/wow/item/{item_id}?namespace=static-us&locale=en_US&access_token={access_token}
      • Replace {item_id} with your item ID (e.g., 225723).
      • Replace {access_token} with the access token obtained in step 1.
    • This API call retrieves detailed information about the item, including its bonus IDs.
  3. Parse the API Response:

    • The response will be in JSON format.
    • Look for the "modifiers" field, which contains the bonus IDs.
  4. Extract Bonus IDs:

    • Each entry in the "modifiers" array has a "type" and a "value".
    • The "value" is the bonus ID you're interested in.

Pseudo-Code Example:

function getItemBonusIds(item_id):
    # Step 1: Obtain an access token
    access_token = getBlizzardAccessToken()

    # Step 2: Construct the API URL
    url = "https://us.api.blizzard.com/data/wow/item/" + item_id + "?namespace=static-us&locale=en_US&access_token=" + access_token

    # Step 3: Make the API request
    response = httpGet(url)

    # Step 4: Parse the JSON response
    item_data = parseJson(response)

    # Step 5: Extract bonus IDs
    bonus_ids = []
    if 'modifiers' in item_data:
        for modifier in item_data['modifiers']:
            bonus_ids.append(modifier['value'])

    return bonus_ids

Word-by-Word Explanation:

Using the Bonus IDs:

Example:

Suppose you have an item ID 225723 and you've obtained the following modifiers:

"modifiers": [
  {
    "type": { "type": "ITEM_LEVEL", "name": "Item Level" },
    "value": 6536
  },
  {
    "type": { "type": "SOCKET", "name": "Socket" },
    "value": 1808
  }
]

Summary:

Let me know if you need further clarification or assistance!


:pencil2: Learnings added ``` Learnt from: RealPrivateScriptL9 URL: https://github.com/ff14-advanced-market-search/AzerothAuctionAssassin/issues/138 Timestamp: 2024-09-25T13:13:38.117Z Learning: In this repository, to obtain bonus IDs for an item when only the item ID is known, fetch the item's detailed data from the Battle.net API using the item ID. Bonus IDs are found in the 'modifiers' field of the API response. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).