refactored some code in board util
This commit is contained in:
@@ -121,81 +121,133 @@ async def refresh_data(ip_list: list):
|
|||||||
|
|
||||||
@disable_buttons
|
@disable_buttons
|
||||||
async def scan_and_get_data(network):
|
async def scan_and_get_data(network):
|
||||||
|
# update status and reset the table
|
||||||
await update_ui_with_data("status", "Scanning")
|
await update_ui_with_data("status", "Scanning")
|
||||||
await update_ui_with_data("ip_count", "")
|
await update_ui_with_data("ip_count", "")
|
||||||
await update_ui_with_data("ip_table", [])
|
await update_ui_with_data("ip_table", [])
|
||||||
|
|
||||||
|
# set progress bar length to network size
|
||||||
network_size = len(network)
|
network_size = len(network)
|
||||||
miner_generator = network.scan_network_generator()
|
|
||||||
await set_progress_bar_len(3 * network_size)
|
await set_progress_bar_len(3 * network_size)
|
||||||
progress_bar_len = 0
|
progress_bar_len = 0
|
||||||
|
|
||||||
miners = []
|
miners = []
|
||||||
async for miner in miner_generator:
|
|
||||||
|
# scan the network for miners using a generator
|
||||||
|
async for miner in network.scan_network_generator():
|
||||||
|
# the generator will either return None or an IP address
|
||||||
if miner:
|
if miner:
|
||||||
miners.append(miner)
|
miners.append(miner)
|
||||||
# can output "Identifying" for each found item, but it gets a bit cluttered
|
|
||||||
# and could possibly be confusing for the end user because of timing on
|
# add to the progress bar length after scanning an address
|
||||||
# adding the IPs
|
|
||||||
# window["ip_table"].update([["Identifying..."] for miner in miners])
|
|
||||||
progress_bar_len += 1
|
progress_bar_len += 1
|
||||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
asyncio.create_task(update_prog_bar(progress_bar_len))
|
||||||
|
|
||||||
|
# add progress for the miners that we aren't going to identify
|
||||||
progress_bar_len += network_size - len(miners)
|
progress_bar_len += network_size - len(miners)
|
||||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
asyncio.create_task(update_prog_bar(progress_bar_len))
|
||||||
get_miner_genenerator = MinerFactory().get_miner_generator(miners)
|
|
||||||
all_miners = []
|
all_miners = []
|
||||||
async for found_miner in get_miner_genenerator:
|
|
||||||
|
# identify different miner instances using the miner factory generator
|
||||||
|
async for found_miner in MinerFactory().get_miner_generator(miners):
|
||||||
|
# miner factory generator will always return a miner
|
||||||
all_miners.append(found_miner)
|
all_miners.append(found_miner)
|
||||||
|
|
||||||
|
# sort the list of miners by IP address
|
||||||
all_miners.sort(key=lambda x: x.ip)
|
all_miners.sort(key=lambda x: x.ip)
|
||||||
|
|
||||||
|
# add the new miner to the table
|
||||||
window["ip_table"].update([[str(miner.ip)] for miner in all_miners])
|
window["ip_table"].update([[str(miner.ip)] for miner in all_miners])
|
||||||
|
|
||||||
|
# update progress bar
|
||||||
progress_bar_len += 1
|
progress_bar_len += 1
|
||||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
asyncio.create_task(update_prog_bar(progress_bar_len))
|
||||||
|
|
||||||
|
# update the count of found miners
|
||||||
await update_ui_with_data("ip_count", str(len(all_miners)))
|
await update_ui_with_data("ip_count", str(len(all_miners)))
|
||||||
data_gen = asyncio.as_completed([get_formatted_data(miner) for miner in miners])
|
|
||||||
|
# update progress bar for miners we wont get data for
|
||||||
|
progress_bar_len += network_size - len(miners)
|
||||||
|
asyncio.create_task(update_prog_bar(progress_bar_len))
|
||||||
|
|
||||||
|
# get the list of IP addresses from the table
|
||||||
ip_table_data = window["ip_table"].Values
|
ip_table_data = window["ip_table"].Values
|
||||||
ordered_all_ips = [item[0] for item in ip_table_data]
|
ordered_all_ips = [item[0] for item in ip_table_data]
|
||||||
progress_bar_len += network_size - len(miners)
|
|
||||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
|
||||||
await update_ui_with_data("status", "Getting Data")
|
await update_ui_with_data("status", "Getting Data")
|
||||||
row_colors = []
|
row_colors = []
|
||||||
for all_data in data_gen:
|
|
||||||
|
# create an in place generator for getting data
|
||||||
|
for all_data in asyncio.as_completed(
|
||||||
|
[get_formatted_data(miner) for miner in miners]
|
||||||
|
):
|
||||||
|
# wait for a generator item to return
|
||||||
data_point = await all_data
|
data_point = await all_data
|
||||||
|
|
||||||
|
# make sure the IP is one we have
|
||||||
|
# this will likely never fail, but a good failsafe
|
||||||
if data_point["IP"] in ordered_all_ips:
|
if data_point["IP"] in ordered_all_ips:
|
||||||
|
# get the index of the IP in the table
|
||||||
ip_table_index = ordered_all_ips.index(data_point["IP"])
|
ip_table_index = ordered_all_ips.index(data_point["IP"])
|
||||||
|
|
||||||
board_left = ""
|
board_left = ""
|
||||||
board_center = ""
|
board_center = ""
|
||||||
board_right = ""
|
board_right = ""
|
||||||
|
|
||||||
|
# make sure we have data, some miners don't allow getting board data
|
||||||
if data_point["data"]:
|
if data_point["data"]:
|
||||||
|
|
||||||
|
# check if the 0th board (L board) is in the data
|
||||||
if 0 in data_point["data"].keys():
|
if 0 in data_point["data"].keys():
|
||||||
board_left = " ".join(
|
board_left = " ".join(
|
||||||
[chain["chip_status"] for chain in data_point["data"][0]]
|
[chain["chip_status"] for chain in data_point["data"][0]]
|
||||||
).replace("o", "•")
|
).replace("o", "•")
|
||||||
else:
|
else:
|
||||||
|
# if the board isn't in data, highlight it red
|
||||||
row_colors.append((ip_table_index, "bad"))
|
row_colors.append((ip_table_index, "bad"))
|
||||||
|
|
||||||
|
# check if the 1st board (C board) is in the data
|
||||||
if 1 in data_point["data"].keys():
|
if 1 in data_point["data"].keys():
|
||||||
board_center = " ".join(
|
board_center = " ".join(
|
||||||
[chain["chip_status"] for chain in data_point["data"][1]]
|
[chain["chip_status"] for chain in data_point["data"][1]]
|
||||||
).replace("o", "•")
|
).replace("o", "•")
|
||||||
else:
|
else:
|
||||||
|
# if the board isn't in data, highlight it red
|
||||||
row_colors.append((ip_table_index, "bad"))
|
row_colors.append((ip_table_index, "bad"))
|
||||||
|
|
||||||
|
# check if the 2nd board (R board) is in the data
|
||||||
if 2 in data_point["data"].keys():
|
if 2 in data_point["data"].keys():
|
||||||
board_right = " ".join(
|
board_right = " ".join(
|
||||||
[chain["chip_status"] for chain in data_point["data"][2]]
|
[chain["chip_status"] for chain in data_point["data"][2]]
|
||||||
).replace("o", "•")
|
).replace("o", "•")
|
||||||
else:
|
else:
|
||||||
|
# if the board isn't in data, highlight it red
|
||||||
row_colors.append((ip_table_index, "bad"))
|
row_colors.append((ip_table_index, "bad"))
|
||||||
|
|
||||||
|
# check if the miner has all nominal chips
|
||||||
if False in [
|
if False in [
|
||||||
|
# True/False if the miner is nominal
|
||||||
chain["nominal"]
|
chain["nominal"]
|
||||||
|
# for each board in the miner
|
||||||
for board in [
|
for board in [
|
||||||
data_point["data"][key] for key in data_point["data"].keys()
|
data_point["data"][key] for key in data_point["data"].keys()
|
||||||
]
|
]
|
||||||
|
# for each chain in each board in the miner
|
||||||
for chain in board
|
for chain in board
|
||||||
]:
|
]:
|
||||||
|
# if the miner doesn't have all chips, highlight it red
|
||||||
row_colors.append((ip_table_index, "bad"))
|
row_colors.append((ip_table_index, "bad"))
|
||||||
else:
|
else:
|
||||||
|
# the row is bad if we have no data
|
||||||
row_colors.append((ip_table_index, "bad"))
|
row_colors.append((ip_table_index, "bad"))
|
||||||
|
|
||||||
|
# split the chip data into thirds
|
||||||
board_left_chips = "\n".join(split_chips(board_left, 3))
|
board_left_chips = "\n".join(split_chips(board_left, 3))
|
||||||
board_center_chips = "\n".join(split_chips(board_center, 3))
|
board_center_chips = "\n".join(split_chips(board_center, 3))
|
||||||
board_right_chips = "\n".join(split_chips(board_right, 3))
|
board_right_chips = "\n".join(split_chips(board_right, 3))
|
||||||
|
|
||||||
|
# create data for the table
|
||||||
data = [
|
data = [
|
||||||
data_point["IP"],
|
data_point["IP"],
|
||||||
data_point["model"],
|
data_point["model"],
|
||||||
@@ -207,14 +259,24 @@ async def scan_and_get_data(network):
|
|||||||
len(board_right),
|
len(board_right),
|
||||||
board_right_chips,
|
board_right_chips,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# put the data at the index of the IP address
|
||||||
ip_table_data[ip_table_index] = data
|
ip_table_data[ip_table_index] = data
|
||||||
window["ip_table"].update(ip_table_data)
|
window["ip_table"].update(ip_table_data)
|
||||||
|
|
||||||
|
# configure "bad" tag to highlight red
|
||||||
table = window["ip_table"].Widget
|
table = window["ip_table"].Widget
|
||||||
table.tag_configure("bad", foreground="white", background="red")
|
table.tag_configure("bad", foreground="white", background="red")
|
||||||
|
|
||||||
|
# set tags on the row if they have been set
|
||||||
for row in row_colors:
|
for row in row_colors:
|
||||||
table.item(row[0] + 1, tags=row[1])
|
table.item(row[0] + 1, tags=row[1])
|
||||||
|
|
||||||
|
# add to the progress bar
|
||||||
progress_bar_len += 1
|
progress_bar_len += 1
|
||||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
asyncio.create_task(update_prog_bar(progress_bar_len))
|
||||||
|
|
||||||
|
# reset status
|
||||||
await update_ui_with_data("status", "")
|
await update_ui_with_data("status", "")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ async def miner_websocket(websocket: WebSocket, miner_ip):
|
|||||||
fan_speeds.append(0)
|
fan_speeds.append(0)
|
||||||
|
|
||||||
if len(miner_temp_list) == 0:
|
if len(miner_temp_list) == 0:
|
||||||
miner_temps_list = [0]
|
miner_temp_list = [0]
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"hashrate": hashrate,
|
"hashrate": hashrate,
|
||||||
|
|||||||
Reference in New Issue
Block a user