-
Notifications
You must be signed in to change notification settings - Fork 56
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
Bugfixes/fix provider gpus UI #143
Conversation
@@ -42,6 +42,7 @@ export async function getNetworkCapacity() { | |||
} | |||
|
|||
export const getProviderList = async () => { | |||
// Fetch provider list with their attributes & auditors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho this kind of comments don't help much. It's already obvious that providers
is a providers list. If it's essential to emphasise it's got attributes and auditors (is it?) it can be named accordingly. e.g. providersWithAttrsAndAuditors
. It would also help understanding code better further if it's important.
api/src/utils/map/provider.ts
Outdated
const gpuModels = (nodes || []) | ||
.flatMap((x) => x.gpus) | ||
.map((x) => ({ vendor: x.vendor, model: x.name, ram: x.memorySize, interface: x.interface })) | ||
.filter((x, i, arr) => arr.findIndex((o) => x.vendor === o.vendor && x.model === o.model && x.ram === o.ram && x.interface === o.interface) === i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is hard to understand, ideally I'd imagine this should be extracted into a named function with some vars that would better explain the conditions.
api/src/utils/map/provider.ts
Outdated
function getDistinctGpuModelsFromNodes(nodes: ProviderSnapshotNode[]) { | ||
const gpuModels = nodes.flatMap((x) => x.gpus).map((x) => ({ vendor: x.vendor, model: x.name, ram: x.memorySize, interface: x.interface })); | ||
const distinctGpuModels = gpuModels.filter( | ||
(x, i, arr) => arr.findIndex((o) => x.vendor === o.vendor && x.model === o.model && x.ram === o.ram && x.interface === o.interface) === i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you pls explain what this means?
I understand that findIndex
matching same vendor, model, etc. Why should it also be of the same index?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I see, it's to remove duplicates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's really hard to understand this. I'd suggest if we could add a dedicated function for this.
type Matcher<T> = (a: T, b: T) => boolean;
function createFilterUnique<T>(matcher: Matcher<T> = (a, b) => a === b): (value: T, index: number, array: T[]) => boolean {
return (value, index, array) => {
return array.findIndex((other) => matcher(value, other)) === index;
};
}
in this case the code above would be:
const distinctGpuModels = gpuModels.filter(
createFilterUnique(x, o) => x.vendor === o.vendor && x.model === o.model && x.ram === o.ram && x.interface === o.interface))
);
and example below would be
.filter(createFilterUnique())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be tested here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to keep only the first occurence of each gpus since there are duplicates in the array. If the current index i
matches findIndex
that means it's the first occurence so it's kept, otherwise it is filtered out as duplicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, I figured after asking the question :) check out a suggestion pls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mb your other replies weren't showing when I answered. For sure that would be easier to understand, I'll add it! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the createFilterUnique
helper with relevant unit tests
@@ -62,7 +62,7 @@ export const ProviderListRow: React.FunctionComponent<Props> = ({ provider }) => | |||
const _totalStorage = provider.isOnline | |||
? bytesToShrink(provider.availableStats.storage + provider.pendingStats.storage + provider.activeStats.storage) | |||
: null; | |||
const gpuModels = provider.hardwareGpuModels.map(gpu => gpu.substring(gpu.lastIndexOf(" ") + 1, gpu.length)); | |||
const gpuModels = provider.gpuModels.map(x => x.model).filter((x, i, arr) => arr.indexOf(x) === i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also utilise that new filter function. What do you think?
const gpuModels = provider.gpuModels.map(x => x.model).filter((x, i, arr) => arr.indexOf(x) === i); | |
const gpuModels = provider.gpuModels.map(x => x.model).filter(createFilterUnique()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I added it to the deploy-web project too. No unit tests for now, but we could add them once the big refactor is done (rebrand).
const gpuModels = | ||
provider?.gpuModels | ||
?.map(x => x.model + " " + x.ram) | ||
.filter((x, i, arr) => arr.indexOf(x) === i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.filter((x, i, arr) => arr.indexOf(x) === i) | |
.filter(createFilterUnique()) |
Display gpu models from feature discovery instead of capabilities attributes