Skip to content
Snippets Groups Projects
Commit a89e7105 authored by matograine's avatar matograine Committed by Moul
Browse files

[enh] commands: Migrate from tabulate to texttable (#203)

modify display for blocks, and diffi commands
parent 17fb11aa
No related branches found
No related tags found
1 merge request!199#203: Harmonize tables style using Texttable
...@@ -24,9 +24,9 @@ from click import IntRange, argument, command, option ...@@ -24,9 +24,9 @@ from click import IntRange, argument, command, option
from duniterpy.api import bma from duniterpy.api import bma
from duniterpy.api.client import WSConnection from duniterpy.api.client import WSConnection
from pendulum import from_timestamp from pendulum import from_timestamp
from tabulate import tabulate
from websocket._exceptions import WebSocketConnectionClosedException from websocket._exceptions import WebSocketConnectionClosedException
from silkaj import tui
from silkaj.blockchain_tools import get_head_block from silkaj.blockchain_tools import get_head_block
from silkaj.constants import ALL from silkaj.constants import ALL
from silkaj.network_tools import client_instance, determine_endpoint from silkaj.network_tools import client_instance, determine_endpoint
...@@ -112,11 +112,15 @@ def display_diffi(current: WSConnection, diffi: Dict) -> None: ...@@ -112,11 +112,15 @@ def display_diffi(current: WSConnection, diffi: Dict) -> None:
system("cls||clear") system("cls||clear")
block_gen = from_timestamp(current["time"], tz="local").format(ALL) block_gen = from_timestamp(current["time"], tz="local").format(ALL)
match = match_pattern(int(current["powMin"]))[0] match = match_pattern(int(current["powMin"]))[0]
table = tabulate(sorted_diffi, headers="keys", tablefmt="orgtbl", stralign="center")
table = tui.Table(style="columns").set_cols_dtype(["t", "t", "t", "i"])
table.fill_from_dict_list(sorted_diffi)
content = f'Current block: n°{current["number"]}, generated on {block_gen}\n\ content = f'Current block: n°{current["number"]}, generated on {block_gen}\n\
Generation of next block n°{diffi["block"]} \ Generation of next block n°{diffi["block"]} \
possible by at least {issuers}/{len(diffi["levels"])} members\n\ possible by at least {issuers}/{len(diffi["levels"])} members\n\
Common Proof-of-Work difficulty level: {current["powMin"]}, hash starting with `{match}`\n{table}' Common Proof-of-Work difficulty level: {current["powMin"]}, hash starting with `{match}`\n\
{table.draw()}'
print(content) print(content)
...@@ -174,10 +178,11 @@ def print_blocks_views(issuers, current_nbr, number, detailed): ...@@ -174,10 +178,11 @@ def print_blocks_views(issuers, current_nbr, number, detailed):
print(header, end=" ") print(header, end=" ")
if detailed or number <= 30: if detailed or number <= 30:
sorted_list = sorted(issuers, key=itemgetter("block"), reverse=True) sorted_list = sorted(issuers, key=itemgetter("block"), reverse=True)
table = tabulate(
sorted_list, headers="keys", tablefmt="orgtbl", stralign="center" table = tui.Table(style="columns")
) table.fill_from_dict_list(sorted_list)
print(f"\n{table}") print(f"\n{table.draw()}")
else: else:
list_issued = [] # type: List[OrderedDict] list_issued = [] # type: List[OrderedDict]
for issuer in issuers: for issuer in issuers:
...@@ -195,14 +200,9 @@ def print_blocks_views(issuers, current_nbr, number, detailed): ...@@ -195,14 +200,9 @@ def print_blocks_views(issuers, current_nbr, number, detailed):
for issued in list_issued: for issued in list_issued:
issued["percent"] = issued["blocks"] / number * 100 issued["percent"] = issued["blocks"] / number * 100
sorted_list = sorted(list_issued, key=itemgetter("blocks"), reverse=True) sorted_list = sorted(list_issued, key=itemgetter("blocks"), reverse=True)
table = tabulate( table = tui.Table(style="columns")
sorted_list, table.fill_from_dict_list(sorted_list)
headers="keys", print(f"from {len(list_issued)} issuers\n{table.draw()}")
tablefmt="orgtbl",
floatfmt=".1f",
stralign="center",
)
print(f"from {len(list_issued)} issuers\n{table}")
@command("argos", help="Display currency information formatted for Argos or BitBar") @command("argos", help="Display currency information formatted for Argos or BitBar")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment