Spaces:
Paused
Paused
Update endpoints/antibot.js
Browse files- endpoints/antibot.js +54 -60
endpoints/antibot.js
CHANGED
|
@@ -174,12 +174,21 @@ function evaluateSimpleMath(expression) {
|
|
| 174 |
|
| 175 |
function parseSoalText(text) {
|
| 176 |
console.log(`π DEBUG parseSoalText: Input text: "${text}"`);
|
|
|
|
|
|
|
|
|
|
| 177 |
const delimiters = /[.,:;\\/\s]+/;
|
| 178 |
-
let parts = text.split(delimiters)
|
|
|
|
|
|
|
|
|
|
| 179 |
if (parts.length === 1) {
|
| 180 |
-
parts = text.split(/\s+/)
|
|
|
|
|
|
|
| 181 |
}
|
| 182 |
-
|
|
|
|
| 183 |
return parts;
|
| 184 |
}
|
| 185 |
|
|
@@ -246,16 +255,27 @@ async function antibot(data) {
|
|
| 246 |
console.log('π DEBUG: Starting matching process...');
|
| 247 |
const result = [];
|
| 248 |
const usedIds = new Set();
|
| 249 |
-
let matchedCount = 0;
|
| 250 |
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
for (let i = 0; i < soalArray.length; i++) {
|
| 253 |
const targetSoal = soalArray[i];
|
| 254 |
console.log(`π― DEBUG: Matching soal "${targetSoal}"`);
|
| 255 |
let foundId = null;
|
| 256 |
|
| 257 |
for (const bot of botResults) {
|
| 258 |
-
if (!usedIds.has(bot.id) && bot.value && bot.value.trim() !== '' &&
|
| 259 |
isValueMatch(bot.value, targetSoal)) {
|
| 260 |
foundId = bot.id;
|
| 261 |
usedIds.add(bot.id);
|
|
@@ -274,70 +294,43 @@ async function antibot(data) {
|
|
| 274 |
|
| 275 |
console.log(`π DEBUG: Initial matches: ${matchedCount}/${soalArray.length}`);
|
| 276 |
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
console.log('π DEBUG: Trying normalized matching...');
|
| 280 |
-
for (let i = 0; i < result.length; i++) {
|
| 281 |
-
if (!result[i].id) {
|
| 282 |
-
const targetSoal = soalArray[i];
|
| 283 |
-
const normalizedSoal = normalizeText(targetSoal);
|
| 284 |
-
|
| 285 |
-
for (const bot of botResults) {
|
| 286 |
-
if (!usedIds.has(bot.id) && bot.normalized && bot.normalized.trim() !== '') {
|
| 287 |
-
if (bot.normalized === normalizedSoal) {
|
| 288 |
-
result[i].id = bot.id;
|
| 289 |
-
result[i].matchType = 'normalized';
|
| 290 |
-
usedIds.add(bot.id);
|
| 291 |
-
matchedCount++;
|
| 292 |
-
console.log(`β
DEBUG: Soal "${targetSoal}" normalized match with bot ${bot.id}`);
|
| 293 |
-
break;
|
| 294 |
-
}
|
| 295 |
-
}
|
| 296 |
-
}
|
| 297 |
-
}
|
| 298 |
-
}
|
| 299 |
-
}
|
| 300 |
-
|
| 301 |
-
console.log(`π DEBUG: After normalized: ${matchedCount}/${soalArray.length}`);
|
| 302 |
-
|
| 303 |
-
// Step 3: Jika masih ada bot yang belum digunakan, assign ke soal yang belum ada jawaban
|
| 304 |
-
const unusedBots = botResults.filter(bot => !usedIds.has(bot.id) && bot.value && bot.value.trim() !== '');
|
| 305 |
-
console.log(`π DEBUG: Unused bots: ${unusedBots.length}`);
|
| 306 |
|
| 307 |
-
for (
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
}
|
| 315 |
}
|
| 316 |
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
console.log(`β DEBUG: Remaining bots to add: ${remainingBots.length}`);
|
| 320 |
|
| 321 |
-
for (const bot of
|
| 322 |
result.push({
|
| 323 |
id: bot.id,
|
| 324 |
soal: '',
|
| 325 |
-
matchType: '
|
| 326 |
});
|
| 327 |
usedIds.add(bot.id);
|
| 328 |
-
console.log(`
|
| 329 |
}
|
| 330 |
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
|
|
|
| 341 |
}
|
| 342 |
|
| 343 |
console.log('π DEBUG: Process completed successfully');
|
|
@@ -358,7 +351,8 @@ async function antibot(data) {
|
|
| 358 |
soal: r.soal
|
| 359 |
})),
|
| 360 |
totalMatches: matchedCount,
|
| 361 |
-
totalResults: result.length
|
|
|
|
| 362 |
}
|
| 363 |
}
|
| 364 |
};
|
|
|
|
| 174 |
|
| 175 |
function parseSoalText(text) {
|
| 176 |
console.log(`π DEBUG parseSoalText: Input text: "${text}"`);
|
| 177 |
+
|
| 178 |
+
const ignoreWords = ['hi', 'how', 'are', 'you', 'hello', 'hey'];
|
| 179 |
+
|
| 180 |
const delimiters = /[.,:;\\/\s]+/;
|
| 181 |
+
let parts = text.split(delimiters)
|
| 182 |
+
.filter(part => part.trim() !== '')
|
| 183 |
+
.filter(part => !ignoreWords.includes(part.toLowerCase()));
|
| 184 |
+
|
| 185 |
if (parts.length === 1) {
|
| 186 |
+
parts = text.split(/\s+/)
|
| 187 |
+
.filter(part => part.trim() !== '')
|
| 188 |
+
.filter(part => !ignoreWords.includes(part.toLowerCase()));
|
| 189 |
}
|
| 190 |
+
|
| 191 |
+
console.log(`π DEBUG parseSoalText: Filtered parts:`, parts);
|
| 192 |
return parts;
|
| 193 |
}
|
| 194 |
|
|
|
|
| 255 |
console.log('π DEBUG: Starting matching process...');
|
| 256 |
const result = [];
|
| 257 |
const usedIds = new Set();
|
|
|
|
| 258 |
|
| 259 |
+
const botAnswerCounts = {};
|
| 260 |
+
botResults.forEach(bot => {
|
| 261 |
+
if (bot.value && bot.value.trim() !== '') {
|
| 262 |
+
const answers = bot.value.split(/[\s,]+/).filter(a => a.trim() !== '');
|
| 263 |
+
botAnswerCounts[bot.id] = answers.length;
|
| 264 |
+
console.log(`π’ DEBUG Bot ${bot.id}: ${answers.length} jawaban - [${answers.join(', ')}]`);
|
| 265 |
+
} else {
|
| 266 |
+
botAnswerCounts[bot.id] = 0;
|
| 267 |
+
console.log(`π’ DEBUG Bot ${bot.id}: 0 jawaban`);
|
| 268 |
+
}
|
| 269 |
+
});
|
| 270 |
+
|
| 271 |
+
let matchedCount = 0;
|
| 272 |
for (let i = 0; i < soalArray.length; i++) {
|
| 273 |
const targetSoal = soalArray[i];
|
| 274 |
console.log(`π― DEBUG: Matching soal "${targetSoal}"`);
|
| 275 |
let foundId = null;
|
| 276 |
|
| 277 |
for (const bot of botResults) {
|
| 278 |
+
if (!usedIds.has(bot.id) && botAnswerCounts[bot.id] >= 2 && bot.value && bot.value.trim() !== '' &&
|
| 279 |
isValueMatch(bot.value, targetSoal)) {
|
| 280 |
foundId = bot.id;
|
| 281 |
usedIds.add(bot.id);
|
|
|
|
| 294 |
|
| 295 |
console.log(`π DEBUG: Initial matches: ${matchedCount}/${soalArray.length}`);
|
| 296 |
|
| 297 |
+
const qualifiedBots = botResults.filter(bot => botAnswerCounts[bot.id] >= 2 && !usedIds.has(bot.id));
|
| 298 |
+
console.log(`β DEBUG: Qualified bots to add: ${qualifiedBots.length}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
+
for (const bot of qualifiedBots) {
|
| 301 |
+
result.push({
|
| 302 |
+
id: bot.id,
|
| 303 |
+
soal: '',
|
| 304 |
+
matchType: 'qualified'
|
| 305 |
+
});
|
| 306 |
+
usedIds.add(bot.id);
|
| 307 |
+
console.log(`β DEBUG: Added qualified bot ${bot.id} to result`);
|
| 308 |
}
|
| 309 |
|
| 310 |
+
const invalidBots = botResults.filter(bot => botAnswerCounts[bot.id] === 1 && !usedIds.has(bot.id));
|
| 311 |
+
console.log(`β DEBUG: Invalid bots (1 jawaban): ${invalidBots.length}`);
|
|
|
|
| 312 |
|
| 313 |
+
for (const bot of invalidBots) {
|
| 314 |
result.push({
|
| 315 |
id: bot.id,
|
| 316 |
soal: '',
|
| 317 |
+
matchType: 'invalid'
|
| 318 |
});
|
| 319 |
usedIds.add(bot.id);
|
| 320 |
+
console.log(`β DEBUG: Added invalid bot ${bot.id} to result`);
|
| 321 |
}
|
| 322 |
|
| 323 |
+
const noAnswerBots = botResults.filter(bot => botAnswerCounts[bot.id] === 0 && !usedIds.has(bot.id));
|
| 324 |
+
console.log(`β DEBUG: No answer bots: ${noAnswerBots.length}`);
|
| 325 |
+
|
| 326 |
+
for (const bot of noAnswerBots) {
|
| 327 |
+
result.push({
|
| 328 |
+
id: bot.id,
|
| 329 |
+
soal: '',
|
| 330 |
+
matchType: 'invalid'
|
| 331 |
+
});
|
| 332 |
+
usedIds.add(bot.id);
|
| 333 |
+
console.log(`β DEBUG: Added no-answer bot ${bot.id} to result`);
|
| 334 |
}
|
| 335 |
|
| 336 |
console.log('π DEBUG: Process completed successfully');
|
|
|
|
| 351 |
soal: r.soal
|
| 352 |
})),
|
| 353 |
totalMatches: matchedCount,
|
| 354 |
+
totalResults: result.length,
|
| 355 |
+
answerCounts: botAnswerCounts
|
| 356 |
}
|
| 357 |
}
|
| 358 |
};
|