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