Skip to content

Feature/graphs update 3 #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ pids
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
/prisma/generated/
/prismaDmob/generated/

start_dmob_tunnel.sh
41 changes: 29 additions & 12 deletions src/service/allocator/allocator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,22 @@ export class AllocatorService {
): Promise<AllocatorSpsComplianceWeekResponse> {
const weeks = await this.storageProviderService.getWeeksTracked();

const lastWeek = DateTime.now()
.toUTC()
.minus({ week: 1 })
.startOf('week')
.toJSDate();

const lastWeekAverageProviderRetrievability =
await this.storageProviderService.getWeekAverageProviderRetrievability(
lastWeek,
isAccumulative,
);

const results: AllocatorSpsComplianceWeek[] = [];

for (const week of weeks) {
const weekAverageRetrievability =
const weekAverageProvidersRetrievability =
await this.storageProviderService.getWeekAverageProviderRetrievability(
week,
isAccumulative,
Expand All @@ -125,12 +137,13 @@ export class AllocatorService {
);

const weekProvidersCompliance: {
// TODO refactor to a type
complianceScore: number;
provider: string;
}[] = weekProviders.map((provider) => {
return this.storageProviderService.getWeekProviderComplianceScore(
provider,
weekAverageRetrievability,
weekAverageProvidersRetrievability,
);
});

Expand All @@ -144,10 +157,11 @@ export class AllocatorService {
(a) => a.allocator,
);

const weekResult: AllocatorSpsComplianceWeekSingle[] = await Promise.all(
Object.entries(clientsByAllocator).map(
// prettier-ignore
async ([allocator, clients]): Promise<AllocatorSpsComplianceWeekSingle> => {
const weekAllocators: AllocatorSpsComplianceWeekSingle[] =
await Promise.all(
Object.entries(clientsByAllocator).map(
// prettier-ignore
async ([allocator, clients]): Promise<AllocatorSpsComplianceWeekSingle> => {
const weekProvidersForAllocator =
await this.storageProviderService.getWeekProvidersForClients(
week,
Expand All @@ -157,7 +171,7 @@ export class AllocatorService {

return {
id: allocator,
totalDatacap: await this.getWeekAllocatorDatacap(
totalDatacap: await this.getWeekAllocatorTotalDatacap(
week,
isAccumulative,
allocator,
Expand All @@ -166,26 +180,29 @@ export class AllocatorService {
weekProvidersCompliance,
weekProvidersForAllocator.map((p) => p.provider),
),
totalSps: weekProvidersForAllocator.length,
};
},
),
);
),
);

results.push({
week: week,
allocators: weekResult,
total: weekResult.length,
averageSuccessRate: weekAverageProvidersRetrievability,
total: weekAllocators.length,
allocators: weekAllocators,
});
}

return new AllocatorSpsComplianceWeekResponse(
lastWeekAverageProviderRetrievability,
this.histogramHelper.withoutCurrentWeek(
this.histogramHelper.sorted(results),
),
);
}

public async getWeekAllocatorDatacap(
public async getWeekAllocatorTotalDatacap(
week: Date,
isAccumulative: boolean,
allocatorId: string,
Expand Down
36 changes: 30 additions & 6 deletions src/service/allocator/types.allocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import { ApiProperty } from '@nestjs/swagger';
import { StorageProviderComplianceWeekPercentage } from '../storage-provider/types.storage-provider';

export class AllocatorSpsComplianceWeekSingle extends StorageProviderComplianceWeekPercentage {
@ApiProperty({ type: String })
@ApiProperty({ type: String, description: 'Allocator ID' })
id: string;

@ApiProperty()
@ApiProperty({
description: 'Total datacap of the allocator in the week',
})
totalDatacap: number;

@ApiProperty({
description:
'Total number of storage providers for the allocator in the week',
})
totalSps: number;
}

export class AllocatorSpsComplianceWeek {
Expand All @@ -17,18 +25,34 @@ export class AllocatorSpsComplianceWeek {
})
week: Date;

@ApiProperty({ type: AllocatorSpsComplianceWeekSingle, isArray: true })
allocators: AllocatorSpsComplianceWeekSingle[];

@ApiProperty()
total: number;

@ApiProperty({
description:
'Average storage providers retrievability success rate in the week',
})
averageSuccessRate: number;

@ApiProperty({ type: AllocatorSpsComplianceWeekSingle, isArray: true })
allocators: AllocatorSpsComplianceWeekSingle[];
}

export class AllocatorSpsComplianceWeekResponse {
@ApiProperty({
description:
'Last week average storage providers retrievability success rate',
})
averageSuccessRate: number;

@ApiProperty({ type: AllocatorSpsComplianceWeek, isArray: true })
results: AllocatorSpsComplianceWeek[];

constructor(results: AllocatorSpsComplianceWeek[]) {
constructor(
averageSuccessRate: number,
results: AllocatorSpsComplianceWeek[],
) {
this.averageSuccessRate = averageSuccessRate;
this.results = results;
}
}
Loading