switch testbench to dark mode and add miner count

This commit is contained in:
UpstreamData
2022-05-19 10:47:36 -06:00
parent 0a4d52ef03
commit 6abfe8a503
2 changed files with 67 additions and 4 deletions

View File

@@ -29,6 +29,32 @@ if (
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class Miners(metaclass=Singleton):
def __init__(self):
self.miners = []
def get_count(self):
return len(self.miners)
def __add__(self, other):
if other not in self.miners:
self.miners.append(other)
def __sub__(self, other):
if other in self.miners:
self.miners.remove(other)
class TestbenchMiner:
def __init__(self, host: ip_address):
self.host = host
@@ -76,14 +102,20 @@ class TestbenchMiner:
try:
if not await ping_miner(self.host, 80):
await self.add_to_output("Waiting for miner connection...")
miners = Miners()
miners -= self.host
return
except asyncio.exceptions.TimeoutError:
await self.add_to_output("Waiting for miner connection...")
miners = Miners()
miners -= self.host
return
self.start_time = datetime.datetime.now()
await ConnectionManager().broadcast_json(
{"IP": str(self.host), "Light": "hide", "online": self.get_online_time()}
)
miners = Miners()
miners += self.host
await self.remove_from_cache()
miner = await MinerFactory().get_miner(self.host)
await self.add_to_output("Found miner: " + str(miner))
@@ -339,6 +371,7 @@ class TestbenchMiner:
"Temps": temps_data,
"online": self.get_online_time(),
"Tuner": tuner_data,
"Count": Miners().get_count()
}
# return stats
@@ -369,6 +402,7 @@ class TestbenchMiner:
"board_7": {"power_limit": 275, "real_power": 0, "status": "None"},
"board_8": {"power_limit": 275, "real_power": 0, "status": "None"},
},
"Count": Miners().get_count()
}
async def install_done(self):
@@ -385,6 +419,7 @@ class TestbenchMiner:
"IP": str(self.host),
"Light": "show",
"online": self.get_online_time(),
"Count": Miners().get_count()
}
print(f"Getting data failed: {self.host}")
@@ -422,6 +457,14 @@ class TestbenchMiner:
await self.install_done()
if self.state == ERROR:
await self.wait_for_disconnect(wait_time=5)
except GeneratorExit as E:
logging.error(f"{self.host}: {E}")
await self.add_to_output(f"Error: {E}")
except RuntimeError as E:
logging.error(f"{self.host}: {E}")
await self.add_to_output(f"Error: {E}")
asyncio.create_task(self.install_loop())
return
except Exception as E:
logging.error(f"{self.host}: {E}")
await self.add_to_output(f"Error: {E}")

View File

@@ -9,8 +9,15 @@
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="py-2">
<body class="bg-dark">
<div class="container d-flex justify-content-center mb-0 px-0">
<div class="row w-100 border border-dark p-3 row bg-dark">
<div class="col d-flex justify-content-center">
<h3 class="text-white" id="miner_count">Miners Online: ??</h3>
</div>
</div>
</div>
<div class="py-2 mt-0 pt-0">
<div class="container">
<div id="chart_container" class="row row-cols-1 row-cols-sm-2 row-cols-md-4" style="height:1500px;"></div>
</div>
@@ -29,8 +36,9 @@
}
},
scales: {
x: {ticks: { color: "white" }},
y: {
ticks: { stepSize: .6 },
ticks: { stepSize: .6, color: "white" },
min: 0,
suggestedMax: 3.6,
grid: {
@@ -59,6 +67,11 @@ var options_temp = {
}
},
aspectRatio: .75,
scales: {
x: {ticks: { color: "white" }},
y: {ticks: { color: "white" }}
}
};
var options_fans = {
@@ -89,6 +102,10 @@ function lightMiner(ip, checkbox) {
};
ws.onmessage = function(event) {
var data = JSON.parse(event.data)
if (data.hasOwnProperty("Count")) {
count = document.getElementById("miner_count")
count.innerHTML = "Miners Online: " + data["Count"]
}
if (data.hasOwnProperty("online")) {
timer = document.getElementById(data["IP"] + "-timer")
if (data["online"] == "0:00:00") {
@@ -275,6 +292,7 @@ ws.onmessage = function(event) {
var label_light = document.createElement("label");
label_light.setAttribute("for", miner["IP"] + "-light");
label_light.innerHTML = "Light";
label_light.classList = "text-light"
// add the button and label to the container
container_light.append(light_switch)
@@ -313,7 +331,7 @@ ws.onmessage = function(event) {
backgroundColor: [
"rgba(103, 0, 221, 1)",
"rgba(199, 199, 199, 1)"
]
],
},
]
},
@@ -374,6 +392,7 @@ ws.onmessage = function(event) {
var fan_1_rpm = data["Fans"]["fan_0"]["RPM"]
var fan_1_title = document.getElementById(data["IP"] + "-fan_l");
fan_1_title.innerHTML = "Fan L: " + fan_1_rpm + " RPM";
fan_1_title.classList = "text-light"
if (fan_1_rpm == 0){
var secondary_col_1 = "rgba(97, 4, 4, 1)"
} else {
@@ -387,6 +406,7 @@ ws.onmessage = function(event) {
var fan_2_rpm = data["Fans"]["fan_1"]["RPM"]
var fan_2_title = document.getElementById(data["IP"] + "-fan_r");
fan_2_title.innerHTML = "Fan R: " + fan_2_rpm + " RPM";
fan_2_title.classList = "text-light"
if (fan_2_rpm == 0){
var secondary_col_2 = "rgba(97, 4, 4, 1)"
} else {