From 2441257b474e03a2c915b4e6d3e4343016bfc61f Mon Sep 17 00:00:00 2001 From: Erik Surface Date: Tue, 10 Dec 2024 17:05:02 -0500 Subject: [PATCH 1/7] Add Score count and percent --- tangy-form-item.js | 10 ++++++++++ tangy-form-reducer.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tangy-form-item.js b/tangy-form-item.js index 418e9ed4..7520fbf5 100644 --- a/tangy-form-item.js +++ b/tangy-form-item.js @@ -818,6 +818,16 @@ export class TangyFormItem extends PolymerElement { scoreEl.name = `${tangyFormItem.getAttribute('id')}_score` scoreEl.value = score this.inputs = [...inputs, scoreEl.getModProps && window.useShrinker ? scoreEl.getModProps() : scoreEl.getProps()] + + const countEl = document.createElement('tangy-input') + countEl.name = `${tangyFormItem.getAttribute('id')}_count` + countEl.value = inputs.length + this.inputs = [...this.inputs, countEl.getModProps && window.useShrinker ? countEl.getModProps() : countEl.getProps()] + + const percentEl = document.createElement('tangy-input') + percentEl.name = `${tangyFormItem.getAttribute('id')}_percent` + percentEl.value = Math.round((score/inputs.length) * 100).toString() + this.inputs = [...this.inputs, percentEl.getModProps && window.useShrinker ? percentEl.getModProps() : percentEl.getProps()] } } if (window.devtools && window.devtools.open) { diff --git a/tangy-form-reducer.js b/tangy-form-reducer.js index 23d01001..df7be2dc 100644 --- a/tangy-form-reducer.js +++ b/tangy-form-reducer.js @@ -376,7 +376,7 @@ const tangyFormReducer = function (state = initialState, action) { return Object.assign({}, item, props) return item }) - }) + })sc case 'HIDE_ITEM_BUTTONS': newState = Object.assign({}, state, { From 62d5a7b821504ce229260182e11fe1802053d715 Mon Sep 17 00:00:00 2001 From: Erik Surface Date: Wed, 11 Dec 2024 16:53:53 -0500 Subject: [PATCH 2/7] WIP: Change names of new inputs --- tangy-form-item.js | 52 ++++++++++++++++++++++--------------------- tangy-form-reducer.js | 2 +- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/tangy-form-item.js b/tangy-form-item.js index 7520fbf5..25cd7aa8 100644 --- a/tangy-form-item.js +++ b/tangy-form-item.js @@ -772,34 +772,36 @@ export class TangyFormItem extends PolymerElement { this .querySelectorAll('[name]') .forEach(input => inputs.push(input.getModProps && window.useShrinker ? input.getModProps() : input.getProps())) + let score = 0 + let inputCount = undefined + let scorePercent = undefined this.inputs = inputs - if (this.querySelector('[name]')) { const tangyFormItem = this.querySelector('[name]').parentElement if(tangyFormItem.hasAttribute('scoring-section')) { const selections = tangyFormItem.getAttribute('scoring-fields') || [] - if(selections.length>0){ + if (selections.length > 0) { const selectionsArray = selections.split(',') - function findObjectByKey(array, key, value) { - for (let i = 0; i < array.length; i++) { if (array[i] == key) {return array[i];} - } return null; - } - - this.inputs.forEach(input => { - const a = findObjectByKey(selectionsArray, input.name) - if (a != null){ - let value; - if (input.tagName === 'TANGY-TIMED') { - //each grid present is scored as "number of correct items"/"number of total items" *100 - const correct = numberOfCorrectItems(input); - const total = input.value.length - value = Math.round((correct/total) * 100).toString(); - } else { - value = getValue(input.name); - } - score += sumScore(value)} - }) + function findObjectByKey(array, key, value) { + for (let i = 0; i < array.length; i++) { if (array[i] == key) {return array[i];} + } return null; + } + inputCount = selectionsArray.length + this.inputs.forEach(input => { + const a = findObjectByKey(selectionsArray, input.name) + if (a != null){ + let value; + if (input.tagName === 'TANGY-TIMED') { + //each grid present is scored as "number of correct items"/"number of total items" *100 + const correct = numberOfCorrectItems(input); + const total = input.value.length + value = Math.round((correct/total) * 100).toString(); + } else { + value = getValue(input.name); + } + score += sumScore(value)} + }) } if(tangyFormItem.hasAttribute('custom-scoring-logic')&&tangyFormItem.getAttribute('custom-scoring-logic').trim().length>0){ score = this.customScore @@ -820,13 +822,13 @@ export class TangyFormItem extends PolymerElement { this.inputs = [...inputs, scoreEl.getModProps && window.useShrinker ? scoreEl.getModProps() : scoreEl.getProps()] const countEl = document.createElement('tangy-input') - countEl.name = `${tangyFormItem.getAttribute('id')}_count` - countEl.value = inputs.length + countEl.name = `${tangyFormItem.getAttribute('id')}_score_count` + countEl.value = inputCount this.inputs = [...this.inputs, countEl.getModProps && window.useShrinker ? countEl.getModProps() : countEl.getProps()] const percentEl = document.createElement('tangy-input') - percentEl.name = `${tangyFormItem.getAttribute('id')}_percent` - percentEl.value = Math.round((score/inputs.length) * 100).toString() + percentEl.name = `${tangyFormItem.getAttribute('id')}_score_percent` + percentEl.value = scorePercent this.inputs = [...this.inputs, percentEl.getModProps && window.useShrinker ? percentEl.getModProps() : percentEl.getProps()] } } diff --git a/tangy-form-reducer.js b/tangy-form-reducer.js index df7be2dc..23d01001 100644 --- a/tangy-form-reducer.js +++ b/tangy-form-reducer.js @@ -376,7 +376,7 @@ const tangyFormReducer = function (state = initialState, action) { return Object.assign({}, item, props) return item }) - })sc + }) case 'HIDE_ITEM_BUTTONS': newState = Object.assign({}, state, { From 4bab5c7c5759747f172b658880f21c8362f66f9a Mon Sep 17 00:00:00 2001 From: Erik Surface Date: Thu, 12 Dec 2024 09:07:43 -0500 Subject: [PATCH 3/7] Rename score_count to score_denominator --- tangy-form-item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tangy-form-item.js b/tangy-form-item.js index 25cd7aa8..df5a45c4 100644 --- a/tangy-form-item.js +++ b/tangy-form-item.js @@ -822,7 +822,7 @@ export class TangyFormItem extends PolymerElement { this.inputs = [...inputs, scoreEl.getModProps && window.useShrinker ? scoreEl.getModProps() : scoreEl.getProps()] const countEl = document.createElement('tangy-input') - countEl.name = `${tangyFormItem.getAttribute('id')}_score_count` + countEl.name = `${tangyFormItem.getAttribute('id')}_score_denominator` countEl.value = inputCount this.inputs = [...this.inputs, countEl.getModProps && window.useShrinker ? countEl.getModProps() : countEl.getProps()] From 1b28c9dea587c427e42eadcfb1f18e50aec410c4 Mon Sep 17 00:00:00 2001 From: Erik Surface Date: Fri, 10 Jan 2025 07:38:49 -0500 Subject: [PATCH 4/7] Calculate
_score_percent --- tangy-form-item.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tangy-form-item.js b/tangy-form-item.js index df5a45c4..0dc28efd 100644 --- a/tangy-form-item.js +++ b/tangy-form-item.js @@ -775,7 +775,6 @@ export class TangyFormItem extends PolymerElement { let score = 0 let inputCount = undefined - let scorePercent = undefined this.inputs = inputs if (this.querySelector('[name]')) { const tangyFormItem = this.querySelector('[name]').parentElement @@ -828,7 +827,7 @@ export class TangyFormItem extends PolymerElement { const percentEl = document.createElement('tangy-input') percentEl.name = `${tangyFormItem.getAttribute('id')}_score_percent` - percentEl.value = scorePercent + percentEl.value = inputCount > 0 ? int(score/inputCount*100) : 0 this.inputs = [...this.inputs, percentEl.getModProps && window.useShrinker ? percentEl.getModProps() : percentEl.getProps()] } } From 1fe93e259adbb37d6ea6eda71cbace8361d269aa Mon Sep 17 00:00:00 2001 From: Erik Surface Date: Fri, 10 Jan 2025 10:38:42 -0500 Subject: [PATCH 5/7] Update scoring section logic to properly calculate and set score, denominator and percent --- demo/tangy-scoring-demo.html | 60 ++++++++++++++++++++++++++++- tangy-form-item.js | 74 +++++++++++++++++++++++------------- 2 files changed, 106 insertions(+), 28 deletions(-) diff --git a/demo/tangy-scoring-demo.html b/demo/tangy-scoring-demo.html index 8bcb3f1b..5a77806a 100644 --- a/demo/tangy-scoring-demo.html +++ b/demo/tangy-scoring-demo.html @@ -70,7 +70,65 @@

tangy-form scoring demo