-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29ff200
commit db6b26c
Showing
5 changed files
with
42 additions
and
33 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...ges/plugins/packages/payload/packages/crypto/packages/nft/packages/score/src/increment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ScaledScore } from './score' | ||
|
||
export const incrementTotal = (score: ScaledScore, by = 1): ScaledScore => { | ||
score[0] += by | ||
return score | ||
} | ||
|
||
export const incrementPossible = (score: ScaledScore, by = 1): ScaledScore => { | ||
score[1] += by | ||
return score | ||
} | ||
|
||
export const incrementTotalAndPossible = (score: ScaledScore, totalBy = 1, possibleBy = 1): ScaledScore => { | ||
score[0] += totalBy | ||
score[1] += possibleBy | ||
return score | ||
} |
37 changes: 4 additions & 33 deletions
37
packages/plugins/packages/payload/packages/crypto/packages/nft/packages/score/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,4 @@ | ||
import { EmptyPayload } from '@xyo-network/payload' | ||
|
||
export type PassFailScore = [total: number, possible: 1] | ||
export const PASS: PassFailScore = [1, 1] | ||
export const FAIL: PassFailScore = [0, 1] | ||
export type ScaledScore = [total: number, possible: number] | ||
export const SKIP: ScaledScore = [0, 0] | ||
export type Score = ScaledScore | PassFailScore | ||
|
||
export type PassFailScoringFunction<T extends EmptyPayload = EmptyPayload> = (payload: T) => PassFailScore | Promise<PassFailScore> | ||
export type ScaledScoringFunction<T extends EmptyPayload = EmptyPayload> = (payload: T) => Score | Promise<Score> | ||
export type ScoringFunction<T extends EmptyPayload = EmptyPayload> = PassFailScoringFunction<T> | ScaledScoringFunction<T> | ||
|
||
export interface WeightedScoringCriteria<T extends EmptyPayload = EmptyPayload> { | ||
score: ScoringFunction<T> | ||
weight: number | ||
} | ||
|
||
export const incrementTotal = (score: ScaledScore, by = 1): ScaledScore => { | ||
score[0] += by | ||
return score | ||
} | ||
|
||
export const incrementPossible = (score: ScaledScore, by = 1): ScaledScore => { | ||
score[1] += by | ||
return score | ||
} | ||
|
||
export const incrementTotalAndPossible = (score: ScaledScore, totalBy = 1, possibleBy = 1): ScaledScore => { | ||
score[0] += totalBy | ||
score[1] += possibleBy | ||
return score | ||
} | ||
export * from './increment' | ||
export * from './score' | ||
export * from './scoringFunction' | ||
export * from './weighted' |
6 changes: 6 additions & 0 deletions
6
packages/plugins/packages/payload/packages/crypto/packages/nft/packages/score/src/score.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type PassFailScore = [total: number, possible: 1] | ||
export const PASS: PassFailScore = [1, 1] | ||
export const FAIL: PassFailScore = [0, 1] | ||
export type ScaledScore = [total: number, possible: number] | ||
export const SKIP: ScaledScore = [0, 0] | ||
export type Score = ScaledScore | PassFailScore |
7 changes: 7 additions & 0 deletions
7
...ugins/packages/payload/packages/crypto/packages/nft/packages/score/src/scoringFunction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { EmptyPayload } from '@xyo-network/payload-model' | ||
|
||
import { PassFailScore, Score } from './score' | ||
|
||
export type PassFailScoringFunction<T extends EmptyPayload = EmptyPayload> = (payload: T) => PassFailScore | Promise<PassFailScore> | ||
export type ScaledScoringFunction<T extends EmptyPayload = EmptyPayload> = (payload: T) => Score | Promise<Score> | ||
export type ScoringFunction<T extends EmptyPayload = EmptyPayload> = PassFailScoringFunction<T> | ScaledScoringFunction<T> |
8 changes: 8 additions & 0 deletions
8
...ages/plugins/packages/payload/packages/crypto/packages/nft/packages/score/src/weighted.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { EmptyPayload } from '@xyo-network/payload-model' | ||
|
||
import { ScoringFunction } from './scoringFunction' | ||
|
||
export interface WeightedScoringCriteria<T extends EmptyPayload = EmptyPayload> { | ||
score: ScoringFunction<T> | ||
weight: number | ||
} |