Skip to content

Commit

Permalink
IJRU Scoring with RS rulesets support
Browse files Browse the repository at this point in the history
  • Loading branch information
swantzter committed Oct 26, 2024
1 parent a206804 commit 0a97b31
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 52 deletions.
2 changes: 2 additions & 0 deletions src/components/ModelCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ const rulesetList = computed(() => Array.isArray(props.model.rulesId) ? props.mo
onMounted(() => {
if (props.model.localAlternativeCompetitionEvents) {
competitionEventLookupCode.value = props.model.localAlternativeCompetitionEvents[0][1]
} else if (props.model.localCompetitionEvent) {
competitionEventLookupCode.value = props.model.localCompetitionEvent
}
})
</script>
3 changes: 2 additions & 1 deletion src/components/ServoEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ async function createScoresheet () {
competitionId: props.competitionId,
entryId: entry.value.EntryNumber,
judgeSequence: judge.value.JudgeSequence,
judgeType: judge.value.JudgeType,
scoringModel: entry.value.ScoringModelName,
competitionEventId: entry.value.EventTypeCode,
options: entry.value.ScoringRulesConfig
options: entry.value.EntryExtraData?.options
})
openScoresheet(scoresheetId)
} finally {
Expand Down
113 changes: 72 additions & 41 deletions src/hooks/scoresheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export interface ServoEntry {
EventDefinitionName: string
EventDefinitionAbbr: number
ScoringModelName: string
EventTypeCode: string // competitionEventLookupCode
EventTypeCode: string // competitionEventLookupCode - without version
IsScored: boolean
IsScratched: boolean
IsLocked: boolean
Expand All @@ -111,6 +111,12 @@ export interface ServoEntry {
TeamName: string
}>
ScoringRulesConfig: Record<string, unknown>
EntryExtraData?: { options?: Record<string, unknown> }
EntryMeta: {
entryId: string
participantId: string
competitionEvent: string
}
}

export interface ServoSession {
Expand All @@ -122,7 +128,7 @@ export interface ServoSession {

export interface ServoJudge {
JudgeSequence: number
JudgeType: null // TODO
JudgeType: string
}

export interface ServoCompetition {
Expand Down Expand Up @@ -458,12 +464,12 @@ const closeServo = async ({ save }: CloseScoresheetOptions) => {
}
const rulesId = scoresheet.value.rulesId
const judgeType = scoresheet.value.judgeType
const model = models.find(model => model.rulesId.includes(rulesId) && model.judgeType === judgeType)
const model = models.find(model => model.rulesId.includes(rulesId) && (Array.isArray(model.judgeType) ? model.judgeType.includes(judgeType) : model.judgeType === judgeType))
if (!model) {
throw new Error('Could not find model for scoresheet')
}
if (model.converters?.servo == null) {
throw new Error('Model does not have a converter for servo scoring')
console.warn('Model does not have a converter for servo scoring - using new structure')
}
const [,competitionId, entryId, judgeSequence] = scoresheet.value.id.split('::')

Expand All @@ -486,7 +492,7 @@ const closeServo = async ({ save }: CloseScoresheetOptions) => {
method = 'POST'
}

const scores = model.converters.servo(scoresheet.value)
const scores = model.converters?.servo?.(scoresheet.value)

// store the remote copy
const response = await fetch(url, {
Expand All @@ -504,7 +510,10 @@ const closeServo = async ({ save }: CloseScoresheetOptions) => {
DeviceID: deviceId.value,
RoutineStartTime: scoresheet.value.openedAt ?? scoresheet.value.createdAt,
BatteryLevel: battery.isSupported ? Math.round(battery.level.value * 100) : undefined,
...scores
...(scores ?? {}),
MarkSheet: {
marks: scoresheet.value.marks
}
}
})
})
Expand Down Expand Up @@ -622,47 +631,69 @@ export interface CreateServoScoresheetArgs {
competitionId: number
entryId: number
judgeSequence: number
judgeType?: string
scoringModel: string
competitionEventId: string
options?: Record<string, any> | null
}
export async function createServoScoresheet ({ competitionId, entryId, judgeSequence, scoringModel, competitionEventId, options }: CreateServoScoresheetArgs) {
export async function createServoScoresheet ({ competitionId, entryId, judgeSequence, judgeType: _judgeType, scoringModel, competitionEventId, options }: CreateServoScoresheetArgs) {
try {
let judgeType: string
if (scoringModel.startsWith('ijru.freestyle.') || scoringModel.startsWith('ijru.teamshow.')) {
if (judgeSequence >= 1 && judgeSequence <= 9) judgeType = 'Pa'
else if (judgeSequence >= 11 && judgeSequence <= 19) judgeType = 'Pr'
else if (judgeSequence >= 21 && judgeSequence <= 29) judgeType = 'R'
else if (judgeSequence >= 31 && judgeSequence <= 39) judgeType = 'D'
else throw new TypeError(`Invalid judge sequence ${judgeSequence} for scoring model ${scoringModel}`)
} else if (scoringModel.startsWith('ijru.speed.')) {
if (judgeSequence === 1) judgeType = 'Shj'
else judgeType = 'S'
} else if (scoringModel.startsWith('ijru.ddcf.') || scoringModel.startsWith('ijru.ddc.')) {
switch (judgeSequence) {
case 1:
case 2:
judgeType = 'J'
break
case 3:
case 4:
judgeType = 'T'
break
case 5:
case 6:
case 7:
judgeType = 'E'
break
case 8:
case 9:
case 10:
judgeType = 'S'
break
default:
throw new TypeError(`Invalid judge sequence ${judgeSequence} for scoring model ${scoringModel}`)
let judgeType = _judgeType
if (judgeType == null) {
if (scoringModel.startsWith('ijru.freestyle.sr@4.0.0')) {
if (judgeSequence >= 1 && judgeSequence <= 9) judgeType = 'P'
else if (judgeSequence >= 11 && judgeSequence <= 19) judgeType = 'T'
else if (judgeSequence >= 21 && judgeSequence <= 29) judgeType = 'Dp'
else if (judgeSequence >= 31 && judgeSequence <= 39) judgeType = 'Dm'
else if (judgeSequence >= 41 && judgeSequence <= 49) judgeType = 'Dr'
else throw new TypeError(`Invalid judge sequence ${judgeSequence} for scoring model ${scoringModel}`)
} else if (scoringModel.startsWith('ijru.freestyle.wh@4.0.0')) {
if (judgeSequence >= 1 && judgeSequence <= 9) judgeType = 'P'
else if (judgeSequence >= 11 && judgeSequence <= 19) judgeType = 'T'
else if (judgeSequence >= 21 && judgeSequence <= 29) judgeType = 'Da'
else if (judgeSequence >= 31 && judgeSequence <= 39) judgeType = 'Db'
else throw new TypeError(`Invalid judge sequence ${judgeSequence} for scoring model ${scoringModel}`)
} else if (scoringModel.startsWith('ijru.freestyle.dd@4.0.0')) {
if (judgeSequence >= 1 && judgeSequence <= 9) judgeType = 'P'
else if (judgeSequence >= 11 && judgeSequence <= 19) judgeType = 'T'
else if (judgeSequence >= 21 && judgeSequence <= 29) judgeType = 'Dj'
else if (judgeSequence >= 31 && judgeSequence <= 39) judgeType = 'Dt'
else throw new TypeError(`Invalid judge sequence ${judgeSequence} for scoring model ${scoringModel}`)
} else if (scoringModel.startsWith('ijru.freestyle.') || scoringModel.startsWith('ijru.teamshow.')) {
if (judgeSequence >= 1 && judgeSequence <= 9) judgeType = 'Pa'
else if (judgeSequence >= 11 && judgeSequence <= 19) judgeType = 'Pr'
else if (judgeSequence >= 21 && judgeSequence <= 29) judgeType = 'R'
else if (judgeSequence >= 31 && judgeSequence <= 39) judgeType = 'D'
else throw new TypeError(`Invalid judge sequence ${judgeSequence} for scoring model ${scoringModel}`)
} else if (scoringModel.startsWith('ijru.speed.')) {
if (judgeSequence === 1) judgeType = 'Shj'
else judgeType = 'S'
} else if (scoringModel.startsWith('ijru.ddcf.') || scoringModel.startsWith('ijru.ddc.')) {
switch (judgeSequence) {
case 1:
case 2:
judgeType = 'J'
break
case 3:
case 4:
judgeType = 'T'
break
case 5:
case 6:
case 7:
judgeType = 'E'
break
case 8:
case 9:
case 10:
judgeType = 'S'
break
default:
throw new TypeError(`Invalid judge sequence ${judgeSequence} for scoring model ${scoringModel}`)
}
} else {
throw new TypeError(`scoring model ${scoringModel} not supported`)
}
} else {
throw new TypeError(`scoring model ${scoringModel} not supported`)
}

const newScoresheet: ServoIntermediateScoresheet<string> = {
Expand Down
2 changes: 2 additions & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface Model {
allowScroll?: boolean
component: Component
localAlternativeCompetitionEvents?: Array<[string, string]>
localCompetitionEvent?: string
localOptions?: Option[]
hidden?: boolean
historic?: boolean
Expand Down Expand Up @@ -568,6 +569,7 @@ const models: Model[] = [
rulesId: ['ijru.freestyle.dd@4.0.0'],
judgeType: 'T',
name: 'Technical (Double Dutch)',
localCompetitionEvent: 'e.ijru.fs.dd.ddsf.1.75@4.0.0',
component: defineAsyncComponent(async () => await import('./views/scoring/ijru@4.0.0/Technical.vue')),
steps: ['marks', 'timeViolations'],
},
Expand Down
12 changes: 6 additions & 6 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
>
Practice
</router-link>
<router-link
class="block p-2 text-center text-lg text-white bg-green-500 hover:bg-green-600 rounded"
to="/servo/connect"
>
Judge an IJRU Scoring Competition
</router-link>
<router-link
class="block p-2 text-center text-lg text-white bg-green-500 hover:bg-green-600 rounded"
to="/rs/groups"
Expand All @@ -84,12 +90,6 @@
>
Stored Scoresheets
</router-link>
<router-link
class="block p-2 text-center text-lg text-white bg-white rounded"
to="/servo/connect"
>
Judge an IJRU Scoring Competition
</router-link>
</nav>

<div v-if="needRefresh" class="mb-8">
Expand Down
4 changes: 2 additions & 2 deletions src/views/scoring/ddc@2023/Judge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ missHints[0] = '(no-miss bonus)'
missHints[7] = '(or more)'
const scoreLabel = computed(() => {
switch (model.value.judgeType) {
switch (Array.isArray(model.value.judgeType) ? model.value.judgeType[0] : model.value.judgeType) {
case 'J':
return 'Jumper Score'
case 'T':
Expand All @@ -80,7 +80,7 @@ const scoreLabel = computed(() => {
})
const scoreMark = computed<Schema>(() => {
switch (model.value.judgeType) {
switch (Array.isArray(model.value.judgeType) ? model.value.judgeType[0] : model.value.judgeType) {
case 'J':
return 'jumperScore'
case 'T':
Expand Down
4 changes: 2 additions & 2 deletions src/views/scoring/ijru@1.1.0/Speed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import type { Model } from '../../../models'
export type Schema = 'step' | 'falseStart' | 'falseSwitch'
const props = defineProps({
defineProps({
model: {
type: Object as PropType<Model>,
required: true
Expand All @@ -73,7 +73,7 @@ const props = defineProps({
const { addMark, tally, scoresheet } = useScoresheet<Schema>()
const isHeadJudge = computed(() => props.model.judgeType === 'Shj')
const isHeadJudge = computed(() => scoresheet.value?.judgeType === 'Shj')
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const hasSwitches = computed(() => /\.\d+x\d+@.*$/.test(scoresheet.value?.competitionEventId ?? ''))
</script>

0 comments on commit 0a97b31

Please sign in to comment.