added temperatures to the tool, and fixed a bug with multicommand not removing bad commands if they were adjacent to each other in the list

This commit is contained in:
UpstreamData
2022-01-05 15:33:56 -07:00
parent e77cbc5415
commit 1148946a29
6 changed files with 42 additions and 44 deletions

View File

@@ -42,14 +42,9 @@ class BaseMinerAPI:
"""Creates and sends multiple commands as one command to the miner."""
# split the commands into a proper list
commands = [*commands]
for item in commands:
# make sure we can actually run the command, otherwise it will fail
if item not in self.get_commands():
# if the command isn't allowed, remove it
print(f"Removing incorrect command: {item}")
commands.remove(item)
allowed_commands = self.get_commands()
# make sure we can actually run the command, otherwise it will fail
commands = [command for command in commands if command in allowed_commands]
# standard multicommand format is "command1+command2"
# doesnt work for S19 which is dealt with in the send command function
command = "+".join(commands)

View File

@@ -525,24 +525,10 @@ class BTMinerAPI(BaseMinerAPI):
"""
return await self.send_command("status")
async def get_miner_info(self, info: str | list):
async def get_miner_info(self):
"""
API 'get_miner_info' command.
Returns a dict containing requested information.
Parameters:
info: the info that you want to get.
"ip",
"proto",
"netmask",
"gateway",
"dns",
"hostname",
"mac",
"ledstat".
Returns a dict containing general miner info.
"""
if isinstance(info, str):
return await self.send_command("get_miner_info", parameters=info)
else:
return await self.send_command("get_miner_info", parameters=f"{','.join([str(item) for item in info])}")
return await self.send_command("get_miner_info")

View File

@@ -120,7 +120,7 @@ async def get_data(ip_list: list):
if data_point["IP"] in ordered_all_ips:
ip_table_index = ordered_all_ips.index(data_point["IP"])
ip_table_data[ip_table_index] = [
data_point["IP"], data_point["host"], str(data_point['TH/s']) + " TH/s", data_point['user'], str(data_point['wattage']) + " W"
data_point["IP"], data_point["host"], str(data_point['TH/s']) + " TH/s", data_point["temp"], data_point['user'], str(data_point['wattage']) + " W"
]
window["ip_table"].update(ip_table_data)
progress_bar_len += 1
@@ -136,18 +136,11 @@ async def get_data(ip_list: list):
async def get_formatted_data(ip: ipaddress.ip_address):
miner = await miner_factory.get_miner(ip)
try:
miner_data = await miner.api.multicommand("summary", "pools", "tunerstatus")
miner_data = await miner.api.multicommand("summary", "devs", "temps", "tunerstatus", "pools")
except APIError:
return {'TH/s': "Unknown", 'IP': str(miner.ip), 'host': "Unknown", 'user': "Unknown", 'wattage': 0}
host = await miner.get_hostname()
if "tunerstatus" in miner_data.keys():
wattage = await safe_parse_api_data(miner_data, "tunerstatus", 0, 'TUNERSTATUS', 0, "PowerLimit")
# data['tunerstatus'][0]['TUNERSTATUS'][0]['PowerLimit']
elif "Power" in miner_data["summary"][0]["SUMMARY"][0].keys():
wattage = await safe_parse_api_data(miner_data, "summary", 0, 'SUMMARY', 0, "Power")
else:
print(miner_data)
wattage = 0
if "summary" in miner_data.keys():
if 'MHS 5s' in miner_data['summary'][0]['SUMMARY'][0].keys():
th5s = round(await safe_parse_api_data(miner_data, 'summary', 0, 'SUMMARY', 0, 'MHS 5s') / 1000000, 2)
@@ -161,13 +154,36 @@ async def get_formatted_data(ip: ipaddress.ip_address):
th5s = 0
else:
th5s = 0
temps = 0
if "temps" in miner_data.keys() and not miner_data["temps"][0]['TEMPS'] == []:
if "Chip" in miner_data["temps"][0]['TEMPS'][0].keys():
for board in miner_data["temps"][0]['TEMPS']:
if board["Chip"] is not None and not board["Chip"] == 0.0:
temps = board["Chip"]
elif "devs" in miner_data.keys() and not miner_data["devs"][0]['DEVS'] == []:
if "Chip Temp Avg" in miner_data["devs"][0]['DEVS'][0].keys():
for board in miner_data["devs"][0]['DEVS']:
if board['Chip Temp Avg'] is not None and not board['Chip Temp Avg'] == 0.0:
temps = board['Chip Temp Avg']
if "pools" not in miner_data.keys():
user = "?"
elif not miner_data['pools'][0]['POOLS'] == []:
user = await safe_parse_api_data(miner_data, 'pools', 0, 'POOLS', 0, 'User')
else:
user = "Blank"
return {'TH/s': th5s, 'IP': str(miner.ip), 'host': host, 'user': user, 'wattage': wattage}
if "tunerstatus" in miner_data.keys():
wattage = await safe_parse_api_data(miner_data, "tunerstatus", 0, 'TUNERSTATUS', 0, "PowerLimit")
# data['tunerstatus'][0]['TUNERSTATUS'][0]['PowerLimit']
elif "Power" in miner_data["summary"][0]["SUMMARY"][0].keys():
wattage = await safe_parse_api_data(miner_data, "summary", 0, 'SUMMARY', 0, "Power")
else:
wattage = 0
return {'TH/s': th5s, 'IP': str(miner.ip), 'temp': round(temps), 'host': host, 'user': user, 'wattage': wattage}
async def generate_config(username, workername, v2_allowed):

View File

@@ -29,25 +29,25 @@ async def sort_data(index: int or str):
data_list = window['ip_table'].Values
# wattage
if re.match("[0-9]* W", data_list[0][index]):
if re.match("[0-9]* W", str(data_list[0][index])):
new_list = sorted(data_list, key=lambda x: int(x[index].replace(" W", "")))
if data_list == new_list:
new_list = sorted(data_list, reverse=True, key=lambda x: int(x[index].replace(" W", "")))
# hashrate
elif re.match("[0-9]*\.?[0-9]* TH\/s", data_list[0][index]):
elif re.match("[0-9]*\.?[0-9]* TH\/s", str(data_list[0][index])):
new_list = sorted(data_list, key=lambda x: float(x[index].replace(" TH/s", "")))
if data_list == new_list:
new_list = sorted(data_list, reverse=True, key=lambda x: float(x[index].replace(" TH/s", "")))
# ip addresses
elif re.match("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)",
data_list[0][index]):
str(data_list[0][index])):
new_list = sorted(data_list, key=lambda x: ipaddress.ip_address(x[index]))
if data_list == new_list:
new_list = sorted(data_list, reverse=True, key=lambda x: ipaddress.ip_address(x[index]))
# everything else, hostname and user
# everything else, hostname, temp, and user
else:
new_list = sorted(data_list, key=lambda x: x[index])
if data_list == new_list:

View File

@@ -24,12 +24,12 @@ layout = [
])],
[sg.Table(
values=[],
headings=["IP", "Hostname", "Hashrate", "Current User", "Wattage"],
headings=["IP", "Hostname", "Hashrate", "Temperature", "Current User", "Wattage"],
auto_size_columns=False,
max_col_width=15,
justification="center",
key="ip_table",
col_widths=[14, 14, 14, 26, 7],
col_widths=[12, 12, 12, 10, 22, 7],
background_color="white",
text_color="black",
size=(105, 27),

View File

@@ -13,8 +13,9 @@ class BTMiner(BaseMiner):
async def get_hostname(self) -> str:
try:
host_data = await self.api.get_miner_info("hostname")
print(host_data)
host_data = await self.api.get_miner_info()
if host_data:
return host_data["Msg"]["hostname"]
except APIError:
return "BTMiner Unknown"