Arafath10 commited on
Commit
8683a5b
1 Parent(s): 6d728e0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +28 -0
main.py CHANGED
@@ -3,6 +3,8 @@ from fastapi.responses import JSONResponse
3
  from fastapi.middleware.cors import CORSMiddleware
4
  import data_collector as dc
5
  import pandas as pd
 
 
6
 
7
  app = FastAPI()
8
  app.add_middleware(
@@ -13,6 +15,32 @@ app.add_middleware(
13
  allow_headers=["*"],
14
  )
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  @app.post("/get_product_count_prediction")
17
  async def get_product_count_prediction(b_id: int):
18
  try:
 
3
  from fastapi.middleware.cors import CORSMiddleware
4
  import data_collector as dc
5
  import pandas as pd
6
+ from prophet import Prophet
7
+ import math
8
 
9
  app = FastAPI()
10
  app.add_middleware(
 
15
  allow_headers=["*"],
16
  )
17
 
18
+
19
+ def forecast(monthly_sales):
20
+ # Prepare the data for Prophet
21
+ monthly_sales.rename(columns={'transaction_date': 'ds', 'sell_qty': 'y'}, inplace=True)
22
+
23
+ # Initialize and fit the Prophet model
24
+ model = Prophet()
25
+ model.fit(monthly_sales)
26
+
27
+ # Make a future dataframe for the next month
28
+ future = model.make_future_dataframe(periods=1, freq='M')
29
+ forecast = model.predict(future)
30
+
31
+ # Extract the forecasted sales for the next month
32
+ forecasted_sales = forecast[['ds', 'yhat']].tail(2)
33
+
34
+ # Combine historical and forecasted data
35
+ combined_sales = pd.concat([monthly_sales, forecasted_sales[-1:]], ignore_index=True)
36
+ original_forecasted_value = combined_sales.tail(1)
37
+ rounded_value = combined_sales.tail(1)
38
+
39
+ rounded_value['yhat'] = rounded_value['yhat'].apply(lambda x: max(0, math.ceil(x)))
40
+
41
+ return combined_sales,original_forecasted_value,rounded_value
42
+
43
+
44
  @app.post("/get_product_count_prediction")
45
  async def get_product_count_prediction(b_id: int):
46
  try: