Skip to content

Commit

Permalink
Use api v3
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbrucker committed Nov 14, 2023
1 parent 80e2ba7 commit 4232911
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/app/api/abstract-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export abstract class AbstractApi<
protected readonly client: AxiosInstance

public constructor(poolIdentifier: string) {
this.client = axios.create({ baseURL: `https://api2.foxypool.io/api/v2/${poolIdentifier}` })
this.client = axios.create({ baseURL: `https://api2.foxypool.io/api/v3/${poolIdentifier}` })
}

public async getPoolConfig(): Promise<PoolConfig> {
Expand Down
22 changes: 6 additions & 16 deletions src/app/api/types/harvester/harvester-stats.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
interface SubmissionStat {
export interface HistoricalSubmissionStat {
shares: number
staleShares: number
invalidShares: number
partials: number
proofTimeSumInSeconds: number|null
date: string
proofTimeInSeconds: number|null
receivedAt: string
}

export enum RejectedSubmissionType {
stale = 'STALE',
invalid = 'INVALID',
}

interface RejectedSubmissionStat extends SubmissionStat {
type: RejectedSubmissionType
}

export interface HarvesterStats {
submissionStats: SubmissionStat[]
rejectedSubmissionStats: RejectedSubmissionStat[]
}
export type HarvesterStats = HistoricalSubmissionStat[]
2 changes: 1 addition & 1 deletion src/app/harvester-card/harvester-card.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h5>{{lastAcceptedPartialAt}}</h5>
<div echarts [options]="proofTimesChartOptions" [merge]="proofTimesChartUpdateOptions" theme="default" class="proof-times-chart"></div>
</div>
<div class="col-12 text-center mt-3" *ngIf="(hasProofTimes | async) === false && (isLoadingProofTimes | async) === false">
<app-empty-state text="No proof times recorded in the last 24h" [icon]="faReceipt"></app-empty-state>
<app-empty-state text="No proof times recorded in the last {{selectedHistoricalStatsDuration}}" [icon]="faReceipt"></app-empty-state>
</div>
<div class="col-12 text-center mt-3" *ngIf="isLoadingProofTimes | async">
<app-loading-state [height]="3" [width]="3"></app-loading-state>
Expand Down
74 changes: 21 additions & 53 deletions src/app/harvester-card/harvester-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Capacity from '../capacity'
import {EChartsOption} from 'echarts'
import {faEllipsisV, faPencil, faReceipt} from '@fortawesome/free-solid-svg-icons'
import {HarvesterSettingsModalComponent} from '../harvester-settings-modal/harvester-settings-modal.component'
import {HarvesterStats, RejectedSubmissionType} from '../api/types/harvester/harvester-stats'
import {HarvesterStats} from '../api/types/harvester/harvester-stats'
import {ProofTime} from '../api/types/harvester/proof-time'
import {Harvester} from '../api/types/harvester/harvester'
import {PoolsProvider, PoolType} from '../pools.provider'
Expand All @@ -21,7 +21,7 @@ import {HarvesterStatus} from '../status/harvester-status'
import {LastUpdatedState} from '../status/last-updated-state'
import {colors, Theme, ThemeProvider} from '../theme-provider'
import {
durationInDays, getResolutionInMinutes,
durationInDays, getResolutionInMinutes, HistoricalStatsDuration,
} from '../api/types/historical-stats-duration'
import {HistoricalStatsDurationProvider} from '../historical-stats-duration-provider'
import {
Expand Down Expand Up @@ -88,6 +88,10 @@ export class HarvesterCardComponent implements OnInit, OnDestroy {
return this.accountService.account?.integrations?.chiaDashboardShareKey !== undefined
}

public get selectedHistoricalStatsDuration(): HistoricalStatsDuration {
return this.historicalStatsDurationProvider.selectedDuration
}

private get historicalIntervalInMinutes(): number {
return getResolutionInMinutes(this.historicalStatsDurationProvider.selectedDuration)
}
Expand Down Expand Up @@ -130,7 +134,7 @@ export class HarvesterCardComponent implements OnInit, OnDestroy {
this.isLoading = this.statsSubject.asObservable().pipe(map(stats => stats === undefined), distinctUntilChanged(), shareReplay())
this.averageEc = this.stats.pipe(
map(stats => {
const totalShares = stats.submissionStats.reduce((acc, submissionStat) => acc.plus(submissionStat.shares), new BigNumber(0))
const totalShares = stats.reduce((acc, submissionStat) => acc.plus(submissionStat.shares), new BigNumber(0))
const ecInGib = totalShares
.dividedBy(sharesPerDayPerK32 * durationInDays(this.historicalStatsDurationProvider.selectedDuration))
.multipliedBy(k32SizeInGib)
Expand All @@ -140,19 +144,14 @@ export class HarvesterCardComponent implements OnInit, OnDestroy {
)
const averageProofTimeInSeconds = this.stats.pipe(
map(stats => {
const averageProofTimes = stats.submissionStats
.map(stat => ({ partials: stat.partials, proofTimeSumInSeconds: stat.proofTimeSumInSeconds }))
.concat(stats.rejectedSubmissionStats.map(stat => ({ partials: stat.partials, proofTimeSumInSeconds: stat.proofTimeSumInSeconds })))
.filter(stat => stat.proofTimeSumInSeconds !== null && stat.partials > 0)

const totalPartials = averageProofTimes.reduce((acc, curr) => acc.plus(curr.partials), new BigNumber(0))
if (totalPartials.isZero()) {
return undefined
const averageProofTimes = stats.filter(stat => stat.proofTimeInSeconds !== null)
if (averageProofTimes.length === 0) {
return
}

return averageProofTimes
.reduce((acc, curr) => acc.plus(curr.proofTimeSumInSeconds), new BigNumber(0))
.dividedBy(totalPartials)
.reduce((acc, curr) => acc.plus(curr.proofTimeInSeconds), new BigNumber(0))
.dividedBy(averageProofTimes.length)
}),
shareReplay(),
)
Expand Down Expand Up @@ -346,13 +345,9 @@ export class HarvesterCardComponent implements OnInit, OnDestroy {
const sharesStream = this.stats
.pipe(
map(harvesterStats => {
const totalValidShares = harvesterStats.submissionStats.reduce((acc, curr) => acc.plus(curr.shares), new BigNumber(0))
const totalInvalidShares = harvesterStats.rejectedSubmissionStats
.filter(stat => stat.type === RejectedSubmissionType.invalid)
.reduce((acc, curr) => acc.plus(curr.shares), new BigNumber(0))
const totalStaleShares = harvesterStats.rejectedSubmissionStats
.filter(stat => stat.type === RejectedSubmissionType.stale)
.reduce((acc, curr) => acc.plus(curr.shares), new BigNumber(0))
const totalValidShares = harvesterStats.reduce((acc, curr) => acc.plus(curr.shares), new BigNumber(0))
const totalInvalidShares = harvesterStats.reduce((acc, curr) => acc.plus(curr.invalidShares), new BigNumber(0))
const totalStaleShares = harvesterStats.reduce((acc, curr) => acc.plus(curr.staleShares), new BigNumber(0))
const totalShares = totalValidShares.plus(totalInvalidShares).plus(totalStaleShares)

return {
Expand Down Expand Up @@ -701,34 +696,12 @@ export class HarvesterCardComponent implements OnInit, OnDestroy {
}

private makeSharesChartUpdateOptions(stats: HarvesterStats): EChartsOption {
const validSharesSeries = stats.submissionStats.map(stats => [stats.date, stats.shares])
const staleSharesSeries = stats.rejectedSubmissionStats
.filter(stat => stat.type === RejectedSubmissionType.stale)
.map(stats => [stats.date, stats.shares])
const invalidSharesSeries = stats.rejectedSubmissionStats
.filter(stat => stat.type === RejectedSubmissionType.invalid)
.map(stats => [stats.date, stats.shares])

const proofTimeSumsByDate = new Map<string, ProofTimeSum[]>()
stats.submissionStats.forEach(stat => {
if (stat.proofTimeSumInSeconds !== null && stat.partials > 0) {
const proofTimeSumsForDate = proofTimeSumsByDate.get(stat.date) ?? []
proofTimeSumsForDate.push({ partials: stat.partials, proofTimeSumInSeconds: stat.proofTimeSumInSeconds })
proofTimeSumsByDate.set(stat.date, proofTimeSumsForDate)
}
})
stats.rejectedSubmissionStats.forEach(stat => {
if (stat.proofTimeSumInSeconds !== null && stat.partials > 0) {
const proofTimeSumsForDate = proofTimeSumsByDate.get(stat.date) ?? []
proofTimeSumsForDate.push({ partials: stat.partials, proofTimeSumInSeconds: stat.proofTimeSumInSeconds })
proofTimeSumsByDate.set(stat.date, proofTimeSumsForDate)
}
})
const averageProofTimes = Array
.from(proofTimeSumsByDate)
.map(([date, proofTimeSums]) => ({ date, averageProofTime: proofTimeSums.reduce((acc, curr) => acc + curr.proofTimeSumInSeconds, 0) / proofTimeSums.reduce((acc, curr) => acc + curr.partials, 0) }))
averageProofTimes.sort((lhs, rhs) => (new Date(lhs.date)).getTime() - (new Date(rhs.date)).getTime())
const averageProofTimesSeries = averageProofTimes.map(stat => [stat.date, stat.averageProofTime])
const validSharesSeries = stats.map(stats => [stats.receivedAt, stats.shares])
const staleSharesSeries = stats.map(stats => [stats.receivedAt, stats.staleShares])
const invalidSharesSeries = stats.map(stats => [stats.receivedAt, stats.invalidShares])
const averageProofTimesSeries = stats
.filter(stat => stat.proofTimeInSeconds !== null)
.map(stat => [stat.receivedAt, stat.proofTimeInSeconds])

const roundToNextLower15Min = (date: Moment): Moment => {
const minutesRoundedDown = Math.floor(date.minutes() / 15) * 15
Expand Down Expand Up @@ -881,11 +854,6 @@ export class HarvesterCardComponent implements OnInit, OnDestroy {
}
}

interface ProofTimeSum {
proofTimeSumInSeconds: number
partials: number
}

enum ChartMode {
shares = 'shares',
proofTimes = 'proofTimes',
Expand Down

0 comments on commit 4232911

Please sign in to comment.