From 21a3834a477636ff31c2f381f38eec43fe4319d7 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 17 Nov 2022 14:12:12 +0100 Subject: [PATCH 1/8] add logs --- src/appointment.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/appointment.js b/src/appointment.js index 078ac6b..7dd81bb 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -107,6 +107,8 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT return } let segmentNumber = listToBook.length / devices.length; + console.log("connected device number:" + listToBook.length) + console.log("segmentNumber:" + segmentNumber) for (let i = 0; i < devices.length; i++) { startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); } From 3776e73c6f5dca179533eab88c333cf2aa02875c Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 17 Nov 2022 14:15:52 +0100 Subject: [PATCH 2/8] filter blacklisted items before booking --- src/appointment.js | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/appointment.js b/src/appointment.js index 7dd81bb..ec86aa9 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -21,6 +21,17 @@ async function filterAlreadyBookedContacts(contactList) { return contactsToBook; } +async function filterBlacklistedContacts(contactList) { + let blackListedContacts = await mongoManager.getAllBlackedListItems(collectionName); + let contactsToBook = []; + contactList.forEach((contact) => { + if (blackListedContacts.find((bookedContact) => bookedContact.email === contact.mail) === undefined) { + contactsToBook.push(contact) + } + }) + return contactsToBook; +} + async function needToBook(contact, mongoManager) { console.log("check contact with email " + contact.mail) let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); @@ -99,21 +110,24 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT return } mongoManager.connect().then(r => { - filterAlreadyBookedContacts(contactList).then(listToBook => { - console.log("number of contacts to book:" + listToBook.length) - android.devices().then((devices) => { - if (devices.length === 0) { - alert("未找到连接的设备"); - return - } - let segmentNumber = listToBook.length / devices.length; - console.log("connected device number:" + listToBook.length) - console.log("segmentNumber:" + segmentNumber) - for (let i = 0; i < devices.length; i++) { - startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); - } - }) - }) + filterBlacklistedContacts(contactList).then(listWithoutBlackContact => { + filterAlreadyBookedContacts(listWithoutBlackContact).then(listToBook => { + console.log("number of contacts to book:" + listToBook.length) + android.devices().then((devices) => { + if (devices.length === 0) { + alert("未找到连接的设备"); + return + } + let segmentNumber = listToBook.length / devices.length; + console.log("connected device number:" + listToBook.length) + console.log("segmentNumber:" + segmentNumber) + for (let i = 0; i < devices.length; i++) { + startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); + } + }) + }) + } + ) } ) } From 85c2102c006661b217157066eaf88e7859864d2a Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 17 Nov 2022 14:55:50 +0100 Subject: [PATCH 3/8] filter blacklisted items before booking --- src/appointment.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/appointment.js b/src/appointment.js index ec86aa9..3d6635e 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -25,8 +25,19 @@ async function filterBlacklistedContacts(contactList) { let blackListedContacts = await mongoManager.getAllBlackedListItems(collectionName); let contactsToBook = []; contactList.forEach((contact) => { - if (blackListedContacts.find((bookedContact) => bookedContact.email === contact.mail) === undefined) { + let blackListedItem = blackListedContacts.find((bookedContact) => bookedContact.email === contact.mail) + if (blackListedItem === undefined) { contactsToBook.push(contact) + } else { + console.log("=====handle blacklist item before booking===="); + console.log("update_at_s is " + blackListedItem.update_at_in_s) + console.log("black list email is " + blackListedItem.mail) + let needToBook = blackListedItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000; + if (!needToBook) { + console.log("contact in blacklist -->skip"); + } else { + contactsToBook.push(contact) + } } }) return contactsToBook; From 139e9ab47ef246a4f9a035768064bd4ee71e176c Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 17 Nov 2022 15:03:39 +0100 Subject: [PATCH 4/8] filter blacklisted items before booking --- src/appointment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/appointment.js b/src/appointment.js index 3d6635e..c9f393b 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -22,7 +22,7 @@ async function filterAlreadyBookedContacts(contactList) { } async function filterBlacklistedContacts(contactList) { - let blackListedContacts = await mongoManager.getAllBlackedListItems(collectionName); + let blackListedContacts = await mongoManager.getAllBlackedListItems(); let contactsToBook = []; contactList.forEach((contact) => { let blackListedItem = blackListedContacts.find((bookedContact) => bookedContact.email === contact.mail) @@ -130,7 +130,7 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT return } let segmentNumber = listToBook.length / devices.length; - console.log("connected device number:" + listToBook.length) + console.log("connected device number:" + devices.length) console.log("segmentNumber:" + segmentNumber) for (let i = 0; i < devices.length; i++) { startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); From cb4823ff6939cd86cf98db3fc92e2a717ee16f75 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 17 Nov 2022 15:14:55 +0100 Subject: [PATCH 5/8] filter blacklisted items before booking --- src/appointment.js | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/appointment.js b/src/appointment.js index c9f393b..b36b9a0 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -14,7 +14,19 @@ async function filterAlreadyBookedContacts(contactList) { let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName); let contactsToBook = []; contactList.forEach((contact) => { - if (alreadyBookedContacts.find((bookedContact) => bookedContact.email === contact.mail) === undefined) { + let needToBook = true; + alreadyBookedContacts.forEach((acceptedItem) => { + if (acceptedItem.email === contact.mail) { + console.log("=====handle already accepted item before booking===="); + console.log("accepted_at is " + acceptedItem.accepted_at); + console.log("accepted email is " + acceptedItem.email); + needToBook = acceptedItem.accepted_at + THIRTY_DAYS_IN_S <= (new Date()) / 1000; + if (!needToBook) { + console.log("already accepted appointment --> skip"); + } + } + }) + if (needToBook) { contactsToBook.push(contact) } }) @@ -25,20 +37,21 @@ async function filterBlacklistedContacts(contactList) { let blackListedContacts = await mongoManager.getAllBlackedListItems(); let contactsToBook = []; contactList.forEach((contact) => { - let blackListedItem = blackListedContacts.find((bookedContact) => bookedContact.email === contact.mail) - if (blackListedItem === undefined) { - contactsToBook.push(contact) - } else { - console.log("=====handle blacklist item before booking===="); - console.log("update_at_s is " + blackListedItem.update_at_in_s) - console.log("black list email is " + blackListedItem.mail) - let needToBook = blackListedItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000; - if (!needToBook) { - console.log("contact in blacklist -->skip"); - } else { + let needToBook = true; + blackListedContacts.forEach((blackListItem) => { + if (blackListItem.mail === contact.mail) { + console.log("=====handle blacklist item before booking====="); + console.log("update_at_s is " + blackListItem.update_at_in_s) + console.log("black list email is " + blackListItem.mail) + needToBook = blackListItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000; + if (!needToBook) { + console.log("contact in blacklist -->skip"); + } + } + if (needToBook) { contactsToBook.push(contact) } - } + }) }) return contactsToBook; } From e5574b5686a07845f122720a4de1bcafa1b09071 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 17 Nov 2022 15:25:42 +0100 Subject: [PATCH 6/8] filter blacklisted items before booking --- src/appointment.js | 47 +++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/appointment.js b/src/appointment.js index b36b9a0..bc25640 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -13,6 +13,17 @@ let collectionName = formatDate(new Date()) async function filterAlreadyBookedContacts(contactList) { let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName); let contactsToBook = []; + contactList.forEach((contact) => { + if (alreadyBookedContacts.find((bookedContact) => bookedContact.email === contact.mail) === undefined) { + contactsToBook.push(contact) + } + }) + return contactsToBook; +} + +async function filterAlreadyAccepteddContacts(contactList) { + let alreadyBookedContacts = await mongoManager.getAllAcceptedAppointments(); + let contactsToBook = []; contactList.forEach((contact) => { let needToBook = true; alreadyBookedContacts.forEach((acceptedItem) => { @@ -134,24 +145,26 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT return } mongoManager.connect().then(r => { - filterBlacklistedContacts(contactList).then(listWithoutBlackContact => { - filterAlreadyBookedContacts(listWithoutBlackContact).then(listToBook => { - console.log("number of contacts to book:" + listToBook.length) - android.devices().then((devices) => { - if (devices.length === 0) { - alert("未找到连接的设备"); - return - } - let segmentNumber = listToBook.length / devices.length; - console.log("connected device number:" + devices.length) - console.log("segmentNumber:" + segmentNumber) - for (let i = 0; i < devices.length; i++) { - startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); - } + filterAlreadyAccepteddContacts(contactList).then(notAcceptedContacts => { + filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => { + filterAlreadyBookedContacts(listWithoutBlackContact).then(listToBook => { + console.log("number of contacts to book:" + listToBook.length) + android.devices().then((devices) => { + if (devices.length === 0) { + alert("未找到连接的设备"); + return + } + let segmentNumber = listToBook.length / devices.length; + console.log("connected device number:" + devices.length) + console.log("segmentNumber:" + segmentNumber) + for (let i = 0; i < devices.length; i++) { + startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); + } + }) }) - }) - } - ) + } + ) + }) } ) } From 923b2f1dc2c5d414922fa4cf45166661d9762267 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Fri, 18 Nov 2022 12:47:11 +0100 Subject: [PATCH 7/8] local changes --- clear_data.sh | 22 +++++++++++++++++++++- src/appointment.js | 13 ++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/clear_data.sh b/clear_data.sh index f8b9611..3864ee7 100644 --- a/clear_data.sh +++ b/clear_data.sh @@ -96,4 +96,24 @@ adb -s 2140c70c shell am start -n com.android.chrome/com.google.android.apps.chr #asus zenfone 3 adb -s G7AZCY07H415CT3 shell pm clear com.android.chrome adb -s G7AZCY07H415CT3 shell am set-debug-app --persistent com.android.chrome -adb -s G7AZCY07H415CT3 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main \ No newline at end of file +adb -s G7AZCY07H415CT3 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#xiao mi +adb -s 192.168.56.107:5555 shell pm clear com.android.chrome +adb -s 192.168.56.107:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.56.107:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#xiao mi +adb -s 192.168.56.105:5555 shell pm clear com.android.chrome +adb -s 192.168.56.105:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.56.105:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#xiao mi +adb -s 192.168.56.109:5555 shell pm clear com.android.chrome +adb -s 192.168.56.109:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.56.109:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#xiao mi +adb -s 192.168.56.110:5555 shell pm clear com.android.chrome +adb -s 192.168.56.110:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.56.110:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main \ No newline at end of file diff --git a/src/appointment.js b/src/appointment.js index bc25640..f1540e4 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -145,28 +145,27 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT return } mongoManager.connect().then(r => { - filterAlreadyAccepteddContacts(contactList).then(notAcceptedContacts => { + filterAlreadyBookedContacts(contactList).then((listToBook)=>{ + filterAlreadyAccepteddContacts(listToBook).then(notAcceptedContacts => { filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => { - filterAlreadyBookedContacts(listWithoutBlackContact).then(listToBook => { - console.log("number of contacts to book:" + listToBook.length) + console.log("number of contacts to book:" + listWithoutBlackContact.length) android.devices().then((devices) => { if (devices.length === 0) { alert("未找到连接的设备"); return } - let segmentNumber = listToBook.length / devices.length; + let segmentNumber = listWithoutBlackContact.length / devices.length; console.log("connected device number:" + devices.length) console.log("segmentNumber:" + segmentNumber) for (let i = 0; i < devices.length; i++) { - startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); + startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); } }) }) } ) }) - } - ) + }); } module.exports = startBookWithNumbers \ No newline at end of file From 621fa57f92ddb136bebcb83b1607c66191a3087b Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Mon, 21 Nov 2022 14:06:08 +0100 Subject: [PATCH 8/8] optimization --- src/appointment.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/appointment.js b/src/appointment.js index f1540e4..2744fb7 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -59,10 +59,10 @@ async function filterBlacklistedContacts(contactList) { console.log("contact in blacklist -->skip"); } } - if (needToBook) { - contactsToBook.push(contact) - } }) + if (needToBook) { + contactsToBook.push(contact) + } }) return contactsToBook; }