-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add markReducer pattern for more efficient live score calculations (#35)
- Loading branch information
Showing
17 changed files
with
502 additions
and
237 deletions.
There are no files selected for viewing
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
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,7 +1,7 @@ | ||
import { simpleCalculateTallyFactory, clampNumber, filterMarkStream, formatFactor, isObject, parseCompetitionEventDefinition, roundTo, roundToCurry, roundToMultiple } from './helpers/helpers.js' | ||
import { calculateTallyFactory, clampNumber, filterMarkStream, formatFactor, isObject, parseCompetitionEventDefinition, roundTo, roundToCurry, roundToMultiple, simpleReducer } from './helpers.js' | ||
import type { GenericMark, JudgeMeta, JudgeTallyFieldDefinition, Mark } from '../models/types.js' | ||
import assert from 'node:assert' | ||
import test from 'node:test' | ||
import type { GenericMark, JudgeMeta, Mark } from './models/types.js' | ||
|
||
export function markGeneratorFactory () { | ||
let sequence = 0 | ||
|
@@ -127,7 +127,7 @@ void test('helpers', async t => { | |
} | ||
}) | ||
|
||
await t.test('simpleCalculateTallyFactory', async t => { | ||
await t.test('calculateTallyFactory', async t => { | ||
const meta: JudgeMeta = { | ||
judgeId: '1', | ||
judgeTypeId: 'S', | ||
|
@@ -136,6 +136,12 @@ void test('helpers', async t => { | |
competitionEvent: '[email protected]', | ||
} | ||
|
||
const tallyDefinitions: Array<JudgeTallyFieldDefinition<string>> = [ | ||
{ schema: 'formPlus', name: 'Form +' }, | ||
{ schema: 'formCheck', name: 'Form c' }, | ||
{ schema: 'formMinus', name: 'Form -' }, | ||
] | ||
|
||
await t.test('Should return tally for MarkScoresheet', () => { | ||
const marks: Array<Mark<string>> = [ | ||
{ sequence: 0, schema: 'formPlus', timestamp: 1 }, | ||
|
@@ -145,22 +151,96 @@ void test('helpers', async t => { | |
const tally = { | ||
formPlus: 2, | ||
formCheck: 1, | ||
formMinus: 0, | ||
} | ||
assert.deepStrictEqual(simpleCalculateTallyFactory(meta.judgeTypeId)({ meta, marks }), { meta, tally }) | ||
assert.deepStrictEqual(calculateTallyFactory(meta.judgeTypeId, simpleReducer, tallyDefinitions)({ meta, marks }), { meta, tally }) | ||
}) | ||
|
||
await t.test('Should return tally for MarkScoresheet with undo marks', () => { | ||
await t.test('Should return tally for MarkScoresheet with undo of last mark', () => { | ||
const m = markGeneratorFactory() | ||
const marks: Array<Mark<string>> = [ | ||
{ sequence: 0, schema: 'formPlus', timestamp: 1 }, | ||
{ sequence: 1, schema: 'formCheck', timestamp: 15 }, | ||
{ sequence: 2, schema: 'formPlus', timestamp: 30 }, | ||
{ sequence: 3, schema: 'undo', timestamp: 45, target: 2 }, | ||
m('formPlus'), | ||
m('formCheck'), | ||
m('formPlus'), | ||
m('undo', { target: 2 }), | ||
] | ||
const tally = { | ||
formPlus: 1, | ||
formCheck: 1, | ||
formMinus: 0, | ||
} | ||
assert.deepStrictEqual(calculateTallyFactory(meta.judgeTypeId, simpleReducer, tallyDefinitions)({ meta, marks }), { meta, tally }) | ||
}) | ||
|
||
await t.test('Should return tally for MarkScoresheet with undo of first mark', () => { | ||
const m = markGeneratorFactory() | ||
const marks: Array<Mark<string>> = [ | ||
m('formPlus'), | ||
m('formCheck'), | ||
m('formPlus'), | ||
m('undo', { target: 0 }), | ||
] | ||
const tally = { | ||
formPlus: 1, | ||
formCheck: 1, | ||
formMinus: 0, | ||
} | ||
assert.deepStrictEqual(calculateTallyFactory(meta.judgeTypeId, simpleReducer, tallyDefinitions)({ meta, marks }), { meta, tally }) | ||
}) | ||
|
||
await t.test('Should return tally for MarkScoresheet with undo of early mark', () => { | ||
const m = markGeneratorFactory() | ||
const marks: Array<Mark<string>> = [ | ||
m('formPlus'), | ||
m('formCheck'), | ||
m('formPlus'), | ||
m('undo', { target: 1 }), | ||
] | ||
const tally = { | ||
formPlus: 2, | ||
formCheck: 0, | ||
formMinus: 0, | ||
} | ||
assert.deepStrictEqual(calculateTallyFactory(meta.judgeTypeId, simpleReducer, tallyDefinitions)({ meta, marks }), { meta, tally }) | ||
}) | ||
|
||
await t.test('Should return tally for MarkScoresheet with clear mark', () => { | ||
const m = markGeneratorFactory() | ||
const marks: Array<Mark<string>> = [ | ||
m('formPlus'), | ||
m('formCheck'), | ||
m('formPlus'), | ||
m('clear'), | ||
m('formPlus'), | ||
m('formPlus'), | ||
m('formPlus'), | ||
] | ||
const tally = { | ||
formPlus: 3, | ||
formCheck: 0, | ||
formMinus: 0, | ||
} | ||
assert.deepStrictEqual(calculateTallyFactory(meta.judgeTypeId, simpleReducer, tallyDefinitions)({ meta, marks }), { meta, tally }) | ||
}) | ||
|
||
await t.test('Should return tally for MarkScoresheet with clear mark and undo targetting before clear', () => { | ||
const m = markGeneratorFactory() | ||
const marks: Array<Mark<string>> = [ | ||
m('formPlus'), | ||
m('formCheck'), | ||
m('formPlus'), | ||
m('clear'), | ||
m('formPlus'), | ||
m('formPlus'), | ||
m('formPlus'), | ||
m('undo', { target: 1 }), | ||
] | ||
const tally = { | ||
formPlus: 3, | ||
formCheck: 0, | ||
formMinus: 0, | ||
} | ||
assert.deepStrictEqual(simpleCalculateTallyFactory(meta.judgeTypeId)({ meta, marks }), { meta, tally }) | ||
assert.deepStrictEqual(calculateTallyFactory(meta.judgeTypeId, simpleReducer, tallyDefinitions)({ meta, marks }), { meta, tally }) | ||
}) | ||
}) | ||
|
||
|
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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ import * as mod from './[email protected]' | |
import * as srMod from './[email protected]' | ||
import { type JudgeResult, type EntryMeta, type JudgeMeta } from '../types.js' | ||
import { RSRWrongJudgeTypeError } from '../../errors.js' | ||
import { markGeneratorFactory } from '../../helpers.test.js' | ||
import { markGeneratorFactory } from '../../helpers/helpers.test.js' | ||
|
||
void test('[email protected]', async t => { | ||
await t.test('L', async t => { | ||
|
@@ -53,7 +53,7 @@ void test('[email protected]', async t => { | |
meta, | ||
marks: [m('miss'), m('miss'), m('rqInteractions')], | ||
}), | ||
{ meta, tally: { miss: 2 } } | ||
{ meta, tally: { miss: 2, spaceViolation: 0, timeViolation: 0 } } | ||
) | ||
}) | ||
|
||
|
@@ -127,14 +127,27 @@ void test('[email protected]', async t => { | |
{ | ||
meta, | ||
tally: { | ||
diffL1Minus: 0, | ||
diffL1: 2, | ||
diffL1Plus: 1, | ||
|
||
diffL2Minus: 0, | ||
diffL2: 3, | ||
diffL2Plus: 0, | ||
|
||
diffL3Minus: 0, | ||
diffL3: 4, | ||
diffL3Plus: 0, | ||
|
||
diffL4Minus: 0, | ||
diffL4: 5, | ||
diffL4Plus: 0, | ||
|
||
diffL5Minus: 1, | ||
diffL5: 6, | ||
diffL5Plus: 0, | ||
|
||
break: 2, | ||
diffL1Plus: 1, | ||
diffL5Minus: 1, | ||
}, | ||
} | ||
) | ||
|
@@ -208,13 +221,25 @@ void test('[email protected]', async t => { | |
{ | ||
meta, | ||
tally: { | ||
diffL1Minus: 0, | ||
diffL1: 2, | ||
diffL1Plus: 1, | ||
|
||
diffL2Minus: 0, | ||
diffL2: 3, | ||
diffL2Plus: 0, | ||
|
||
diffL3Minus: 0, | ||
diffL3: 4, | ||
diffL3Plus: 0, | ||
|
||
diffL4Minus: 0, | ||
diffL4: 5, | ||
diffL5: 6, | ||
diffL1Plus: 1, | ||
diffL4Plus: 0, | ||
|
||
diffL5Minus: 1, | ||
diffL5: 6, | ||
diffL5Plus: 0, | ||
}, | ||
} | ||
) | ||
|
Oops, something went wrong.