binaychandra commited on
Commit
6e07918
·
1 Parent(s): 26ad899

Adding functions for random data and fixing typos

Browse files
Files changed (2) hide show
  1. app.py +83 -78
  2. helper.py +28 -0
app.py CHANGED
@@ -9,6 +9,8 @@ from fastapi.middleware.cors import CORSMiddleware
9
  from pydantic import BaseModel
10
  from fastapi import Query
11
 
 
 
12
  app = FastAPI()
13
 
14
  # Configure CORS settings
@@ -87,87 +89,90 @@ def run_pred_pipeline(input: PredictionInput):
87
  print(f"Running the pipeline : {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} ")
88
 
89
  ## Hardcoding for testing purposes ##
 
 
90
  data_out = {
91
  "status" : "success",
92
  "data" : {
93
  "id": input.dict()['id'],
94
- "predictions": {
95
- "ASDA": {
96
- "Apr-25": 741.86,
97
- "May-25": 2624.14,
98
- "Jun-25": 808.83,
99
- "Jul-25": 923.99,
100
- "Aug-25": 280.57,
101
- "Sep-25": 13.72,
102
- "Oct-25": 20.58,
103
- "Nov-25": 23.9,
104
- "Dec-25": 1619.17,
105
- "Jan-26": 1123.3,
106
- "Feb-26": 235.05,
107
- "Mar-26": 162.03,
108
- "Apr-26": 410.15
109
- },
110
- "MORRISONS": {
111
- "Apr-25": 2331.82,
112
- "May-25": 12573.63,
113
- "Jun-25": 8536.11,
114
- "Jul-25": 11987.12,
115
- "Aug-25": 7898.69,
116
- "Sep-25": 6396.44,
117
- "Oct-25": 6263.68,
118
- "Nov-25": 4706.39,
119
- "Dec-25": 4583.83,
120
- "Jan-26": 5898.89,
121
- "Feb-26": 4337.92,
122
- "Mar-26": 6339.77,
123
- "Apr-26": 5191.83
124
- },
125
- "SAINSBURYS": {
126
- "Apr-25": 392.79,
127
- "May-25": 4353.46,
128
- "Jun-25": 2627.94,
129
- "Jul-25": 3361.95,
130
- "Aug-25": 5763.03,
131
- "Sep-25": 2985.44,
132
- "Oct-25": 3457.49,
133
- "Nov-25": 2631.01,
134
- "Dec-25": 2645.14,
135
- "Jan-26": 3034.98,
136
- "Feb-26": 2958.94,
137
- "Mar-26": 4043.73,
138
- "Apr-26": 3364.26
139
- },
140
- "TESCO": {
141
- "Apr-25": 2302.79,
142
- "May-25": 18921.9,
143
- "Jun-25": 17958.08,
144
- "Jul-25": 18710.57,
145
- "Aug-25": 13609.1,
146
- "Sep-25": 18693.05,
147
- "Oct-25": 21091.39,
148
- "Nov-25": 18796.81,
149
- "Dec-25": 21114.51,
150
- "Jan-26": 20039.52,
151
- "Feb-26": 21608.5,
152
- "Mar-26": 22534.27,
153
- "Apr-26": 16405.85
154
- },
155
- "TOTAL_MARKET": {
156
- "Apr-25": 10964.68,
157
- "May-25": 77262.14,
158
- "Jun-25": 62432.31,
159
- "Jul-25": 76078.74,
160
- "Aug-25": 52031.48,
161
- "Sep-25": 47737.41,
162
- "Oct-25": 51094.34,
163
- "Nov-25": 42181.84,
164
- "Dec-25": 47680.7,
165
- "Jan-26": 50010.67,
166
- "Feb-26": 46154.89,
167
- "Mar-26": 49339.0,
168
- "Apr-26": 39747.65
169
- }
170
- }
 
171
  }
172
  }
173
 
@@ -290,7 +295,7 @@ async def query_ai(request: QueryRequest):
290
  "status": "success",
