switch testbench to dark mode and add miner count
This commit is contained in:
@@ -29,6 +29,32 @@ if (
|
|||||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
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:
|
class TestbenchMiner:
|
||||||
def __init__(self, host: ip_address):
|
def __init__(self, host: ip_address):
|
||||||
self.host = host
|
self.host = host
|
||||||
@@ -76,14 +102,20 @@ class TestbenchMiner:
|
|||||||
try:
|
try:
|
||||||
if not await ping_miner(self.host, 80):
|
if not await ping_miner(self.host, 80):
|
||||||
await self.add_to_output("Waiting for miner connection...")
|
await self.add_to_output("Waiting for miner connection...")
|
||||||
|
miners = Miners()
|
||||||
|
miners -= self.host
|
||||||
return
|
return
|
||||||
except asyncio.exceptions.TimeoutError:
|
except asyncio.exceptions.TimeoutError:
|
||||||
await self.add_to_output("Waiting for miner connection...")
|
await self.add_to_output("Waiting for miner connection...")
|
||||||
|
miners = Miners()
|
||||||
|
miners -= self.host
|
||||||
return
|
return
|
||||||
self.start_time = datetime.datetime.now()
|
self.start_time = datetime.datetime.now()
|
||||||
await ConnectionManager().broadcast_json(
|
await ConnectionManager().broadcast_json(
|
||||||
{"IP": str(self.host), "Light": "hide", "online": self.get_online_time()}
|
{"IP": str(self.host), "Light": "hide", "online": self.get_online_time()}
|
||||||
)
|
)
|
||||||
|
miners = Miners()
|
||||||
|
miners += self.host
|
||||||
await self.remove_from_cache()
|
await self.remove_from_cache()
|
||||||
miner = await MinerFactory().get_miner(self.host)
|
miner = await MinerFactory().get_miner(self.host)
|
||||||
await self.add_to_output("Found miner: " + str(miner))
|
await self.add_to_output("Found miner: " + str(miner))
|
||||||
@@ -339,6 +371,7 @@ class TestbenchMiner:
|
|||||||
"Temps": temps_data,
|
"Temps": temps_data,
|
||||||
"online": self.get_online_time(),
|
"online": self.get_online_time(),
|
||||||
"Tuner": tuner_data,
|
"Tuner": tuner_data,
|
||||||
|
"Count": Miners().get_count()
|
||||||
}
|
}
|
||||||
|
|
||||||
# return stats
|
# return stats
|
||||||
@@ -369,6 +402,7 @@ class TestbenchMiner:
|
|||||||
"board_7": {"power_limit": 275, "real_power": 0, "status": "None"},
|
"board_7": {"power_limit": 275, "real_power": 0, "status": "None"},
|
||||||
"board_8": {"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):
|
async def install_done(self):
|
||||||
@@ -385,6 +419,7 @@ class TestbenchMiner:
|
|||||||
"IP": str(self.host),
|
"IP": str(self.host),
|
||||||
"Light": "show",
|
"Light": "show",
|
||||||
"online": self.get_online_time(),
|
"online": self.get_online_time(),
|
||||||
|
"Count": Miners().get_count()
|
||||||
}
|
}
|
||||||
print(f"Getting data failed: {self.host}")
|
print(f"Getting data failed: {self.host}")
|
||||||
|
|
||||||
@@ -422,6 +457,14 @@ class TestbenchMiner:
|
|||||||
await self.install_done()
|
await self.install_done()
|
||||||
if self.state == ERROR:
|
if self.state == ERROR:
|
||||||
await self.wait_for_disconnect(wait_time=5)
|
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:
|
except Exception as E:
|
||||||
logging.error(f"{self.host}: {E}")
|
logging.error(f"{self.host}: {E}")
|
||||||
await self.add_to_output(f"Error: {E}")
|
await self.add_to_output(f"Error: {E}")
|
||||||
|
|||||||
@@ -9,8 +9,15 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Title</title>
|
<title>Title</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body class="bg-dark">
|
||||||
<div class="py-2">
|
<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 class="container">
|
||||||
<div id="chart_container" class="row row-cols-1 row-cols-sm-2 row-cols-md-4" style="height:1500px;"></div>
|
<div id="chart_container" class="row row-cols-1 row-cols-sm-2 row-cols-md-4" style="height:1500px;"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -29,8 +36,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
scales: {
|
scales: {
|
||||||
|
x: {ticks: { color: "white" }},
|
||||||
y: {
|
y: {
|
||||||
ticks: { stepSize: .6 },
|
ticks: { stepSize: .6, color: "white" },
|
||||||
min: 0,
|
min: 0,
|
||||||
suggestedMax: 3.6,
|
suggestedMax: 3.6,
|
||||||
grid: {
|
grid: {
|
||||||
@@ -59,6 +67,11 @@ var options_temp = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
aspectRatio: .75,
|
aspectRatio: .75,
|
||||||
|
scales: {
|
||||||
|
x: {ticks: { color: "white" }},
|
||||||
|
y: {ticks: { color: "white" }}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var options_fans = {
|
var options_fans = {
|
||||||
@@ -89,6 +102,10 @@ function lightMiner(ip, checkbox) {
|
|||||||
};
|
};
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function(event) {
|
||||||
var data = JSON.parse(event.data)
|
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")) {
|
if (data.hasOwnProperty("online")) {
|
||||||
timer = document.getElementById(data["IP"] + "-timer")
|
timer = document.getElementById(data["IP"] + "-timer")
|
||||||
if (data["online"] == "0:00:00") {
|
if (data["online"] == "0:00:00") {
|
||||||
@@ -275,6 +292,7 @@ ws.onmessage = function(event) {
|
|||||||
var label_light = document.createElement("label");
|
var label_light = document.createElement("label");
|
||||||
label_light.setAttribute("for", miner["IP"] + "-light");
|
label_light.setAttribute("for", miner["IP"] + "-light");
|
||||||
label_light.innerHTML = "Light";
|
label_light.innerHTML = "Light";
|
||||||
|
label_light.classList = "text-light"
|
||||||
|
|
||||||
// add the button and label to the container
|
// add the button and label to the container
|
||||||
container_light.append(light_switch)
|
container_light.append(light_switch)
|
||||||
@@ -313,7 +331,7 @@ ws.onmessage = function(event) {
|
|||||||
backgroundColor: [
|
backgroundColor: [
|
||||||
"rgba(103, 0, 221, 1)",
|
"rgba(103, 0, 221, 1)",
|
||||||
"rgba(199, 199, 199, 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_rpm = data["Fans"]["fan_0"]["RPM"]
|
||||||
var fan_1_title = document.getElementById(data["IP"] + "-fan_l");
|
var fan_1_title = document.getElementById(data["IP"] + "-fan_l");
|
||||||
fan_1_title.innerHTML = "Fan L: " + fan_1_rpm + " RPM";
|
fan_1_title.innerHTML = "Fan L: " + fan_1_rpm + " RPM";
|
||||||
|
fan_1_title.classList = "text-light"
|
||||||
if (fan_1_rpm == 0){
|
if (fan_1_rpm == 0){
|
||||||
var secondary_col_1 = "rgba(97, 4, 4, 1)"
|
var secondary_col_1 = "rgba(97, 4, 4, 1)"
|
||||||
} else {
|
} else {
|
||||||
@@ -387,6 +406,7 @@ ws.onmessage = function(event) {
|
|||||||
var fan_2_rpm = data["Fans"]["fan_1"]["RPM"]
|
var fan_2_rpm = data["Fans"]["fan_1"]["RPM"]
|
||||||
var fan_2_title = document.getElementById(data["IP"] + "-fan_r");
|
var fan_2_title = document.getElementById(data["IP"] + "-fan_r");
|
||||||
fan_2_title.innerHTML = "Fan R: " + fan_2_rpm + " RPM";
|
fan_2_title.innerHTML = "Fan R: " + fan_2_rpm + " RPM";
|
||||||
|
fan_2_title.classList = "text-light"
|
||||||
if (fan_2_rpm == 0){
|
if (fan_2_rpm == 0){
|
||||||
var secondary_col_2 = "rgba(97, 4, 4, 1)"
|
var secondary_col_2 = "rgba(97, 4, 4, 1)"
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user