Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
feat: add plot_expected_against_actual_mainstats method
Browse files Browse the repository at this point in the history
  • Loading branch information
trumully committed Apr 13, 2024
1 parent 5e6db3a commit 1446bcb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
54 changes: 53 additions & 1 deletion src/artipy/analysis/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from plotly.subplots import make_subplots

from artipy.artifacts import Artifact
from artipy.stats import STAT_NAMES
from artipy.stats import STAT_NAMES, VALID_MAINSTATS, StatType

from .analyse import (
RollMagnitude,
Expand Down Expand Up @@ -121,6 +121,58 @@ def plot_roll_value_distribution(iterations: int = 1000) -> None:
fig.show()


def plot_expected_against_actual_mainstats(iterations: int = 1000) -> None:
for a in (artifacts := create_multiple_random_artifacts(iterations)):
upgrade_artifact_to_max(a)

expected_mainstats = {
k: v for k, v in VALID_MAINSTATS.items() if k not in ("flower", "plume")
}
actual_mainstats: dict[str, list[StatType]] = {k: [] for k in expected_mainstats}

for a in artifacts:
if (slot := a.get_artifact_slot()) in expected_mainstats:
actual_mainstats[slot].append(a.get_mainstat().name)

actual_mainstats_pct: dict[str, dict[StatType, float]] = {
k: {
stat: (actual_mainstats[k].count(stat) / len(actual_mainstats[k])) * 100
for stat in v
}
for k, v in actual_mainstats.items()
}

fig = make_subplots(
rows=1, cols=len(expected_mainstats), subplot_titles=list(expected_mainstats)
)

for i, slot in enumerate(expected_mainstats, start=1):
col = (i - 1) % len(expected_mainstats) + 1
fig.add_trace(
go.Bar(
x=list(expected_mainstats[slot]),
y=list(expected_mainstats[slot].values()),
name="Expected",
marker=dict(color="#FF6961"),
),
row=1,
col=col,
)
fig.add_trace(
go.Bar(
x=list(actual_mainstats_pct[slot]),
y=list(actual_mainstats_pct[slot].values()),
name="Actual",
marker=dict(color="#B4D8E7"),
),
row=1,
col=col,
)

fig.update_layout(barmode="overlay", showlegend=False)
fig.show()


def plot_multi_value_distribution(
iterations: int = 1000, *, attributes: tuple[str]
) -> None:
Expand Down
12 changes: 7 additions & 5 deletions src/artipy/analysis/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def create_random_artifact(
slot: str = random.choice(("flower", "plume", "sands", "goblet")),
slot: str = random.choice(("flower", "plume", "sands", "goblet", "circlet")),
) -> Artifact:
"""Create a random artifact.
Expand Down Expand Up @@ -39,14 +39,16 @@ def upgrade_artifact_to_max(artifact: Artifact) -> Artifact:
return artifact


def create_multiple_random_artifacts(
amount: int = 1, slot: str = random.choice(("flower", "plume", "sands", "goblet"))
) -> list[Artifact]:
def create_multiple_random_artifacts(amount: int = 1) -> list[Artifact]:
"""Create multiple random artifacts.
:param amount: The amount of artifacts to create, defaults to 1
:type amount: int, optional
:return: The list of random artifacts.
:rtype: list[Artifact]
"""
return [create_random_artifact(slot) for _ in range(amount)]
result = []
for _ in range(amount):
slot = random.choice(("flower", "plume", "sands", "goblet", "circlet"))
result.append(create_random_artifact(slot))
return result

0 comments on commit 1446bcb

Please sign in to comment.