291
  "data": {
292
  "baseCode": "GB10002",
293
- "scenario": "scenatio_01",
294
  "weekDate": "2025-04-28",
295
  "levelOfSugar": "STANDARD",
296
  "packGroup": "CHOC ADULT SGLS",
 
9
  from pydantic import BaseModel
10
  from fastapi import Query
11
 
12
+ from helper import generate_random_predictions
13
+
14
  app = FastAPI()
15
 
16
  # Configure CORS settings
 
89
  print(f"Running the pipeline : {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} ")
90
 
91
  ## Hardcoding for testing purposes ##
92
+
93
+ temp_predictions_dict = generate_random_predictions()
94
  data_out = {
95
  "status" : "success",
96
  "data" : {
97
  "id": input.dict()['id'],
98
+ "predictions": temp_predictions_dict
99
+ # "predictions": {
100
+ # "ASDA": {
101
+ # "Apr-25": 741.86,
102
+ # "May-25": 2624.14,
103
+ # "Jun-25": 808.83,
104
+ # "Jul-25": 923.99,
105
+ # "Aug-25": 280.57,
106
+ # "Sep-25": 13.72,
107
+ # "Oct-25": 20.58,
108
+ # "Nov-25": 23.9,
109
+ # "Dec-25": 1619.17,
110
+ # "Jan-26": 1123.3,
111
+ # "Feb-26": 235.05,
112
+ # "Mar-26": 162.03,
113
+ # "Apr-26": 410.15
114
+ # },
115
+ # "MORRISONS": {
116
+ # "Apr-25": 2331.82,
117
+ # "May-25": 12573.63,
118
+ # "Jun-25": 8536.11,
119
+ # "Jul-25": 11987.12,
120
+ # "Aug-25": 7898.69,
121
+ # "Sep-25": 6396.44,
122
+ # "Oct-25": 6263.68,
123
+ # "Nov-25": 4706.39,
124
+ # "Dec-25": 4583.83,
125
+ # "Jan-26": 5898.89,
126
+ # "Feb-26": 4337.92,
127
+ # "Mar-26": 6339.77,
128
+ # "Apr-26": 5191.83
129
+ # },
130
+ # "SAINSBURYS": {
131
+ # "Apr-25": 392.79,
132
+ # "May-25": 4353.46,
133
+ # "Jun-25": 2627.94,
134
+ # "Jul-25": 3361.95,
135
+ # "Aug-25": 5763.03,
136
+ # "Sep-25": 2985.44,
137
+ # "Oct-25": 3457.49,
138
+ # "Nov-25": 2631.01,
139
+ # "Dec-25": 2645.14,
140
+ # "Jan-26": 3034.98,
141
+ # "Feb-26": 2958.94,
142
+ # "Mar-26": 4043.73,
143
+ # "Apr-26": 3364.26
144
+ # },
145
+ # "TESCO": {
146
+ # "Apr-25": 2302.79,
147
+ # "May-25": 18921.9,
148
+ # "Jun-25": 17958.08,
149
+ # "Jul-25": 18710.57,
150
+ # "Aug-25": 13609.1,
151
+ # "Sep-25": 18693.05,
152
+ # "Oct-25": 21091.39,
153
+ # "Nov-25": 18796.81,
154
+ # "Dec-25": 21114.51,
155
+ # "Jan-26": 20039.52,
156
+ # "Feb-26": 21608.5,
157
+ # "Mar-26": 22534.27,
158
+ # "Apr-26": 16405.85
159
+ # },
160
+ # "TOTAL_MARKET": {
161
+ # "Apr-25": 10964.68,
162
+ # "May-25": 77262.14,
163
+ # "Jun-25": 62432.31,
164
+ # "Jul-25": 76078.74,
165
+ # "Aug-25": 52031.48,
166
+ # "Sep-25": 47737.41,
167
+ # "Oct-25": 51094.34,
168
+ # "Nov-25": 42181.84,
169
+ # "Dec-25": 47680.7,
170
+ # "Jan-26": 50010.67,
171
+ # "Feb-26": 46154.89,
172
+ # "Mar-26": 49339.0,
173
+ # "Apr-26": 39747.65
174
+ # }
175
+ # }
176
  }
177
  }
178
 
 
295
  "status": "success",
296
  "data": {
297
  "baseCode": "GB10002",
298
+ "scenario": "SAMPLE_EUCO_Scenario",
299
  "weekDate": "2025-04-28",
300
  "levelOfSugar": "STANDARD",
301
  "packGroup": "CHOC ADULT SGLS",
helper.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+
4
+ def generate_random_predictions():
5
+
6
+ # Number of rows and columns
7
+ num_rows = 13
8
+ num_cols = 5 # Including Total Market
9
+
10
+ # Create a DataFrame with random float numbers
11
+ data = {}
12
+ column_names = ["ASDA", "MORRISONS", "SAINSBURYS", "TESCO", "TOTAL_MARKET"]
13
+ months = [f"{month}-{year}" for year in [25,26] for month in ["Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar"]][:13]
14
+ for col in column_names:
15
+ data[col] = np.random.rand(num_rows) * 10000 # Random float numbers up to 10000
16
+
17
+ df = pd.DataFrame(data, index=months)
18
+
19
+ # Ensure Total Markets is greater than the sum of others
20
+ for index in df.index:
21
+ total_others = sum(df.loc[index, : "TESCO"])
22
+ df.loc[index, "TOTAL_MARKET"] = total_others + np.random.rand()*1000 # Add a random value to guarantee it is larger
23
+
24
+
25
+ df = df.round(2)
26
+ df_dict = df.to_dict()
27
+
28
+ return df_dict