Rename variables, avoid using long set logic thing

This commit is contained in:
Hans5958 2022-05-06 14:38:48 +07:00
parent 5129fbc1ff
commit 935eadd618

View file

@ -1028,7 +1028,8 @@ function updateErrors() {
periodsStatus.textContent = "No paths available on this period!" periodsStatus.textContent = "No paths available on this period!"
} }
const [conflicts, invalidPaths, allErrors] = getErrors() const {conflicts, insufficientPaths} = getErrors()
let errorCount = 0
// console.log(conflicts, invalidPaths, allErrors) // console.log(conflicts, invalidPaths, allErrors)
periodGroupElements.forEach((el, index) => { periodGroupElements.forEach((el, index) => {
@ -1038,16 +1039,17 @@ function updateErrors() {
if (conflicts[index] !== undefined) { if (conflicts[index] !== undefined) {
periodStatusEl.textContent += `Period conflicts with path${conflicts[index].length === 1 ? "" : "s"} ${conflicts[index].join(", ")}.\n` periodStatusEl.textContent += `Period conflicts with path${conflicts[index].length === 1 ? "" : "s"} ${conflicts[index].join(", ")}.\n`
} }
if (invalidPaths[index] !== undefined) { if (insufficientPaths[index] !== undefined) {
periodStatusEl.textContent += `Insufficient paths. Got ${invalidPaths[index]}, need at least 3.\n` periodStatusEl.textContent += `Insufficient paths. Got ${insufficientPaths[index]}, need at least 3.\n`
} }
if (periodStatusEl.textContent !== "") { if (periodStatusEl.textContent !== "") {
periodStatusEl.classList.remove("d-none") periodStatusEl.classList.remove("d-none")
periodGroupEl.dataset.status = "error" periodGroupEl.dataset.status = "error"
errorCount += 1
} }
}) })
if (allErrors.length > 0) { if (errorCount > 0) {
periodsStatus.textContent = `Problems detected. Please check the groups indicated by red.` periodsStatus.textContent = `Problems detected. Please check the groups indicated by red.`
finishButton.disabled = true finishButton.disabled = true
} else { } else {
@ -1063,8 +1065,7 @@ function updateErrors() {
function getConflicts() { function getConflicts() {
let conflicts = new Set() const conflicts = {}
const conflictsNew = {}
for (let i = pathWithPeriods.length - 1; i > 0; i--) { for (let i = pathWithPeriods.length - 1; i > 0; i--) {
const [start1, end1, period1] = parsePeriod(pathWithPeriods[i][0]) const [start1, end1, period1] = parsePeriod(pathWithPeriods[i][0])
@ -1077,32 +1078,33 @@ function getConflicts() {
(start1 <= start2 && start2 <= end1) || (start1 <= start2 && start2 <= end1) ||
(start1 <= end2 && end2 <= end1) (start1 <= end2 && end2 <= end1)
) { ) {
if (!conflictsNew[i]) conflictsNew[i] = [] if (!conflicts[i]) conflicts[i] = []
if (!conflictsNew[j]) conflictsNew[j] = [] if (!conflicts[j]) conflicts[j] = []
conflictsNew[i].push(j) conflicts[i].push(j)
conflictsNew[j].push(i) conflicts[j].push(i)
} }
} }
} }
conflicts = [...conflicts] return conflicts
return conflictsNew
} }
function getErrors() { function getErrors() {
const conflicts = getConflicts() const conflicts = getConflicts()
const invalidPaths = {} const insufficientPaths = {}
pathWithPeriods.forEach(([period, path], i) => { pathWithPeriods.forEach(([period, path], i) => {
if (path.length < 3) invalidPaths[i] = path.length if (path.length < 3) insufficientPaths[i] = path.length
}) })
// console.info('conflicts', conflicts) // console.info('conflicts', conflicts)
// console.info('invalid paths', invalidPaths) // console.info('invalid paths', invalidPaths)
return [conflicts, invalidPaths, [...new Set([...Object.keys(conflicts).flat(), ...Object.keys(invalidPaths).flat()])]] return {
conflicts,
insufficientPaths,
}
} }
// function compressPeriod(periodsString) { // function compressPeriod(periodsString) {