mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-03-17 13:22:53 +01:00
fix: Swarm hashRate check, shorter uptime, & pause refresh on scan (#560)
* fix: Only add devices that have a hashRate property * fix: Allow shorter dates & use for swarm uptime * fix: Pause & don't refresh swarm while scanning
This commit is contained in:
parent
c4dc297c40
commit
94cc0f07f1
@ -26,7 +26,6 @@
|
||||
<p-slider id="refresh-interval" class="pl-2 pr-2"
|
||||
[min]="5"
|
||||
[max]="30"
|
||||
[(ngModel)]="refreshTimeSet"
|
||||
[style]="{'width': '150px'}"
|
||||
[formControl]="refreshIntervalControl">
|
||||
</p-slider>
|
||||
@ -68,7 +67,7 @@
|
||||
<div class="text-sm">{{axe.hostname}}</div>
|
||||
</td>
|
||||
<td>{{axe.hashRate * 1000000000 | hashSuffix}}</td>
|
||||
<td>{{axe.uptimeSeconds | dateAgo}}</td>
|
||||
<td>{{axe.uptimeSeconds | dateAgo: {intervals: 2} }}</td>
|
||||
<td>
|
||||
<div class="w-min cursor-pointer"
|
||||
pTooltip="Shares Accepted"
|
||||
|
@ -63,14 +63,13 @@ export class SwarmComponent implements OnInit, OnDestroy {
|
||||
|
||||
if (swarmData == null) {
|
||||
this.scanNetwork();
|
||||
//this.swarm$ = this.scanNetwork('192.168.1.23', '255.255.255.0').pipe(take(1));
|
||||
} else {
|
||||
this.swarm = swarmData;
|
||||
this.refreshList();
|
||||
}
|
||||
|
||||
this.refreshIntervalRef = window.setInterval(() => {
|
||||
if (!this.isRefreshing) {
|
||||
if (!this.scanning && !this.isRefreshing) {
|
||||
this.refreshIntervalTime--;
|
||||
if (this.refreshIntervalTime <= 0) {
|
||||
this.refreshList();
|
||||
@ -84,8 +83,6 @@ export class SwarmComponent implements OnInit, OnDestroy {
|
||||
this.form.reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ipToInt(ip: string): number {
|
||||
return ip.split('.').reduce((acc, octet) => (acc << 8) + parseInt(octet, 10), 0) >>> 0;
|
||||
}
|
||||
@ -111,12 +108,15 @@ export class SwarmComponent implements OnInit, OnDestroy {
|
||||
mergeMap(ipAddr =>
|
||||
this.httpClient.get(`http://${ipAddr}/api/system/info`).pipe(
|
||||
map(result => {
|
||||
return {
|
||||
IP: ipAddr,
|
||||
...result
|
||||
if ('hashRate' in result) {
|
||||
return {
|
||||
IP: ipAddr,
|
||||
...result
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
timeout(5000), // Set the timeout to 1 second
|
||||
timeout(5000), // Set the timeout to 5 seconds
|
||||
catchError(error => {
|
||||
//console.error(`Request to ${ipAddr}/api/system/info failed or timed out`, error);
|
||||
return []; // Return an empty result or handle as desired
|
||||
@ -127,9 +127,11 @@ export class SwarmComponent implements OnInit, OnDestroy {
|
||||
toArray() // Collect all results into a single array
|
||||
).pipe(take(1)).subscribe({
|
||||
next: (result) => {
|
||||
// Filter out null items first
|
||||
const validResults = result.filter((item): item is NonNullable<typeof item> => item !== null);
|
||||
// Merge new results with existing swarm entries
|
||||
const existingIps = new Set(this.swarm.map(item => item.IP));
|
||||
const newItems = result.filter(item => !existingIps.has(item.IP));
|
||||
const newItems = validResults.filter(item => !existingIps.has(item.IP));
|
||||
this.swarm = [...this.swarm, ...newItems].sort(this.sortByIp.bind(this));
|
||||
this.localStorageService.setObject(SWARM_DATA, this.swarm);
|
||||
this.calculateTotals();
|
||||
@ -184,6 +186,10 @@ export class SwarmComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
public refreshList() {
|
||||
if (this.scanning) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.refreshIntervalTime = this.refreshTimeSet;
|
||||
const ips = this.swarm.map(axeOs => axeOs.IP);
|
||||
this.isRefreshing = true;
|
||||
|
@ -22,9 +22,11 @@ export class DateAgoPipe implements PipeTransform {
|
||||
'second': 1
|
||||
};
|
||||
let result = '';
|
||||
let shownIntervals = 0;
|
||||
for (const i in intervals) {
|
||||
if (args?.intervals && shownIntervals >= args.intervals) break;
|
||||
const counter = Math.floor(seconds / intervals[i]);
|
||||
if (counter > 0)
|
||||
if (counter > 0) {
|
||||
if (counter === 1) {
|
||||
if (result) result += ', '
|
||||
result += counter + ' ' + i + ''; // singular (1 day ago)
|
||||
@ -34,6 +36,8 @@ export class DateAgoPipe implements PipeTransform {
|
||||
result += counter + ' ' + i + 's'; // plural (2 days ago)
|
||||
seconds -= intervals[i] * counter
|
||||
}
|
||||
shownIntervals++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user