Skip to content

Commit

Permalink
Determine answer correctness numerically only if very wrong is not sp…
Browse files Browse the repository at this point in the history
…ecified
  • Loading branch information
motin committed Apr 27, 2020
1 parent b79faf0 commit cdeff1e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/gsheetsData/combinedToplineSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
getSheetDataIncludingHeaderRow,
lookupGsDashboardSurveyListing
} from "../common";
import { answerOptionMatchesFactualAnswer } from "../lib/answerOptionMatchesFactualAnswer";
import {
answerOptionIsTheSameAsFactualAnswer,
answerOptionMatchesFactualAnswer
} from "../lib/answerOptionMatchesFactualAnswer";
import { chosenAnswerOptionIsThisManyAnswerOptionsAwayFromFactualAnswer } from "../lib/chosenAnswerOptionIsThisManyAnswerOptionsAwayFromFactualAnswer";
import Spreadsheet = GoogleAppsScript.Spreadsheet.Spreadsheet;
import {
Expand Down Expand Up @@ -387,27 +390,24 @@ export function updateCombinedToplineSheetFormulasAndCalculatedColumns(
correspondingCombinedToplineEntry =>
correspondingCombinedToplineEntry.answer
);
const correctAnswerOptions = answerOptions.filter($answerOption =>
answerOptionMatchesFactualAnswer($answerOption, factualCorrectAnswer)
);
if (correctAnswerOptions.length === 0) {
return `(No answer option matching the correct answer "${factualCorrectAnswer}" found)`;
}

let autoMarkedAsCorrect = false;
let autoMarkedAsWrong = false;
let autoMarkedAsVeryWrong = false;
if (correctAnswerOptions.indexOf(combinedToplineEntry.answer) > -1) {
autoMarkedAsCorrect = true;
} else {
autoMarkedAsWrong = true;
}
let correctAnswerOptions;

// Determine if very wrong
// Determine numerically if very wrong is not specified
if (
factualVeryWrongAnswer === undefined ||
factualVeryWrongAnswer.trim() === ""
) {
// Determine correct answer numerically if possible
correctAnswerOptions = answerOptions.filter($answerOption =>
answerOptionMatchesFactualAnswer($answerOption, factualCorrectAnswer)
);
if (correctAnswerOptions.length === 0) {
return `(No answer option numerically matching the correct answer "${factualCorrectAnswer}" found)`;
}
// Determine very wrong answer numerically if possible
try {
const answerOptionsAwayFromFactualAnswer = chosenAnswerOptionIsThisManyAnswerOptionsAwayFromFactualAnswer(
Expand All @@ -426,11 +426,25 @@ export function updateCombinedToplineSheetFormulasAndCalculatedColumns(
}
}
} else {
autoMarkedAsVeryWrong = answerOptionMatchesFactualAnswer(
correctAnswerOptions = answerOptions.filter($answerOption =>
answerOptionIsTheSameAsFactualAnswer(
$answerOption,
factualCorrectAnswer
)
);
if (correctAnswerOptions.length === 0) {
return `(No answer option matching the correct answer "${factualCorrectAnswer}" found)`;
}
autoMarkedAsVeryWrong = answerOptionIsTheSameAsFactualAnswer(
combinedToplineEntry.answer,
factualVeryWrongAnswer
);
}
if (correctAnswerOptions.indexOf(combinedToplineEntry.answer) > -1) {
autoMarkedAsCorrect = true;
} else {
autoMarkedAsWrong = true;
}
const autoMarkedCorrectness = autoMarkedAsCorrect
? 1
: autoMarkedAsVeryWrong
Expand Down
22 changes: 22 additions & 0 deletions src/lib/answerOptionMatchesFactualAnswer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,34 @@ import { keyNormalizerForSlightlyFuzzyLookups } from "./keyNormalizerForSlightly
export function answerOptionMatchesFactualAnswer(
answerOption: string,
factualAnswer: string
): boolean {
return (
answerOptionIsTheSameAsFactualAnswer(answerOption, factualAnswer) ||
answerOptionMatchesFactualAnswerNumerically(answerOption, factualAnswer)
);
}

/**
* @hidden
*/
export function answerOptionIsTheSameAsFactualAnswer(
answerOption: string,
factualAnswer: string
): boolean {
answerOption = keyNormalizerForSlightlyFuzzyLookups(answerOption);
factualAnswer = keyNormalizerForSlightlyFuzzyLookups(factualAnswer);
if (answerOption === factualAnswer) {
return true;
}
}

/**
* @hidden
*/
export function answerOptionMatchesFactualAnswerNumerically(
answerOption: string,
factualAnswer: string
): boolean {
// Support matching eg "14" to "14 pounds"
const numericalPartsOfAnswerOption = extractNumericalPartsOfAnswerOption(
answerOption
Expand Down

0 comments on commit cdeff1e

Please sign in to comment.