Skip to content

Commit 22bcca3

Browse files
Merge pull request #67 from Cognic-AI/sahan_last
Sahan last
2 parents 0306f9f + 2fc1763 commit 22bcca3

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

ML_model/firestoreDB.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ def get_customer_history(self, customer_id):
5252

5353
return items_docs
5454

55-
def add_search_result(self, item_id, item_score, customer_id):
55+
def add_search_result(self, item_id, item_score, customer_id,item_name):
5656
print(f"\nAdding search result for Item ID(s): {item_id}, score(s): {item_score}")
5757
self.db.collection("customer").document(customer_id).collection("history").add({
5858
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
5959
"items": item_id,
60-
"score": item_score
60+
"score": item_score,
61+
"item_name":item_name
6162
})
6263

6364
def add_purchase(self, item_id, customer_id):
@@ -89,7 +90,7 @@ def check_csv(self, item_name, country_code):
8990

9091
return False,None
9192

92-
def add_search_item(self, customer_id, item_array):
93+
def add_search_item(self, customer_id, item_array,item_name):
9394
print(f"\nAdding search items for Customer ID: {customer_id}")
9495
item_suggested = []
9596
item_suggested_score = []
@@ -123,7 +124,7 @@ def add_search_item(self, customer_id, item_array):
123124
item_suggested.append(item_id)
124125
item_suggested_score.append(item.score)
125126

126-
self.add_search_result(item_suggested, item_suggested_score, customer_id)
127+
self.add_search_result(item_suggested, item_suggested_score, customer_id,item_name)
127128
self.add_purchase(item_id,customer_id)
128129

129130

Machine_Customer_Endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def recommend():
8888
print("\nSending response to database...")
8989
# Initialize database connection
9090
database = db.FirestoreDB()
91-
database.add_search_item(machine_customer.customer_id, result)
91+
database.add_search_item(machine_customer.customer_id, result,request_data["item_name"])
9292
print("Sending email...")
9393
print(send_email(machine_customer.customer_name, machine_customer.email, result, request_data["item_name"]))
9494
return jsonify({"status": "success and email sent"})

frontend/app/api/firestore.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export const createAccount = async (collectionName, data) => {
6868

6969
// Iterate over each document in the 'history' collection
7070
for (const historyDoc of docs_) {
71-
const folder = {folder:historyDoc.id,items:[]};
71+
const folder_name = historyDoc.get("item_name")!=""?historyDoc.get("item_name"):historyDoc.id;
72+
const folder = {folder:folder_name,items:[]};
7273
const items = [];
7374
const historyItems = historyDoc.get("items"); // Assume 'items' is an array of item IDs
7475
if (Array.isArray(historyItems)) {

0 commit comments

Comments
 (0)