message id fix
This commit is contained in:
parent
51bcef67fe
commit
a95806f3d0
@ -11,8 +11,7 @@ const stringSimilarity = require('string-similarity');
|
||||
|
||||
async function updateUser(uid, mid, name, picture, email) {
|
||||
try {
|
||||
await nonQuery('INSERT INTO "User" (username, name, picture, email) VALUES ($1, $2, $3, $4);', [uid, name, picture, email]);
|
||||
await nonQuery('UPDATE "User" SET message_id = array_append(message_id, $1) WHERE username = $2 ;', [mid, uid]);
|
||||
await nonQuery('INSERT INTO "User" (username, name, picture, email, message_id) VALUES ($1, $2, $3, $4, $5);', [uid, name, picture, email, mid]);
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -297,7 +296,7 @@ async function moveDoneItems(uid, sl_id, billcontent) {
|
||||
|
||||
for (let item of removeableItems) {
|
||||
await nonQuery('INSERT INTO "Done_Purchase" (purchased_item_id, username, name, date, count) VALUES($1,$2,$3,$4,$5);',
|
||||
[generate_item_id(), uid, item.name, today, 1]);
|
||||
[generate_item_id(), uid, item.name, today, item.count]);
|
||||
|
||||
}
|
||||
|
||||
@ -514,17 +513,14 @@ function compareData(listitems, doneitems) {
|
||||
let output = [];
|
||||
|
||||
for (let item of listitems) {
|
||||
if (doneitems.includes(item.name)) {
|
||||
|
||||
if (probability(item.name, doneitems).best > 0.6) {
|
||||
output.push({item: item, count: probability(item.name, doneitems).count});
|
||||
} else if (probability(item.name.toUpperCase(), doneitems.toUpperCase()).best > 0.6) {
|
||||
output.push({item: item, count: probability(item.name, doneitems).count});
|
||||
output.push(item);
|
||||
} else if (doneitems.toUpperCase().includes(item.name.toUpperCase())) {
|
||||
output.push(item);
|
||||
} else if (doneitems.toLowerCase().includes(item.name.toLowerCase())) {
|
||||
output.push(item);
|
||||
} else if (probability(item.name, doneitems) > 0.6) {
|
||||
output.push(item);
|
||||
} else if (probability(item.name.toUpperCase(), doneitems.toUpperCase()) > 0.6) {
|
||||
output.push(item);
|
||||
} else if (probability(item.name.toLowerCase(), doneitems.toLowerCase()) > 0.6) {
|
||||
} else if (probability(item.name.toLowerCase(), doneitems.toLowerCase()).best > 0.6) {
|
||||
output.push({item: item, count: probability(item.name, doneitems).count});
|
||||
output.push(item);
|
||||
}
|
||||
}
|
||||
@ -533,19 +529,33 @@ function compareData(listitems, doneitems) {
|
||||
}
|
||||
|
||||
function probability(cur_item, data) {
|
||||
|
||||
let best = 0;
|
||||
|
||||
let pos;
|
||||
let count = 0;
|
||||
let numbers = "123456789";
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
|
||||
let prob = stringSimilarity.compareTwoStrings(cur_item, data.slice(i, i + cur_item.length));
|
||||
|
||||
if (prob > best) {
|
||||
best = prob;
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
for(let i = pos; i >= 0; i--) {
|
||||
if(numbers.includes(data.charAt(i)) == true) {
|
||||
count = data.charAt(i);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
best: best, count: count
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user