mirror of
https://github.com/jwinterm/rarity-analyser.git
synced 2026-10-17 05:41:40 +02:00
Add config option to ignore trait types
This commit is contained in:
@@ -43,11 +43,22 @@ Add weights to scale rarity scores up or down.
|
|||||||
{
|
{
|
||||||
weights: {
|
weights: {
|
||||||
"Trait A": 1.2,
|
"Trait A": 1.2,
|
||||||
"Trait B": 0,
|
"Trait B": 0.1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### ignoreTraits
|
||||||
|
Array of trait types to be ignored by the rarity analyser.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
{
|
||||||
|
ingoreTraits: [
|
||||||
|
'Trait x',
|
||||||
|
'Trait y',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
### getMissingTraitIdentifier
|
### getMissingTraitIdentifier
|
||||||
`(trait_type?: string) => string | undefined`
|
`(trait_type?: string) => string | undefined`
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const config: Config = {
|
|||||||
// weights: {},
|
// weights: {},
|
||||||
// getMissingTraitIdentifier: (trait_type?: string) => undefined,
|
// getMissingTraitIdentifier: (trait_type?: string) => undefined,
|
||||||
// attributesFieldName: 'attributes',
|
// attributesFieldName: 'attributes',
|
||||||
|
// ignoreTraits: []
|
||||||
}
|
}
|
||||||
|
|
||||||
export default config
|
export default config
|
||||||
|
|||||||
+12
-1
@@ -106,6 +106,12 @@ export const analyse = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const filterIgnored = (tokens: Token[], ignoredTraits: string[]) => tokens.map(token => ({
|
||||||
|
...token,
|
||||||
|
attributes: token.attributes.filter(attribute => (
|
||||||
|
!(ignoredTraits.includes(attribute.trait_type))
|
||||||
|
))
|
||||||
|
}))
|
||||||
|
|
||||||
const preprocess = (
|
const preprocess = (
|
||||||
tokens: Record<string, string | number | Attribute[]>[]
|
tokens: Record<string, string | number | Attribute[]>[]
|
||||||
@@ -152,7 +158,12 @@ const preprocess = (
|
|||||||
t = mapped
|
t = mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
return t as Token[]
|
let result: Token[]
|
||||||
|
if (config.ignoreTraits !== undefined)
|
||||||
|
result = filterIgnored(t as Token[], config.ignoreTraits)
|
||||||
|
else result = t as Token[]
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ export interface Config {
|
|||||||
weights?: Weights
|
weights?: Weights
|
||||||
getMissingTraitIdentifier?: GetMissingTraitIdentifier
|
getMissingTraitIdentifier?: GetMissingTraitIdentifier
|
||||||
attributesFieldName?: string
|
attributesFieldName?: string
|
||||||
|
ignoreTraits?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AttributeWithRarity = Attribute & RarityFields
|
export type AttributeWithRarity = Attribute & RarityFields
|
||||||
|
|||||||
Reference in New Issue
Block a user