Skip to content

Commit

Permalink
Merge pull request #268 from qbreader/field-regularization
Browse files Browse the repository at this point in the history
Field regularization
  • Loading branch information
geoffrey-wu authored Apr 29, 2024
2 parents c2bfcd6 + fce59ba commit 92ffa7f
Show file tree
Hide file tree
Showing 29 changed files with 95 additions and 215 deletions.
9 changes: 4 additions & 5 deletions client/admin/category-reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function TossupCard({
const reason = tossup.reports.map(report => report.description).join('; ') || 'None given';
document.getElementById('report-reason').value = reason;
}
const powerParts = tossup.question.split('(*)');
return /*#__PURE__*/React.createElement("div", {
className: "card my-2"
}, /*#__PURE__*/React.createElement("div", {
Expand All @@ -68,13 +67,13 @@ function TossupCard({
className: "card-body"
}, /*#__PURE__*/React.createElement("span", {
dangerouslySetInnerHTML: {
__html: powerParts.length > 1 ? '<b>' + powerParts[0] + '(*)</b>' + powerParts[1] : tossup.question
__html: tossup.question
}
}), /*#__PURE__*/React.createElement("hr", {
className: "my-3"
}), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("b", null, "ANSWER:"), " ", /*#__PURE__*/React.createElement("span", {
dangerouslySetInnerHTML: {
__html: tossup?.formatted_answer ?? tossup.answer
__html: tossup?.answer
}
}))), /*#__PURE__*/React.createElement("div", {
className: "card-footer clickable",
Expand Down Expand Up @@ -102,7 +101,7 @@ function BonusCard({
}
function getBonusPartLabel(index, defaultValue = 10, defaultDifficulty = '') {
const value = bonus.values ? bonus.values[index] ?? defaultValue : defaultValue;
const difficulty = bonus.difficulties ? bonus.difficulties[index] ?? defaultDifficulty : defaultDifficulty;
const difficulty = bonus.difficultyModifiers ? bonus.difficultyModifiers[index] ?? defaultDifficulty : defaultDifficulty;
return `[${value}${difficulty}]`;
}
function onClick() {
Expand All @@ -127,7 +126,7 @@ function BonusCard({
key: `${bonus._id}-${i}`
}, /*#__PURE__*/React.createElement("hr", null), /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement("span", null, getBonusPartLabel(i), " "), /*#__PURE__*/React.createElement("span", null, bonus.parts[i])), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("b", null, "ANSWER: "), /*#__PURE__*/React.createElement("span", {
dangerouslySetInnerHTML: {
__html: (bonus?.formatted_answers ?? bonus.answers)[i]
__html: bonus?.answers[i]
}
}))))), /*#__PURE__*/React.createElement("div", {
className: "card-footer clickable",
Expand Down
14 changes: 4 additions & 10 deletions client/admin/category-reports.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ function TossupCard({ tossup }) {
document.getElementById('report-reason').value = reason;
}

const powerParts = tossup.question.split('(*)');

return (
<div className="card my-2">
<div className="card-header d-flex justify-content-between clickable" data-bs-toggle="collapse" data-bs-target={`#question-${_id}`}>
Expand All @@ -73,13 +71,9 @@ function TossupCard({ tossup }) {
</div>
<div className="card-container collapse show" id={`question-${_id}`}>
<div className="card-body">
<span dangerouslySetInnerHTML={{
__html: powerParts.length > 1 ? '<b>' + powerParts[0] + '(*)</b>' + powerParts[1] : tossup.question,
}}></span>
<span dangerouslySetInnerHTML={{ __html: tossup.question }}></span>
<hr className="my-3"></hr>
<div><b>ANSWER:</b> <span dangerouslySetInnerHTML={{
__html: tossup?.formatted_answer ?? tossup.answer,
}}></span></div>
<div><b>ANSWER:</b> <span dangerouslySetInnerHTML={{ __html: tossup?.answer }}></span></div>
</div>
<div className="card-footer clickable" onClick={onClick} id={`fix-category-${_id}`} data-bs-toggle="modal" data-bs-target="#fix-category-modal">
<small className="text-muted">{packetName ? 'Packet ' + packetName : <span>&nbsp;</span>}</small>
Expand All @@ -105,7 +99,7 @@ function BonusCard({ bonus }) {

function getBonusPartLabel(index, defaultValue = 10, defaultDifficulty = '') {
const value = bonus.values ? (bonus.values[index] ?? defaultValue) : defaultValue;
const difficulty = bonus.difficulties ? (bonus.difficulties[index] ?? defaultDifficulty) : defaultDifficulty;
const difficulty = bonus.difficultyModifiers ? (bonus.difficultyModifiers[index] ?? defaultDifficulty) : defaultDifficulty;
return `[${value}${difficulty}]`;
}

Expand Down Expand Up @@ -140,7 +134,7 @@ function BonusCard({ bonus }) {
</p>
<div>
<b>ANSWER: </b>
<span dangerouslySetInnerHTML={{ __html: (bonus?.formatted_answers ?? bonus.answers)[i] }}></span>
<span dangerouslySetInnerHTML={{ __html: bonus?.answers[i] }}></span>
</div>
</div>,
)}
Expand Down
2 changes: 1 addition & 1 deletion client/admin/geoword/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ document.getElementById('form').addEventListener('submit', event => {
<div><b>Given answer:</b> ${escapeHTML(myBuzz.givenAnswer)}</div>
</div>
<div class="col-6">
<div><b>Answer:</b> ${removeParentheses(myBuzz.formatted_answer ?? myBuzz.answer)}</div>
<div><b>Answer:</b> ${removeParentheses(myBuzz.answer)}</div>
<div><b>Celerity:</b> ${(opponentBuzz.celerity ?? 0.0).toFixed(3)}</div>
<div><b>Points:</b> ${opponentBuzz.points}</div>
<div><b>Given answer:</b> ${escapeHTML(opponentBuzz.givenAnswer)}</div>
Expand Down
4 changes: 2 additions & 2 deletions client/admin/geoword/protests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fetch('/api/admin/geoword/protests?' + new URLSearchParams({ packetName, divisio
const { questionNumber } = tossup;
innerHTML += `<div>${tossup.questionNumber}. ${tossup.question}</div>`;
// innerHTML += '<hr class="my-3"></hr>';
innerHTML += `<div>ANSWER: ${tossup.formatted_answer ?? tossup.answer}</div>`;
innerHTML += `<div>ANSWER: ${tossup.answer}</div>`;
innerHTML += `<p>&lt;${tossup.category} / ${tossup.subcategory}&gt;</p>`;

if (protests.filter(protest => protest.questionNumber === questionNumber).length === 0) {
Expand Down Expand Up @@ -55,7 +55,7 @@ fetch('/api/admin/geoword/protests?' + new URLSearchParams({ packetName, divisio
a.addEventListener('click', () => {
document.getElementById('resolve-protest-id').value = a.id;
document.getElementById('resolve-protest-given-answer').value = document.getElementById(`given-answer-${a.id}`).textContent;
document.getElementById('resolve-protest-actual-answer').innerHTML = packet[parseInt(a.attributes.question.value) - 1].formatted_answer;
document.getElementById('resolve-protest-actual-answer').innerHTML = packet[parseInt(a.attributes.question.value) - 1].answer;
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion client/admin/geoword/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fetch('/api/admin/geoword/stats?' + new URLSearchParams({ packetName, division }
<div><b>#${stats[i].tossup.questionNumber}</b></div>
<div><b>Times heard:</b> ${stats[i].timesHeard}</div>
<div><b>Number correct:</b> ${stats[i].numberCorrect}</div>
<div><b>Answer:</b> ${stats[i].tossup.formatted_answer}</div>
<div><b>Answer:</b> ${stats[i].tossup.answer}</div>
</div>
<div class="col-6">
<div><b>Best buzz:</b> ${stats[i].bestUsername}</div>
Expand Down
4 changes: 2 additions & 2 deletions client/api-docs/schemas.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ <h4 class="mt-4 md-2" id="tossup"><code>Tossup</code></h4>
</li>
<li class="list-group-item">
<div>
<code>formatted_answer</code><code class="text-muted">: string</code>
<code>answer</code><code class="text-muted">: string</code>
<code class="text-muted float-end fw-semibold text-decoration-underline">optional</code>
</div>
<div>The answerline, formatted with HTML.</div>
Expand Down Expand Up @@ -290,7 +290,7 @@ <h4 class="mt-4 md-2" id="bonus"><code>Bonus</code></h4>
</li>
<li class="list-group-item">
<div>
<code>formatted_answers</code><code class="text-muted">: [string, string, string]</code>
<code>answers</code><code class="text-muted">: [string, string, string]</code>
<code class="text-muted float-end fw-semibold text-decoration-underline">optional</code>
</div>
<div>The answerlines, formatted with HTML.</div>
Expand Down
43 changes: 16 additions & 27 deletions client/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function escapeCSVString(string) {
return `"${string.replace(/"/g, '""').replace(/\n/g, '\\n')}"`;
}
function downloadTossupsAsCSV(tossups, filename = 'tossups.csv') {
const header = ['_id', 'set.name', 'packet.number', 'number', 'question', 'answer', 'formatted_answer', 'category', 'subcategory', 'alternate_subcategory', 'difficulty', 'set._id', 'packet._id', 'createdAt', 'updatedAt'];
const header = ['_id', 'set.name', 'packet.number', 'number', 'question', 'answer', 'answer', 'category', 'subcategory', 'alternate_subcategory', 'difficulty', 'set._id', 'packet._id', 'createdAt', 'updatedAt'];
let csvdata = header.join(',') + '\n';
for (const tossup of tossups) {
for (const key of header) {
Expand All @@ -47,7 +47,7 @@ function downloadTossupsAsCSV(tossups, filename = 'tossups.csv') {
hiddenElement.click();
}
function downloadBonusesAsCSV(bonuses, filename = 'bonuses.csv') {
const header = ['_id', 'set.name', 'packet.number', 'number', 'leadin', 'parts.0', 'parts.1', 'parts.2', 'answers.0', 'answers.1', 'answers.2', 'formatted_answers.0', 'formatted_answers.1', 'formatted_answers.2', 'category', 'subcategory', 'alternate_subcategory', 'difficulty', 'set._id', 'packet._id', 'createdAt', 'updatedAt'];
const header = ['_id', 'set.name', 'packet.number', 'number', 'leadin', 'parts.0', 'parts.1', 'parts.2', 'answers_sanitized.0', 'answers_sanitized.1', 'answers_sanitized.2', 'answers.0', 'answers.1', 'answers.2', 'category', 'subcategory', 'alternate_subcategory', 'difficulty', 'set._id', 'packet._id', 'createdAt', 'updatedAt'];
let csvdata = header.join(',') + '\n';
for (const bonus of bonuses) {
for (const key of header) {
Expand Down Expand Up @@ -77,15 +77,15 @@ function downloadQuestionsAsText(tossups, bonuses, filename = 'data.txt') {
textdata += `${tossup.set.name} Packet ${tossup.packet.number}\n`;
textdata += `Question ID: ${tossup._id}\n`;
textdata += `${tossup.number}. ${tossup.question}\n`;
textdata += `ANSWER: ${tossup.answer}\n`;
textdata += `ANSWER: ${tossup.answer_sanitized}\n`;
textdata += `<${tossup.category} / ${tossup.subcategory}${tossup.alternate_subcategory ? ' (' + tossup.alternate_subcategory + ')' : ''}>\n\n`;
}
for (const bonus of bonuses) {
textdata += `Question ID: ${bonus._id}\n`;
textdata += `${bonus.set.name} Packet ${bonus.packet.number}\n`;
textdata += `${bonus.number}. ${bonus.leadin}\n`;
for (let i = 0; i < bonus.parts.length; i++) {
textdata += `${getBonusPartLabel(bonus, i)} ${bonus.parts[i]}\nANSWER: ${bonus.answers[i]}\n`;
textdata += `${getBonusPartLabel(bonus, i)} ${bonus.parts[i]}\nANSWER: ${bonus.answers_sanitized[i]}\n`;
}
textdata += `<${bonus.category} / ${bonus.subcategory}${bonus.alternate_subcategory ? ' (' + bonus.alternate_subcategory + ')' : ''}>\n\n`;
}
Expand All @@ -107,7 +107,7 @@ function downloadQuestionsAsText(tossups, bonuses, filename = 'data.txt') {
*/
function getBonusPartLabel(bonus, index, defaultValue = 10, defaultDifficulty = '') {
const value = bonus.values ? bonus.values[index] ?? defaultValue : defaultValue;
const difficulty = bonus.difficulties ? bonus.difficulties[index] ?? defaultDifficulty : defaultDifficulty;
const difficulty = bonus.difficultyModifiers ? bonus.difficultyModifiers[index] ?? defaultDifficulty : defaultDifficulty;
return `[${value}${difficulty}]`;
}
function getMatchIndices(clean, regex) {
Expand Down Expand Up @@ -195,14 +195,10 @@ function highlightTossupQuery({
const words = ignoreWordOrder ? queryString.split(' ').filter(word => word !== '').map(word => new RegExp(word, 'ig')) : [regExp];
for (const word of words) {
if (searchType === 'question' || searchType === 'all') {
tossup.question = insertMatches(tossup.question, tossup.unformatted_question, word);
tossup.question = insertMatches(tossup.question, tossup.question_sanitized, word);
}
if (searchType === 'answer' || searchType === 'all') {
if (tossup.formatted_answer) {
tossup.formatted_answer = insertMatches(tossup.formatted_answer, tossup.unformatted_answer, word);
} else {
tossup.answer = insertMatches(tossup.answer, tossup.unformatted_answer, word);
}
tossup.answer = insertMatches(tossup.answer, tossup.answer_sanitized, word);
}
}
return tossup;
Expand All @@ -217,20 +213,14 @@ function highlightBonusQuery({
const words = ignoreWordOrder ? queryString.split(' ').filter(word => word !== '').map(word => new RegExp(word, 'ig')) : [regExp];
for (const word of words) {
if (searchType === 'question' || searchType === 'all') {
bonus.leadin = insertMatches(bonus.leadin, bonus.unformatted_leadin, word);
bonus.leadin = insertMatches(bonus.leadin, bonus.leadin_sanitized, word);
for (let i = 0; i < bonus.parts.length; i++) {
bonus.parts[i] = insertMatches(bonus.parts[i], bonus.unformatted_parts[i], word);
bonus.parts[i] = insertMatches(bonus.parts[i], bonus.parts_sanitized[i], word);
}
}
if (searchType === 'answer' || searchType === 'all') {
if (bonus.formatted_answers) {
for (let i = 0; i < bonus.formatted_answers.length; i++) {
bonus.formatted_answers[i] = insertMatches(bonus.formatted_answers[i], bonus.unformatted_answers[i], word);
}
} else {
for (let i = 0; i < bonus.answers.length; i++) {
bonus.answers[i] = insertMatches(bonus.answers[i], bonus.unformatted_answers[i], word);
}
for (let i = 0; i < bonus.answers.length; i++) {
bonus.answers[i] = insertMatches(bonus.answers[i], bonus.answers_sanitized[i], word);
}
}
}
Expand All @@ -246,7 +236,7 @@ function TossupCard({
const _id = tossup._id;
const packetName = tossup.packet.name;
function clickToCopy() {
let textdata = `${tossup.question}\nANSWER: ${tossup.answer}`;
let textdata = `${tossup.question}\nANSWER: ${tossup.answer_sanitized}`;
let tag = '';
if (tossup.category && tossup.subcategory && tossup.category !== tossup.subcategory) {
tag += `${tossup.category} / ${tossup.subcategory}`;
Expand Down Expand Up @@ -326,7 +316,6 @@ function TossupCard({
console.error('Error:', error);
});
}
const powerParts = highlightedTossup.question.split('(*)');
return /*#__PURE__*/React.createElement("div", {
className: "card my-2"
}, /*#__PURE__*/React.createElement("div", {
Expand All @@ -348,13 +337,13 @@ function TossupCard({
}
}, /*#__PURE__*/React.createElement("span", {
dangerouslySetInnerHTML: {
__html: powerParts.length > 1 ? '<b>' + powerParts[0] + '(*)</b>' + powerParts[1] : highlightedTossup.question
__html: highlightedTossup.question
}
}), /*#__PURE__*/React.createElement("hr", {
className: "my-3"
}), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("b", null, "ANSWER:"), " ", /*#__PURE__*/React.createElement("span", {
dangerouslySetInnerHTML: {
__html: hideAnswerline ? '' : highlightedTossup?.formatted_answer ?? highlightedTossup.answer
__html: hideAnswerline ? '' : highlightedTossup?.answer
}
}))), /*#__PURE__*/React.createElement("div", {
className: `card-footer clickable ${!showCardFooter && 'd-none'}`,
Expand Down Expand Up @@ -391,7 +380,7 @@ function BonusCard({
let textdata = `${bonus.leadin}\n`;
for (let i = 0; i < bonus.parts.length; i++) {
textdata += `${getBonusPartLabel(bonus, i)} ${bonus.parts[i]}\n`;
textdata += `ANSWER: ${bonus.answers[i]}\n`;
textdata += `ANSWER: ${bonus.answers_sanitized[i]}\n`;
}
let tag = '';
if (bonus.category && bonus.subcategory && bonus.category !== bonus.subcategory) {
Expand Down Expand Up @@ -502,7 +491,7 @@ function BonusCard({
}
})), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("b", null, "ANSWER: "), /*#__PURE__*/React.createElement("span", {
dangerouslySetInnerHTML: {
__html: hideAnswerlines ? '' : (highlightedBonus?.formatted_answers ?? highlightedBonus.answers)[i]
__html: hideAnswerlines ? '' : highlightedBonus?.answers[i]
}
}))))), /*#__PURE__*/React.createElement("div", {
className: `card-footer clickable ${!showCardFooter && 'd-none'}`,
Expand Down
Loading

0 comments on commit 92ffa7f

Please sign in to comment.