added new text buttons to show total hashrate and current sort key

This commit is contained in:
UpstreamData
2022-05-09 10:24:48 -06:00
parent 1f8d92f6bb
commit 666c5bfc64
3 changed files with 97 additions and 15 deletions

View File

@@ -14,7 +14,7 @@ TABLE_HEADERS = {
"Pool User", "Pool User",
"Wattage", "Wattage",
], ],
"CMD": ["IP", "Model", "Command Output"], "CMD": ["IP", "Model", "Output"],
"POOLS_ALL": [ "POOLS_ALL": [
"IP", "IP",
"Split", "Split",
@@ -48,6 +48,19 @@ MINER_COUNT_BUTTONS = [
"pools_miner_count", "pools_miner_count",
] ]
SORT_KEY_BUTTONS = [
"scan_sort_key",
"cmd_sort_key",
"cfg_sort_key",
"pools_sort_key",
]
HASHRATE_TOTAL_BUTTONS = [
"scan_total_hashrate",
"cfg_total_hashrate",
"pools_total_hashrate",
]
BUTTON_KEYS = [ BUTTON_KEYS = [
"btn_scan", "btn_scan",
"btn_cmd", "btn_cmd",
@@ -114,6 +127,20 @@ def get_scan_layout():
sg.InputText(key="scan_ip", size=(31, 1)), sg.InputText(key="scan_ip", size=(31, 1)),
sg.Button("Scan", key="btn_scan"), sg.Button("Scan", key="btn_scan"),
sg.Push(), sg.Push(),
sg.Button(
"Sort: IP",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="scan_sort_key",
),
sg.Button(
"Hashrate: 0 TH/s",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="scan_total_hashrate",
),
sg.Button( sg.Button(
"Miners: 0", "Miners: 0",
disabled=True, disabled=True,
@@ -161,6 +188,13 @@ def get_command_layout():
sg.InputText(key="cmd_txt", expand_x=True), sg.InputText(key="cmd_txt", expand_x=True),
sg.Button("Send Command", key="btn_cmd"), sg.Button("Send Command", key="btn_cmd"),
sg.Push(), sg.Push(),
sg.Button(
"Sort: IP",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="cmd_sort_key",
),
sg.Button( sg.Button(
"Miners: 0", "Miners: 0",
disabled=True, disabled=True,
@@ -211,6 +245,20 @@ def get_pools_layout():
sg.Button("REFRESH DATA", key="pools_refresh"), sg.Button("REFRESH DATA", key="pools_refresh"),
sg.Button("OPEN IN WEB", key="pools_web"), sg.Button("OPEN IN WEB", key="pools_web"),
sg.Push(), sg.Push(),
sg.Button(
"Sort: IP",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="pools_sort_key",
),
sg.Button(
"Hashrate: 0 TH/s",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="pools_total_hashrate",
),
sg.Button( sg.Button(
"Miners: 0", "Miners: 0",
disabled=True, disabled=True,
@@ -314,6 +362,20 @@ def get_config_layout():
sg.Button("CONFIG", key="cfg_config"), sg.Button("CONFIG", key="cfg_config"),
sg.Button("GENERATE", key="cfg_generate"), sg.Button("GENERATE", key="cfg_generate"),
sg.Push(), sg.Push(),
sg.Button(
"Sort: IP",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="cfg_sort_key",
),
sg.Button(
"Hashrate: 0 TH/s",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="cfg_total_hashrate",
),
sg.Button( sg.Button(
"Miners: 0", "Miners: 0",
disabled=True, disabled=True,

View File

@@ -1,5 +1,7 @@
from tools.cfg_util.layout import ( from tools.cfg_util.layout import (
MINER_COUNT_BUTTONS, MINER_COUNT_BUTTONS,
HASHRATE_TOTAL_BUTTONS,
SORT_KEY_BUTTONS,
TABLE_KEYS, TABLE_KEYS,
TABLE_HEADERS, TABLE_HEADERS,
window, window,
@@ -14,6 +16,20 @@ def update_miner_count(count):
window[button].update(f"Miners: {count}") window[button].update(f"Miners: {count}")
def update_total_hr(hashrate: float):
if hashrate > 999:
hashrate = f"{round(hashrate/1000, 2)} PH/s"
else:
hashrate = f"{round(hashrate)} TH/s"
for button in HASHRATE_TOTAL_BUTTONS:
window[button].update(f"Hashrate: {hashrate}")
def update_sort_key_btns():
for button in SORT_KEY_BUTTONS:
window[button].update(f"Sort: {TableManager().sort_key}")
def update_tables(data: list or None = None): def update_tables(data: list or None = None):
TableManager().update_data(data) TableManager().update_data(data)
@@ -22,14 +38,6 @@ def clear_tables():
TableManager().clear_tables() TableManager().clear_tables()
async def update_tree(data: list):
for item in data:
if not item.get("IP"):
continue
table_manager = TableManager()
table_manager.update_tree_by_key(item, "IP")
class Singleton(type): class Singleton(type):
_instances = {} _instances = {}
@@ -59,6 +67,7 @@ class TableManager(metaclass=Singleton):
if self.sort_key == sort_key: if self.sort_key == sort_key:
self.sort_reverse = not self.sort_reverse self.sort_reverse = not self.sort_reverse
self.sort_key = sort_key self.sort_key = sort_key
update_sort_key_btns()
self.update_tables() self.update_tables()
def update_item(self, data: dict): def update_item(self, data: dict):
@@ -122,8 +131,20 @@ class TableManager(metaclass=Singleton):
window["cmd_table"].update(treedata) window["cmd_table"].update(treedata)
update_miner_count(len(self.data)) update_miner_count(len(self.data))
total_hr = 0
for key in self.data.keys():
hashrate = 0
if not self.data[key]["Hashrate"] == "":
hashrate = (
self.data[key]["Hashrate"].replace(" ", "").replace("TH/s", "")
)
total_hr += float(hashrate)
update_total_hr(round(total_hr))
def _get_sort(self, data_key: str): def _get_sort(self, data_key: str):
if self.sort_key not in self.data[data_key]:
return ""
if self.sort_key == "IP": if self.sort_key == "IP":
return ipaddress.ip_address(self.data[data_key]["IP"]) return ipaddress.ip_address(self.data[data_key]["IP"])

View File

@@ -55,12 +55,11 @@ async def ui():
sys.exit() sys.exit()
if isinstance(event, tuple): if isinstance(event, tuple):
if len(window["scan_table"].Values) > 0: if event[0].endswith("_table"):
if event[0].endswith("_table"): if event[2][0] == -1:
if event[2][0] == -1: mgr = TableManager()
mgr = TableManager() table = window[event[0]].Widget
table = window[event[0]].Widget mgr.update_sort_key(table.heading(event[2][1])["text"])
mgr.update_sort_key(table.heading(event[2][1])["text"])
# scan tab # scan tab