Skip to content

Commit

Permalink
Modularize scoring model
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Aug 2, 2023
1 parent 29ff200 commit db6b26c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 33 deletions.
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
}
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'
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
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>
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
}

0 comments on commit db6b26c

Please sign in to comment.