Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -84,7 +84,7 @@ def delete_json(b_id):
|
|
84 |
cursor.close()
|
85 |
connection.close()
|
86 |
|
87 |
-
def get_data(b_id,page_number,page_size):
|
88 |
start = (page_number - 1) * page_size
|
89 |
end = start + page_size
|
90 |
|
@@ -116,15 +116,20 @@ def get_data(b_id,page_number,page_size):
|
|
116 |
bid = row[0]
|
117 |
forecast_data_json = row[1]
|
118 |
created_at = row[2]
|
119 |
-
|
120 |
# Convert JSON string back to Python dictionary
|
121 |
forecast_data = json.loads(forecast_data_json)
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
else:
|
130 |
return f"plesae genertae forcast for this business id:{b_id}"
|
@@ -248,7 +253,30 @@ async def get_product_count_prediction_from_DB(b_id: int,page_number :int,page_s
|
|
248 |
response_content = {
|
249 |
"status": "done",
|
250 |
"message": "data from DB",
|
251 |
-
"data": get_data(b_id,page_number,page_size),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
"status_code":200
|
253 |
}
|
254 |
return response_content
|
|
|
84 |
cursor.close()
|
85 |
connection.close()
|
86 |
|
87 |
+
def get_data(b_id,page_number,page_size,search):
|
88 |
start = (page_number - 1) * page_size
|
89 |
end = start + page_size
|
90 |
|
|
|
116 |
bid = row[0]
|
117 |
forecast_data_json = row[1]
|
118 |
created_at = row[2]
|
119 |
+
|
120 |
# Convert JSON string back to Python dictionary
|
121 |
forecast_data = json.loads(forecast_data_json)
|
122 |
+
|
123 |
+
if search==False:
|
124 |
+
result = {
|
125 |
+
"BID":bid,
|
126 |
+
"created_at":created_at,
|
127 |
+
"forecast_data":forecast_data[start:end]
|
128 |
+
}
|
129 |
+
return result
|
130 |
+
else:
|
131 |
+
return forecast_data
|
132 |
+
|
133 |
|
134 |
else:
|
135 |
return f"plesae genertae forcast for this business id:{b_id}"
|
|
|
253 |
response_content = {
|
254 |
"status": "done",
|
255 |
"message": "data from DB",
|
256 |
+
"data": get_data(b_id,page_number,page_size,False),
|
257 |
+
"status_code":200
|
258 |
+
}
|
259 |
+
return response_content
|
260 |
+
|
261 |
+
|
262 |
+
|
263 |
+
def find_related_products(sub_sku=None, product_name=None,forecast_data=None):
|
264 |
+
print(type(forecast_data))
|
265 |
+
# Filter products based on the given sub_sku or Product Name
|
266 |
+
filtered_products = [
|
267 |
+
item for item in forecast_data
|
268 |
+
if (sub_sku and item['sub_sku'] == sub_sku) or
|
269 |
+
(product_name and item['Product Name'].lower() == product_name.lower())
|
270 |
+
]
|
271 |
+
return filtered_products
|
272 |
+
|
273 |
+
@app.post("/search_results_from_DB")
|
274 |
+
async def get_product_count_prediction_from_DB(b_id: int,search_sku:str,product_name:str):
|
275 |
+
related_products = find_related_products(sub_sku=search_sku, product_name=product_name,forecast_data = get_data(b_id,1,2,True))
|
276 |
+
response_content = {
|
277 |
+
"status": "done",
|
278 |
+
"message": "data from DB",
|
279 |
+
"data": related_products,
|
280 |
"status_code":200
|
281 |
}
|
282 |
return response_content
|