Changed var names so eslint is happy

This commit is contained in:
mrfry 2020-10-02 09:22:03 +02:00
parent ecd7f0594d
commit bc0f77dc36

View file

@ -42,17 +42,17 @@ class StringUtils {
} }
RemoveStuff(value, removableStrings, toReplace) { RemoveStuff(value, removableStrings, toReplace) {
removableStrings.forEach((x) => { removableStrings.forEach((removableString) => {
var regex = new RegExp(x, 'g') var regex = new RegExp(removableString, 'g')
value = value.replace(regex, toReplace || '') value = value.replace(regex, toReplace || '')
}) })
return value return value
} }
SimplifyQuery(q) { SimplifyQuery(question) {
assert(q) assert(question)
var result = q.replace(/\n/g, ' ').replace(/\s/g, ' ') var result = question.replace(/\n/g, ' ').replace(/\s/g, ' ')
return this.RemoveUnnecesarySpaces(result) return this.RemoveUnnecesarySpaces(result)
} }
@ -162,10 +162,10 @@ class StringUtils {
RemoveAnswerLetters(value) { RemoveAnswerLetters(value) {
assert(value) assert(value)
let s = value.split('. ') let val = value.split('. ')
if (s[0].length < 2 && s.length > 1) { if (val[0].length < 2 && val.length > 1) {
s.shift() val.shift()
return s.join(' ') return val.join(' ')
} else { } else {
return value return value
} }
@ -207,9 +207,9 @@ class StringUtils {
const SUtils = new StringUtils() const SUtils = new StringUtils()
class Question { class Question {
constructor(q, a, data) { constructor(question, answer, data) {
this.Q = SUtils.SimplifyQuestion(q) this.Q = SUtils.SimplifyQuestion(question)
this.A = SUtils.SimplifyAnswer(a) this.A = SUtils.SimplifyAnswer(answer)
this.data = { ...data } this.data = { ...data }
} }
@ -264,10 +264,10 @@ class Question {
} else { } else {
return 0 return 0
} }
} catch (e) { } catch (error) {
debugLog('Error comparing data', 'Compare question data', 1) debugLog('Error comparing data', 'Compare question data', 1)
debugLog(e.message, 'Compare question data', 1) debugLog(error.message, 'Compare question data', 1)
debugLog(e, 'Compare question data', 2) debugLog(error, 'Compare question data', 2)
} }
return 0 return 0
} }
@ -323,10 +323,10 @@ class Question {
} }
class Subject { class Subject {
constructor(n) { constructor(name) {
assert(n) assert(name)
this.Name = n this.Name = name
this.Questions = [] this.Questions = []
} }
@ -342,10 +342,10 @@ class Subject {
return this.Questions.length return this.Questions.length
} }
AddQuestion(q) { AddQuestion(question) {
assert(q) assert(question)
this.Questions.push(q) this.Questions.push(question)
} }
getSubjNameWithoutYear() { getSubjNameWithoutYear() {
@ -361,40 +361,40 @@ class Subject {
} }
} }
Search(q, data) { Search(question, data) {
assert(q) assert(question)
var r = [] var result = []
for (let i = 0; i < this.length; i++) { for (let i = 0; i < this.length; i++) {
let percent = this.Questions[i].Compare(q, data) let percent = this.Questions[i].Compare(question, data)
if (percent.avg > minMatchAmmount) { if (percent.avg > minMatchAmmount) {
r.push({ result.push({
q: this.Questions[i], question: this.Questions[i],
match: percent.avg, match: percent.avg,
detailedMatch: percent, detailedMatch: percent,
}) })
} }
} }
for (let i = 0; i < r.length; i++) { for (let i = 0; i < result.length; i++) {
for (var j = i; j < r.length; j++) { for (var j = i; j < result.length; j++) {
if (r[i].match < r[j].match) { if (result[i].match < result[j].match) {
var tmp = r[i] var tmp = result[i]
r[i] = r[j] result[i] = result[j]
r[j] = tmp result[j] = tmp
} }
} }
} }
return r return result
} }
toString() { toString() {
var r = [] var result = []
for (var i = 0; i < this.Questions.length; i++) { for (var i = 0; i < this.Questions.length; i++) {
r.push(this.Questions[i].toString()) result.push(this.Questions[i].toString())
} }
return '+' + this.Name + '\n' + r.join('\n') return '+' + this.Name + '\n' + result.join('\n')
} }
} }
@ -407,9 +407,9 @@ class QuestionDB {
return this.Subjects.length return this.Subjects.length
} }
AddQuestion(subj, q) { AddQuestion(subj, question) {
debugLog('Adding new question with subjName: ' + subj, 'qdb add', 1) debugLog('Adding new question with subjName: ' + subj, 'qdb add', 1)
debugLog(q, 'qdb add', 3) debugLog(question, 'qdb add', 3)
assert(subj) assert(subj)
var i = 0 var i = 0
@ -424,44 +424,44 @@ class QuestionDB {
if (i < this.Subjects.length) { if (i < this.Subjects.length) {
debugLog('Adding new question to existing subject', 'qdb add', 1) debugLog('Adding new question to existing subject', 'qdb add', 1)
this.Subjects[i].AddQuestion(q) this.Subjects[i].AddQuestion(question)
} else { } else {
debugLog('Creating new subject for question', 'qdb add', 1) debugLog('Creating new subject for question', 'qdb add', 1)
const n = new Subject(subj) const newSubject = new Subject(subj)
n.AddQuestion(q) newSubject.AddQuestion(question)
this.Subjects.push(n) this.Subjects.push(newSubject)
} }
} }
SimplifyQuestion(q) { SimplifyQuestion(question) {
if (typeof q === 'string') { if (typeof q === 'string') {
return SUtils.SimplifyQuestion(q) return SUtils.SimplifyQuestion(question)
} else { } else {
q.Q = SUtils.SimplifyQuestion(q.Q) question.Q = SUtils.SimplifyQuestion(question.Q)
q.A = SUtils.SimplifyQuestion(q.A) question.A = SUtils.SimplifyQuestion(question.A)
return q return question
} }
} }
Search(q, subjName, data) { Search(question, subjName, data) {
assert(q) assert(question)
debugLog('Searching for question', 'qdb search', 1) debugLog('Searching for question', 'qdb search', 1)
debugLog('Question:', 'qdb search', 2) debugLog('Question:', 'qdb search', 2)
debugLog(q, 'qdb search', 2) debugLog(question, 'qdb search', 2)
debugLog(`Subject name: ${subjName}`, 'qdb search', 2) debugLog(`Subject name: ${subjName}`, 'qdb search', 2)
debugLog('Data:', 'qdb search', 2) debugLog('Data:', 'qdb search', 2)
debugLog(data || q.data, 'qdb search', 2) debugLog(data || question.data, 'qdb search', 2)
if (!data) { if (!data) {
data = q.data || { type: 'simple' } data = question.data || { type: 'simple' }
} }
if (!subjName) { if (!subjName) {
subjName = '' subjName = ''
debugLog('No subject name as param!', 'qdb search', 1) debugLog('No subject name as param!', 'qdb search', 1)
} }
q = this.SimplifyQuestion(q) question = this.SimplifyQuestion(question)
var r = [] var result = []
this.Subjects.forEach((subj) => { this.Subjects.forEach((subj) => {
if ( if (
subjName subjName
@ -469,21 +469,21 @@ class QuestionDB {
.includes(subj.getSubjNameWithoutYear().toLowerCase()) .includes(subj.getSubjNameWithoutYear().toLowerCase())
) { ) {
debugLog(`Searching in ${subj.Name} `, 2) debugLog(`Searching in ${subj.Name} `, 2)
r = r.concat(subj.Search(q, data)) result = result.concat(subj.Search(question, data))
} }
}) })
// FIXME: try to remove this? but this is also a good backup plan so idk // FIXME: try to remove this? but this is also a good backup plan so idk
if (r.length === 0) { if (result.length === 0) {
debugLog( debugLog(
'Reqults length is zero when comparing names, trying all subjects', 'Reqults length is zero when comparing names, trying all subjects',
'qdb search', 'qdb search',
1 1
) )
this.Subjects.forEach((subj) => { this.Subjects.forEach((subj) => {
r = r.concat(subj.Search(q, data)) result = result.concat(subj.Search(question, data))
}) })
if (r.length > 0) { if (result.length > 0) {
debugLog( debugLog(
`FIXME: '${subjName}' gave no result but '' did!`, `FIXME: '${subjName}' gave no result but '' did!`,
'qdb search', 'qdb search',
@ -493,18 +493,18 @@ class QuestionDB {
} }
} }
for (let i = 0; i < r.length; i++) { for (let i = 0; i < result.length; i++) {
for (var j = i; j < r.length; j++) { for (var j = i; j < result.length; j++) {
if (r[i].match < r[j].match) { if (result[i].match < result[j].match) {
var tmp = r[i] var tmp = result[i]
r[i] = r[j] result[i] = result[j]
r[j] = tmp result[j] = tmp
} }
} }
} }
debugLog(`QDB search result length: ${r.length}`, 'qdb search', 1) debugLog(`QDB search result length: ${result.length}`, 'qdb search', 1)
return r return result
} }
AddSubject(subj) { AddSubject(subj) {
@ -523,11 +523,11 @@ class QuestionDB {
} }
toString() { toString() {
var r = [] var result = []
for (var i = 0; i < this.Subjects.length; i++) { for (var i = 0; i < this.Subjects.length; i++) {
r.push(this.Subjects[i].toString()) result.push(this.Subjects[i].toString())
} }
return r.join('\n\n') return result.join('\n\n')
} }
} }