Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main/http_server/axe-os/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { AppLayoutModule } from './layout/app.layout.module';
import { ANSIPipe } from './pipes/ansi.pipe';
import { DateAgoPipe } from './pipes/date-ago.pipe';
import { HashSuffixPipe } from './pipes/hash-suffix.pipe';
import { DiffSuffixPipe } from './pipes/diff-suffix.pipe';
import { PrimeNGModule } from './prime-ng.module';
import { MessageModule } from 'primeng/message';
import { TooltipModule } from 'primeng/tooltip';
Expand Down Expand Up @@ -59,6 +60,7 @@ const components = [
SwarmComponent,
SettingsComponent,
HashSuffixPipe,
DiffSuffixPipe,
ThemeConfigComponent,
DesignComponent,
PoolComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@
<div class="flex justify-content-between mb-3">
<div>
<span class="block text-500 font-medium mb-3">Best Difficulty</span>
<div class="text-900 font-medium text-2xl">{{info.bestDiff}}
<div class="text-900 font-medium text-2xl">{{info.bestDiff | diffSuffix}}
<span class="text-500 text-lg">all-time best</span>
</div>
</div>
</div>
<span class="text-900 font-medium">{{info.bestSessionDiff}} </span>
<span class="text-900 font-medium">{{info.bestSessionDiff | diffSuffix}} </span>
<span class="text-500">since system boot</span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HttpErrorResponse } from '@angular/common/http';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { HashSuffixPipe } from 'src/app/pipes/hash-suffix.pipe';
import { DiffSuffixPipe } from 'src/app/pipes/diff-suffix.pipe';
import { ByteSuffixPipe } from 'src/app/pipes/byte-suffix.pipe';
import { QuicklinkService } from 'src/app/services/quicklink.service';
import { ShareRejectionExplanationService } from 'src/app/services/share-rejection-explanation.service';
Expand Down Expand Up @@ -436,7 +437,7 @@ export class HomeComponent implements OnInit, OnDestroy {
(info.hashRate ? HashSuffixPipe.transform(info.hashRate) : ''),
(info.temp ? `${info.temp}${info.temp2 > -1 ? `/${info.temp2}` : ''}${info.vrTemp ? `/${info.vrTemp}` : ''} °C` : ''),
(!info.power_fault ? `${info.power} W` : ''),
(info.bestDiff ? info.bestDiff : ''),
(info.bestDiff ? DiffSuffixPipe.transform(info.bestDiff) : ''),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2>Swarm</h2>
{ label: 'Total Devices', value: swarm.length },
{ label: 'Total Hashrate', value: totals.hashRate * 1000000000 | hashSuffix},
{ label: 'Total Power', value: (totals.power | number: '1.1-1') + ' W' },
{ label: 'Best Diff', value: totals.bestDiff }
{ label: 'Best Diff', value: totals.bestDiff | diffSuffix }
]">
<div class="card flex flex-column mb-0">
<span class="text-500 font-medium mb-3">{{metric.label}}</span>
Expand Down Expand Up @@ -64,10 +64,10 @@ <h2>Swarm</h2>
</td>
<td>
<p class="cursor-pointer m-0" pTooltip="Best Diff" tooltipPosition="top">
{{axe.bestDiff}}
{{axe.bestDiff | diffSuffix}}
</p>
<p class="text-500 cursor-pointer m-0" pTooltip="Best Session Diff" tooltipPosition="top">
{{axe.bestSessionDiff}}
{{axe.bestSessionDiff | diffSuffix}}
</p>
</td>
<td class="cursor-pointer" pTooltip="{{axe.uptimeSeconds | dateAgo}}" tooltipPosition="top">
Expand Down
62 changes: 37 additions & 25 deletions main/http_server/axe-os/src/app/components/swarm/swarm.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ToastrService } from 'ngx-toastr';
import { forkJoin, catchError, from, map, mergeMap, of, take, timeout, toArray, Observable } from 'rxjs';
import { LocalStorageService } from 'src/app/local-storage.service';
import { ModalComponent } from '../modal/modal.component';
import { ISystemInfo } from 'src/models/ISystemInfo';

