Skip to content

Commit

Permalink
add graph flags, fix order
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelsoup42 committed Oct 14, 2023
1 parent 226822b commit 5bed9e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
29 changes: 28 additions & 1 deletion src/cardano_account_pandas_dumper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ def _create_arg_parser():
help="Path to graphics output file.",
type=str,
)
result.add_argument(
"--graph_order",
help="Graph order of assets: appearance=order of appearance (default), alpha=alphabetical.",
type=str,
choices=["alpha", "appearance"],
default="appearance",
)
result.add_argument(
"--matplotlib_rc",
help="Path to matplotlib defaults file.",
Expand All @@ -79,6 +86,21 @@ def _create_arg_parser():
os.path.dirname(os.path.abspath(__file__)), "matplotlib.rc"
),
)
result.add_argument(
"--graph_width", help="Width of graph, in inches.", type=float, default=11.69
)
result.add_argument(
"--graph_height",
help="Height of graph for one asset, in inches.",
type=float,
default=2.0675,
)
result.add_argument(
"--width_ratio",
help="Ratio of plot width to legend with for an asset .",
type=int,
default=6,
)
result.add_argument(
"--detail_level",
help="Level of detail of report (1=only own addresses, 2=other addresses as well).",
Expand Down Expand Up @@ -235,7 +257,12 @@ def main():
if args.graph_output:
with mpl.rc_context(fname=args.matplotlib_rc):
try:
reporter.plot_balance()
reporter.plot_balance(
order=args.graph_order,
graph_width=args.graph_width,
graph_height=args.graph_height,
width_ratio=args.width_ratio,
)
plt.savefig(
args.graph_output,
metadata=reporter.get_graph_metadata(args.graph_output),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ def make_balance_frame(self, with_total: bool, raw_values: bool, detail_level: i
else:
group = (0, 2)
balance = balance.T.groupby(level=group).sum(numeric_only=True).T
balance[balance == 0] = pd.NA
if with_total:
balance = pd.concat(
[
Expand Down Expand Up @@ -581,7 +580,7 @@ def make_transaction_frame(
)
balance_frame = self.make_balance_frame(
detail_level=detail_level, with_total=with_total, raw_values=raw_values
)
).replace(0, pd.NA)
if not raw_values:
balance_frame.sort_index(axis=1, level=0, sort_remaining=True, inplace=True)
if detail_level > 1:
Expand Down Expand Up @@ -653,7 +652,9 @@ def _draw_asset_legend(self, ax: Axes, asset_id: str):
ax.set_xlim((0.0, 1.0))
ax.set_ylim((1.0, 0.0))

def plot_balance(self, order: str = "appearance"):
def plot_balance(
self, order: str, graph_width: float, graph_height: float, width_ratio: int
):
"""Create a Matplotlib plot with the asset balance over time."""
balance = self.make_balance_frame(
detail_level=1, with_total=False, raw_values=True
Expand All @@ -672,15 +673,17 @@ def plot_balance(self, order: str = "appearance"):
level=0,
sort_remaining=True,
inplace=True,
key=lambda i: [balance[x].first_valid_index() for x in i],
key=lambda i: [
balance[x].replace(0, pd.NA).first_valid_index() for x in i
],
)
else:
raise ValueError(f"Unkown ordering: {order}")
fig, ax = pyplot.subplots(
len(balance.columns),
2,
width_ratios=(6, 1),
figsize=(11.69, 2.0675 * len(balance.columns)),
width_ratios=(width_ratio, 1),
figsize=(graph_width, graph_height * len(balance.columns)),
)
fig.suptitle("\n" + self._plot_title() + "\n")
for i in range( # pylint: disable=consider-using-enumerate
Expand Down

0 comments on commit 5bed9e0

Please sign in to comment.