Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ The [`examples/`](https://github.com/swgoh-utils/comlink-python/tree/main/exampl
| [`get_gac_brackets.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/get_gac_brackets.py) | Scan GAC brackets and search for a player |
| [`calc_stats_local.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/calc_stats_local.py) | Calculate character stats locally with `StatCalc` |
| [`search_for_guilds.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/search_for_guilds.py) | Search for guilds by name or criteria |
| [`guild_omicron_breakdown.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/guild_omicron_breakdown.py) | Report omicron adoption across a guild by game mode |

### Asynchronous ([`examples/Async/`](https://github.com/swgoh-utils/comlink-python/tree/main/examples/Async))

Expand All @@ -301,6 +302,7 @@ The [`examples/`](https://github.com/swgoh-utils/comlink-python/tree/main/exampl
| [`concurrent_requests.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/concurrent_requests.py) | Fetch multiple players in parallel with `asyncio.gather()` |
| [`streaming_guild_roster.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/streaming_guild_roster.py) | Fetch all guild members concurrently with `asyncio.TaskGroup` |
| [`streaming_guild_roster_advanced.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/streaming_guild_roster_advanced.py) | Production-quality guild roster fetch with CLI args and retry logic |
| [`guild_omicron_breakdown.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/guild_omicron_breakdown.py) | Report omicron adoption across a guild, fetching member profiles concurrently |
| [`calc_stats_local.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/calc_stats_local.py) | Calculate character stats locally with `StatCalcAsync` |

See the [full examples listing](https://github.com/swgoh-utils/comlink-python/blob/main/examples/README.md) for all available scripts and usage details.
Expand Down
63 changes: 63 additions & 0 deletions docs/api/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,69 @@ Functions for querying omicron skill data from game data collections.
show_root_heading: true
show_root_full_path: false

### get_omicron_breakdown

Summarizes omicron adoption across a set of player profiles, grouped by game mode. For every
omicron in game data it lists the players who have applied it, the players who own the unit
but have not, and how many do not own the unit.

It takes **player profiles**, not guild member entries: a guild's `member` list carries no
roster, so fetch each member's profile first. Pass `ability_list` whenever a person will read
the result. A unit often has several omicrons in one mode, so the unit name alone does not
tell the rows apart, and the omicron's own name comes from the `ability` collection.

```python
from swgoh_comlink import SwgohComlink
from swgoh_comlink.helpers import DataItems, get_guild_members, get_localization_dictionary, get_omicron_breakdown

comlink = SwgohComlink()
members = get_guild_members(comlink, allycode=314927874)
profiles = [comlink.get_player(player_id=member["playerId"]) for member in members]
game_data = comlink.get_game_data(
items=DataItems.SKILL | DataItems.UNITS | DataItems.ABILITY, include_pve_units=False
)

breakdown = get_omicron_breakdown(
profiles,
game_data["skill"],
game_data["units"],
ability_list=game_data["ability"],
localization=get_localization_dictionary(comlink),
)
for mode in breakdown["modes"]:
for row in mode["skills"]:
print(mode["mode_name"], row["unit_name"], row["skill_name"], len(row["applied"]))
```

See `examples/Sync/guild_omicron_breakdown.py` for a full report, and
`examples/Async/guild_omicron_breakdown.py` for the same report with the profiles fetched
concurrently.

::: swgoh_comlink.helpers._omicron.get_omicron_breakdown
options:
show_root_heading: true
show_root_full_path: false

::: swgoh_comlink.helpers._omicron.OmicronBreakdown
options:
show_root_heading: true
show_root_full_path: false

::: swgoh_comlink.helpers._omicron.OmicronModeBreakdown
options:
show_root_heading: true
show_root_full_path: false

::: swgoh_comlink.helpers._omicron.OmicronSkillStats
options:
show_root_heading: true
show_root_full_path: false

::: swgoh_comlink.helpers._omicron.OmicronMember
options:
show_root_heading: true
show_root_full_path: false

---

## Localization Helpers
Expand Down
2 changes: 2 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ These examples use `SwgohComlink` — the synchronous client. Simple blocking ca
| [`get_gac_leaderboard.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/get_gac_leaderboard.py) | Get GAC bracket or league/division leaderboards |
| [`get_gac_brackets.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/get_gac_brackets.py) | Scan GAC brackets for a league and search for a player |
| [`get_guild_leaderboard.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/get_guild_leaderboard.py) | Get guild-level leaderboards (TW, raids, GP, TB) |
| [`guild_omicron_breakdown.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/guild_omicron_breakdown.py) | Report omicron adoption across a guild by game mode |
| [`get_language_bundle.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/get_language_bundle.py) | Retrieve and parse a specific language bundle |
| [`get_location_bundle.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/get_location_bundle.py) | Retrieve the full localization bundle (zipped or unzipped) |
| [`get_location_bundle_adv.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Sync/get_location_bundle_adv.py) | Advanced localization bundle retrieval |
Expand Down Expand Up @@ -46,6 +47,7 @@ These examples use `SwgohComlinkAsync` — the asynchronous client. Supports con
| [`get_gac_leaderboard.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/get_gac_leaderboard.py) | Get GAC bracket or league/division leaderboards |
| [`get_gac_brackets.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/get_gac_brackets.py) | Scan GAC brackets for a league and search for a player (parallel batches) |
| [`get_guild_leaderboard.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/get_guild_leaderboard.py) | Get guild-level leaderboards (TW, raids, GP, TB) |
| [`guild_omicron_breakdown.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/guild_omicron_breakdown.py) | Report omicron adoption across a guild by game mode, fetching member profiles concurrently |
| [`get_language_bundle.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/get_language_bundle.py) | Retrieve and parse a specific language bundle |
| [`get_location_bundle.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/get_location_bundle.py) | Retrieve the full localization bundle (zipped or unzipped) |
| [`get_latest_game_data_version.py`](https://github.com/swgoh-utils/comlink-python/blob/main/examples/Async/get_latest_game_data_version.py) | Get current game data and language version strings |
Expand Down
1 change: 1 addition & 0 deletions examples/Async/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ These examples use the `SwgohComlinkAsync` async client. All methods must be `aw
| `get_game_data.py` | Retrieve game data collections (all, by segment, or by name) |
| `get_guild.py` | Look up guild info from a player's ally code |
| `get_guild_leaderboard.py` | Get guild-level leaderboards (TW, raids, GP, TB) |
| `guild_omicron_breakdown.py` | Report omicron adoption across a guild by game mode, fetching member profiles concurrently |
| `get_language_bundle.py` | Retrieve and parse a specific language bundle |
| `get_latest_game_data_version.py` | Get current game data and language version strings |
| `get_location_bundle.py` | Retrieve the full localization bundle (zipped or unzipped) |
Expand Down
110 changes: 110 additions & 0 deletions examples/Async/guild_omicron_breakdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""
guild_omicron_breakdown.py
Report omicron adoption across an entire guild, separated by game mode.

This example demonstrates how to:
1. List a guild's members from one player's ally code with async_get_guild_members()
2. Fetch every member's full profile concurrently using asyncio.TaskGroup
3. Pull only the 'skill', 'units' and 'ability' game data collections, by combining
individual DataItems bits with | rather than requesting whole segments
4. Resolve unit and omicron names through a localization dictionary
5. Summarise adoption with helpers.get_omicron_breakdown()

Why the profiles have to be fetched: a guild's 'member' list holds identity stubs (player ID,
name, galactic power) and carries no roster. Whether a member has an omicron applied lives in
player['rosterUnit'][n]['skill'], so every member needs a full get_player() call. That fan-out
is the bulk of this program; the breakdown itself is one call.
"""

import asyncio
import time

from swgoh_comlink import SwgohComlinkAsync
from swgoh_comlink.helpers import (
DataItems,
async_get_guild_members,
async_get_localization_dictionary,
get_omicron_breakdown,
)

# CONFIGURATION
# Change these to any valid values to look up that player's guild
ALLY_CODE = 314927874
COMLINK_HOST = "localhost"
COMLINK_PORT = 3000
LANGUAGE = "eng_us"

# How many omicrons to list per game mode
TOP_N = 5


async def main():
async with SwgohComlinkAsync(host=COMLINK_HOST, port=COMLINK_PORT) as comlink:
# Step 1: The guild's member list, from any one member's ally code.
members = await async_get_guild_members(comlink, allycode=ALLY_CODE)
print(f"Members: {len(members)}")

# Step 2: Every member profile, concurrently.
start = time.perf_counter()
async with asyncio.TaskGroup() as tg:
tasks = [tg.create_task(comlink.get_player(player_id=member["playerId"])) for member in members]
profiles = [task.result() for task in tasks]
print(f"Fetched {len(profiles)} profiles in {time.perf_counter() - start:.2f}s")

# Step 3: Game data. Request exactly the three collections needed by combining the
# individual DataItems bits; whole segments pull far more than this needs. 'ability'
# supplies the omicron names: a unit often has several omicrons in one game mode, so
# the unit name alone does not identify them. PvE units are left out, since only
# playable units can be in a roster.
game_data = await comlink.get_game_data(
items=DataItems.SKILL | DataItems.UNITS | DataItems.ABILITY,
include_pve_units=False,
)
print(
f"Game data: {len(game_data['skill'])} skills, {len(game_data['units'])} unit rows, "
f"{len(game_data['ability'])} abilities"
)

# Step 4: Localization, so units and omicrons read as names rather than IDs.
localization = await async_get_localization_dictionary(comlink, language=LANGUAGE)

# Step 5: The breakdown itself. It needs no client, so it runs after the session closes.
breakdown = get_omicron_breakdown(
profiles,
game_data["skill"],
game_data["units"],
ability_list=game_data["ability"],
localization=localization,
)

# Step 6: Report. Counts first, then the detail behind one of them.
total = breakdown["total_members"]
for mode in breakdown["modes"]:
print(f"\n=== {mode['mode_name']} (mode {mode['mode']}): {len(mode['skills'])} omicrons ===")
for row in mode["skills"][:TOP_N]:
applied = len(row["applied"])
owners = applied + len(row["owned_not_applied"])
label = f"{row['unit_name'] or row['unit_base_id'] or '?'}: {row['skill_name'] or row['skill_id']}"
print(f" {label:<60} {applied:>3}/{total} guild | {applied:>3}/{owners} owners")

# The member lists are the point of the helper, so show one in full: the omicron with the
# most owners who have not applied it, the guild's largest single opportunity.
rows = [(mode["mode_name"], row) for mode in breakdown["modes"] for row in mode["skills"]]
if not rows:
return
mode_name, target = max(rows, key=lambda pair: len(pair[1]["owned_not_applied"]))
if not target["owned_not_applied"]:
return

unit = target["unit_name"] or target["unit_base_id"] or "?"
print(f"\n=== Biggest opportunity: {unit}: {target['skill_name'] or target['skill_id']} ({mode_name}) ===")
print(f" applied by {len(target['applied'])}, missing on {len(target['owned_not_applied'])} rosters")
print(f" {target['not_owned_count']} members do not own the unit\n")
for member in target["owned_not_applied"]:
# tier is None when the skill is not in the roster at all: star-gated and not yet
# unlocked, rather than merely not upgraded.
position = "not unlocked" if member["tier"] is None else f"tier {member['tier']}/{target['omicron_tier']}"
print(f" {member['player_name']:<24} {position}")


asyncio.run(main())
1 change: 1 addition & 0 deletions examples/Sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ These examples use the `SwgohComlink` synchronous client. They run in a standard
| `get_game_data.py` | Retrieve game data collections (all, by segment, or by name) |
| `get_guild.py` | Look up guild info from a player's ally code |
| `get_guild_leaderboard.py` | Get guild-level leaderboards (TW, raids, GP, TB) |
| `guild_omicron_breakdown.py` | Report omicron adoption across a guild by game mode |
| `get_language_bundle.py` | Retrieve and parse a specific language bundle |
| `get_latest_game_data_version.py` | Get current game data and language version strings |
| `get_location_bundle.py` | Retrieve the full localization bundle (zipped or unzipped) |
Expand Down
100 changes: 100 additions & 0 deletions examples/Sync/guild_omicron_breakdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""
guild_omicron_breakdown.py
Report omicron adoption across an entire guild, separated by game mode.

This example demonstrates how to:
1. List a guild's members from one player's ally code with get_guild_members()
2. Fetch every member's full profile
3. Pull only the 'skill', 'units' and 'ability' game data collections, by combining
individual DataItems bits with | rather than requesting whole segments
4. Resolve unit and omicron names through a localization dictionary
5. Summarise adoption with helpers.get_omicron_breakdown()

Why the profiles have to be fetched: a guild's 'member' list holds identity stubs (player ID,
name, galactic power) and carries no roster. Whether a member has an omicron applied lives in
player['rosterUnit'][n]['skill'], so every member needs a full get_player() call. Here they are
fetched one after another; see examples/Async/guild_omicron_breakdown.py to fetch them
concurrently.
"""

import time

from swgoh_comlink import SwgohComlink
from swgoh_comlink.helpers import (
DataItems,
get_guild_members,
get_localization_dictionary,
get_omicron_breakdown,
)

# CONFIGURATION
# Change these to any valid values to look up that player's guild
ALLY_CODE = 314927874
COMLINK_HOST = "localhost"
COMLINK_PORT = 3000
LANGUAGE = "eng_us"

# How many omicrons to list per game mode
TOP_N = 5

comlink = SwgohComlink(host=COMLINK_HOST, port=COMLINK_PORT)

# Step 1: The guild's member list, from any one member's ally code.
members = get_guild_members(comlink, allycode=ALLY_CODE)
print(f"Members: {len(members)}")

# Step 2: Every member profile.
start = time.perf_counter()
profiles = [comlink.get_player(player_id=member["playerId"]) for member in members]
print(f"Fetched {len(profiles)} profiles in {time.perf_counter() - start:.2f}s")

# Step 3: Game data. Request exactly the three collections needed by combining the individual
# DataItems bits; whole segments pull far more than this needs. 'ability' supplies the omicron
# names: a unit often has several omicrons in one game mode, so the unit name alone does not
# identify them. PvE units are left out, since only playable units can be in a roster.
game_data = comlink.get_game_data(
items=DataItems.SKILL | DataItems.UNITS | DataItems.ABILITY,
include_pve_units=False,
)
print(
f"Game data: {len(game_data['skill'])} skills, {len(game_data['units'])} unit rows, "
f"{len(game_data['ability'])} abilities"
)

# Step 4: Localization, so units and omicrons read as names rather than IDs.
localization = get_localization_dictionary(comlink, language=LANGUAGE)

# Step 5: The breakdown itself.
breakdown = get_omicron_breakdown(
profiles,
game_data["skill"],
game_data["units"],
ability_list=game_data["ability"],
localization=localization,
)

# Step 6: Report. Counts first, then the detail behind one of them.
total = breakdown["total_members"]
for mode in breakdown["modes"]:
print(f"\n=== {mode['mode_name']} (mode {mode['mode']}): {len(mode['skills'])} omicrons ===")
for row in mode["skills"][:TOP_N]:
applied = len(row["applied"])
owners = applied + len(row["owned_not_applied"])
label = f"{row['unit_name'] or row['unit_base_id'] or '?'}: {row['skill_name'] or row['skill_id']}"
print(f" {label:<60} {applied:>3}/{total} guild | {applied:>3}/{owners} owners")

# The member lists are the point of the helper, so show one in full: the omicron with the most
# owners who have not applied it, the guild's largest single opportunity.
rows = [(mode["mode_name"], row) for mode in breakdown["modes"] for row in mode["skills"]]
if rows:
mode_name, target = max(rows, key=lambda pair: len(pair[1]["owned_not_applied"]))
if target["owned_not_applied"]:
unit = target["unit_name"] or target["unit_base_id"] or "?"
print(f"\n=== Biggest opportunity: {unit}: {target['skill_name'] or target['skill_id']} ({mode_name}) ===")
print(f" applied by {len(target['applied'])}, missing on {len(target['owned_not_applied'])} rosters")
print(f" {target['not_owned_count']} members do not own the unit\n")
for member in target["owned_not_applied"]:
# tier is None when the skill is not in the roster at all: star-gated and not yet
# unlocked, rather than merely not upgraded.
position = "not unlocked" if member["tier"] is None else f"tier {member['tier']}/{target['omicron_tier']}"
print(f" {member['player_name']:<24} {position}")
10 changes: 10 additions & 0 deletions src/swgoh_comlink/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
parse_swgoh_string,
)
from ._omicron import (
OmicronBreakdown,
OmicronMember,
OmicronModeBreakdown,
OmicronSkillStats,
get_omicron_breakdown,
get_omicron_skill_tier,
get_omicron_skills,
get_tw_omicrons,
Expand Down Expand Up @@ -217,6 +222,11 @@
"get_named_rewards",
"get_player_title_names",
# Omicron
"OmicronBreakdown",
"OmicronMember",
"OmicronModeBreakdown",
"OmicronSkillStats",
"get_omicron_breakdown",
"get_omicron_skill_tier",
"get_omicron_skills",
"get_tw_omicrons",
Expand Down
Loading
Loading