const SWARM_DATA = 'SWARM_DATA';
const SWARM_REFRESH_TIME = 'SWARM_REFRESH_TIME';
Expand Down Expand Up @@ -33,7 +34,7 @@ export class SwarmComponent implements OnInit, OnDestroy {
public refreshIntervalTime = 30;
public refreshTimeSet = 30;

public totals: { hashRate: number; power: number; bestDiff: string } = { hashRate: 0, power: 0, bestDiff: '0' };
public totals: { hashRate: number; power: number; bestDiff: number } = { hashRate: 0, power: 0, bestDiff: 0 };

public isRefreshing = false;

Expand Down Expand Up @@ -140,12 +141,12 @@ export class SwarmComponent implements OnInit, OnDestroy {
private getAllDeviceInfo(ips: string[], errorHandler: (error: any, ip: string) => Observable<SwarmDevice[] | null>, fetchAsic: boolean = true) {
return from(ips).pipe(
mergeMap(IP => forkJoin({
info: this.httpClient.get(`http://${IP}/api/system/info`),
asic: fetchAsic ? this.httpClient.get(`http://${IP}/api/system/asic`).pipe(catchError(() => of({}))) : of({})
info: this.httpClient.get<any>(`http://${IP}/api/system/info`),
asic: fetchAsic ? this.httpClient.get<any>(`http://${IP}/api/system/asic`).pipe(catchError(() => of({}))) : of({})
}).pipe(
map(({ info, asic }) => {
const existingDevice = this.swarm.find(device => device.IP === IP);
const result = { IP, ...(existingDevice ? existingDevice : {}), ...info, ...asic };
const result = { IP, ...(existingDevice ? existingDevice : {}), ...info, ...asic, ...this.numerizeDeviceBestDiffs(info) };
return this.fallbackDeviceModel(result);
}),
timeout(5000),
Expand Down Expand Up @@ -174,7 +175,7 @@ export class SwarmComponent implements OnInit, OnDestroy {
return;
}

this.swarm.push({ IP, ...asic, ...info });
this.swarm.push({ IP, ...asic, ...info, ...this.numerizeDeviceBestDiffs(info) });
this.sortSwarm();
this.localStorageService.setObject(SWARM_DATA, this.swarm);
this.calculateTotals();
Expand Down Expand Up @@ -292,29 +293,10 @@ export class SwarmComponent implements OnInit, OnDestroy {
});
}

private compareBestDiff(a: string, b: string): string {
if (!a || a === '0') return b || '0';
if (!b || b === '0') return a;

const units = 'kMGTPE';
const unitA = units.indexOf(a.slice(-1));
const unitB = units.indexOf(b.slice(-1));

if (unitA !== unitB) {
return unitA > unitB ? a : b;
}

const valueA = parseFloat(a.slice(0, unitA >= 0 ? -1 : 0));
const valueB = parseFloat(b.slice(0, unitB >= 0 ? -1 : 0));
return valueA >= valueB ? a : b;
}

private calculateTotals() {
this.totals.hashRate = this.swarm.reduce((sum, axe) => sum + (axe.hashRate || 0), 0);
this.totals.power = this.swarm.reduce((sum, axe) => sum + (axe.power || 0), 0);
this.totals.bestDiff = this.swarm
.map(axe => axe.bestDiff || '0')
.reduce((max, curr) => this.compareBestDiff(max, curr), '0');
this.totals.bestDiff = this.swarm.reduce((max, axe) => Math.max(max, axe.bestDiff || 0), 0);
}

get deviceFamilies(): SwarmDevice[] {
Expand Down Expand Up @@ -359,4 +341,34 @@ export class SwarmComponent implements OnInit, OnDestroy {
default: return 'gray';
}
}

private numerizeDeviceBestDiffs(info: ISystemInfo) {
const parseAsNumber = (val: number | string): number => {
return typeof val === 'string' ? this.parseSuffixString(val) : val;
};

return {
bestDiff: parseAsNumber(info.bestDiff),
bestSessionDiff: parseAsNumber(info.bestSessionDiff),
};
}

private parseSuffixString(input: string): number {
input = input.trim();
const value = parseFloat(input);
const lastChar = input.charAt(input.length - 1).toUpperCase();

const multipliers: Record<string, number> = {
K: 1e3,
M: 1e6,
G: 1e9,
T: 1e12,
P: 1e15,
E: 1e18,
};

const multiplier = multipliers[lastChar] ?? 1;

return value * multiplier;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { DiffSuffixPipe } from './diff-suffix.pipe';

describe('DiffSuffixPipe', () => {
it('create an instance', () => {
const pipe = new DiffSuffixPipe();
expect(pipe).toBeTruthy();
});
});
33 changes: 33 additions & 0 deletions main/http_server/axe-os/src/app/pipes/diff-suffix.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'diffSuffix',
pure: true
})
export class DiffSuffixPipe implements PipeTransform {

private static _this = new DiffSuffixPipe();

public static transform(value: number): string {
return this._this.transform(value);
}

public transform(value: number): string {
if (value == null || value < 0) {
return '0';
}

const suffixes = ['', 'K', 'M', 'G', 'T', 'P', 'E'];

const power = Math.max(0, Math.floor(Math.log10(value) / 3));
const scaledValue = value / Math.pow(1000, power);
const suffix = suffixes[power] ?? '';
const space = suffix ? ' ' : '';

if (power > 0) {
return scaledValue.toFixed(2) + space + suffix;
} else {
return scaledValue.toFixed(0) + space + suffix;
}
}
}
6 changes: 3 additions & 3 deletions main/http_server/axe-os/src/app/services/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class SystemService {
nominalVoltage: 5,
hashRate: 475,
expectedHashrate: 420,
bestDiff: "0",
bestSessionDiff: "0",
bestDiff: 238214491,
bestSessionDiff: 21212121,
freeHeap: 200504,
coreVoltage: 1200,
coreVoltageActual: 1200,
Expand Down Expand Up @@ -67,7 +67,7 @@ export class SystemService {
fallbackStratumExtranonceSubscribe: 0,
poolDifficulty: 1000,
responseTime: 10,
isUsingFallbackStratum: true,
isUsingFallbackStratum: false,
frequency: 485,
version: "v2.9.0",
axeOSVersion: "v2.9.0",
Expand Down
4 changes: 2 additions & 2 deletions main/http_server/axe-os/src/models/ISystemInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export interface ISystemInfo {
nominalVoltage: number,
hashRate: number,
expectedHashrate: number,
bestDiff: string,
bestSessionDiff: string,
bestDiff: number,
bestSessionDiff: number,
freeHeap: number,
coreVoltage: number,
hostname: string,
Expand Down
4 changes: 2 additions & 2 deletions main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,8 @@ static esp_err_t GET_system_info(httpd_req_t * req)
cJSON_AddNumberToObject(root, "nominalVoltage", GLOBAL_STATE->DEVICE_CONFIG.family.nominal_voltage);
cJSON_AddNumberToObject(root, "hashRate", GLOBAL_STATE->SYSTEM_MODULE.current_hashrate);
cJSON_AddNumberToObject(root, "expectedHashrate", expected_hashrate);
cJSON_AddStringToObject(root, "bestDiff", GLOBAL_STATE->SYSTEM_MODULE.best_diff_string);
cJSON_AddStringToObject(root, "bestSessionDiff", GLOBAL_STATE->SYSTEM_MODULE.best_session_diff_string);
cJSON_AddNumberToObject(root, "bestDiff", GLOBAL_STATE->SYSTEM_MODULE.best_nonce_diff);
cJSON_AddNumberToObject(root, "bestSessionDiff", GLOBAL_STATE->SYSTEM_MODULE.best_session_nonce_diff);
cJSON_AddNumberToObject(root, "poolDifficulty", GLOBAL_STATE->pool_difficulty);

cJSON_AddNumberToObject(root, "isUsingFallbackStratum", GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback);
Expand Down
4 changes: 2 additions & 2 deletions main/http_server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ components:
type: number
description: Automatic fan speed control (0=manual, 1=auto)
bestDiff:
type: string
type: number
description: Best difficulty achieved
bestSessionDiff:
type: string
type: number
description: Best difficulty achieved in current session
boardVersion:
type: string
Expand Down
Loading