Skip to content

Commit

Permalink
move graph to reporter, add ADA logo
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelsoup42 committed Oct 11, 2023
1 parent 3b7541d commit 0786f09
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies = [
"openpyxl",
"pandas",
"types-openpyxl",
"types-Pillow",
]

[project.scripts]
Expand All @@ -31,7 +32,7 @@ cardano_account_pandas_dumper = "cardano_account_pandas_dumper.__main__:main"
where = ["src"]

[tool.setuptools.package-data]
cardano_account_pandas_dumper = ["*.jsonc"]
cardano_account_pandas_dumper = ["*.jsonc", "*.webp"]

[tool.mypy]
follow_imports = "normal"
Expand Down
21 changes: 3 additions & 18 deletions src/cardano_account_pandas_dumper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from json import JSONDecodeError

import jstyleson
from matplotlib.patches import Rectangle
import matplotlib.pyplot as plt
import matplotlib as mpl
from blockfrost import ApiError, BlockFrostApi
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
from .cardano_account_pandas_dumper import AccountData, AccountPandasDumper
Expand Down Expand Up @@ -229,22 +228,8 @@ def main():
except OSError as exception:
warnings.warn(f"Failed to write .xlsx file: {exception}")
if args.plot:
balance = reporter.make_balance_frame(
with_total=False, raw_values=True
).cumsum()
balance.plot(logy=True)

plt.legend(
[
Rectangle(xy=(0, 0), width=10, height=10, color=(0.9, 0.9, 0.7))
for l in balance.columns
],
[reporter.asset_names.get(c, c) for c in balance.columns],
bbox_to_anchor=(1, 1),
fontsize="small",
)
plt.suptitle(f"Asset balances until block {args.to_block}.")
plt.show()
reporter.plot_balance()
mpl.pyplot.show()
print("Done.")


Expand Down
Binary file added src/cardano_account_pandas_dumper/ada_logo.webp
Binary file not shown.
46 changes: 46 additions & 0 deletions src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
""" Cardano Account To Pandas Dumper."""
import datetime
import itertools
from base64 import b64decode
from collections import defaultdict
from io import BytesIO
import os
from typing import (
Any,
Callable,
Expand All @@ -16,6 +19,7 @@
)

import blockfrost.utils
import matplotlib as mpl
import numpy as np
import pandas as pd
from blockfrost import BlockFrostApi
Expand Down Expand Up @@ -590,3 +594,45 @@ def make_transaction_frame(
), f"Frame lengths do not match {msg_frame=!s} , {balance_frame=!s}"
joined_frame = pd.concat(objs=[msg_frame, balance_frame], axis=1)
return joined_frame

def plot_balance(self):
balance = self.make_balance_frame(with_total=False, raw_values=True).cumsum()
balance.sort_index(
axis=1,
level=0,
sort_remaining=True,
inplace=True,
key=lambda i: [self.asset_names.get(x, x) for x in i],
)

balance.plot(
logy=True, title=f"Asset balances until block {self.data.to_block}."
)
assets = [self.data.assets.get(c, None) for c in balance.columns]
logos = [
BytesIO(b64decode(a.metadata.logo))
if (
a
and hasattr(a, "metadata")
and hasattr(a.metadata, "logo")
and a.metadata.logo
)
else None
for a in assets
]
assert (
balance.columns[0] == self.ADA_ASSET
), f"ADA not the first asset in {balance.columns}"
logos[0] = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "ada_logo.webp"
)

mpl.pyplot.legend(
[
mpl.patches.Rectangle(xy=(0, 0), width=10, height=10, color=f"C{i}")
for i in range(len(balance.columns))
],
[self.asset_names.get(c, c) for c in balance.columns],
bbox_to_anchor=(1, 1),
fontsize="small",
)

0 comments on commit 0786f09

Please sign in to comment.