Arafath10 commited on
Commit
e57c2bb
·
verified ·
1 Parent(s): 8a3a98f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -96
main.py CHANGED
@@ -1,104 +1,15 @@
1
  import asyncio
2
  from fastapi import FastAPI
 
3
  import requests
4
- import pandas as pd
5
- import json
 
6
 
7
- global data
8
  app = FastAPI()
9
 
10
  # Declare the continuous function as an async function.
11
- async def your_continuous_function():
12
- import pandas as pd
13
- global data
14
- while True:
15
- print("data fetcher running.....")
16
-
17
- # Initialize an empty DataFrame to store the combined data
18
- combined_df = pd.DataFrame()
19
- url = "https://dev3.api.curfox.parallaxtec.com/api/admin/order/metadata"
20
-
21
- payload = {}
22
- headers = {
23
- 'Accept': 'application/json',
24
- 'X-Tenant': 'mng',
25
- 'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiZWQzYjVkN2JkNTU5YmQxNWNmYzdiNThhM2UyZDlmNGEyMGQzMDFjMWY4ZWVlNDY2ZDBlZTAxYmMzZmVjMTU1ZWNjNzMxOWUxMGUxZGY3NDMiLCJpYXQiOjE3MDIyNzIyMDcuNjg0OTE2LCJuYmYiOjE3MDIyNzIyMDcuNjg0OTIzLCJleHAiOjE3MzM4OTQ2MDcuNjczNDYyLCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.NFZvGO0GjoD7u3FRiIewRRoWu7ouUmKTKnCei8LMwQWzLntBLYcj_Bs21amjcHtzdbQNyCovHSDHJQaLJnD04kY1JRAdDC_OLi2YiZoSvnSJxNjWiuC4kwNE59Ndwu3o2iAzB-nd1EvyMnU_na7WxICRP8OegrpM-_q6M-wgnv7igaNeWjdxnXdtxbr-Zz7N2Xv2skWZwoDce37kWvH1tK7eqMK0uWqqyhBpli22CmkKPduHUNKMNOEnGTskeDaTuX5za2Lr8CNa34_FdKu3Y5CrFMGDBHT_UGALocpr80_38iifXm7WDl6ZIA1iYy6dBvCTeoC_aFo1X5FIrFbJgMCokW4VH0Q2ljm9ty0W7ATAiKrM1GIVFS5Dir4A1KI3LSeE459SqZpqsoJmaU95zSYbfnU_oZ9UpvW59nFgD6yJ8hGHyYnjhCS0jmxk3cq93T9X1rNWo2t0A3XYXgqZYnZrZpdrSbn-JVoX_NW1QC6RtmAGm7AtZ3GBrzxwu3m_7MicMI7Tu4W6d2WD9kZjq0khBUrm2DVZJzN2BRmH-a7JkAqJ0icpHQ_2Tc6T-95axebp6QEmHHXBKILNNwWxucZ0l-Ny0TuUivqn0m9gSJJDkA8ssWyBkzzJ9fUeRmJGbUFTeemPhMrF3_cvTUZ0J7IC2CK7qWePcHPQ-sy0is4'
26
- }
27
- count = requests.request("GET", url, headers=headers).json()["data"]["order_count"]//2000
28
- count = count + 2
29
- print(count)
30
- # Loop through pages 1 to 4
31
- for page in range(1,count):
32
- try:
33
- # Update the payload for each page
34
- url = "https://dev3.api.curfox.parallaxtec.com/api/admin/test-dataset?sort=id&paginate=2000&page="+str(page)
35
-
36
- payload = {}
37
- headers = {
38
- 'Accept': 'application/json',
39
- 'X-Tenant': 'mng',
40
- 'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiNDE3YTIyNDE4MGUzNDJmMjRiYzlkMjAyYTk3NWE0MjRiYzhlY2I0NDM3NmI0ZDdiN2M5MTQ5NjI4YTM0ZWM1Y2ZlYmZhMGMzOWFkMmNkZWIiLCJpYXQiOjE2OTA3OTk4MjQuNzgwNzY4LCJuYmYiOjE2OTA3OTk4MjQuNzgwNzcyLCJleHAiOjE3MjI0MjIyMjQuNzcwOTk0LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.OCTRI6oDChKUHsZAbxdrsarqXJEuQpnNuQzo1cp4OWj2KddKfBCMCad9cFA5-aJ2S6INN1WsGZAEa1JtOLSzxnsfLIwRr73ODHiRZM9ZYOLdJukTisbO6ONOkAFbpE48o6CHTFYen_D2QYSxqKmQ1lCO2-FQn18RPK6QOiuHuW1KYTWtxo_wXncRl5Rt2PWyrm88iMClD969-oXcjk-wU7Wr1TFTY01JDLLHYe9sqfUTkRewpzFk2YIg9pt1yTGJRboyF9mqeVcq7fADdOzP7uqUFQnro-dHrzivYYYYXUmc0UBBu7t0FY2SerwHnWObNF-tMxyPX_9xGQjzy9H1NtbvxULIrnqA9WLJBqERhpRGlKH2S_C-eacAUwI548JkwHQGelRJHpAh36xaJqNsOGh0l2HX2LIF52TqdHevj-4FE4AFLPRPqGYYv-v-tL50LRHdbTmLw_n8bpeROba8dNoz7RC-YKdyYRpBsIiaIA78_ltk_-1Qme-u9ArX_Zycf2m9BkefEVpN1DUHOuPRm_pGAyIagkCmMfIFsV9rMiEhCtqT_IV0HmMrBw1OJ2m-c-DxXLdCLpjgiKc4HPb44aCxZgm8s0vJOGGP-2zajtQ1H2IpJ7Zkjyggl4frZ2EkwX4Ay0dsiQxTG5DgKOcQZfvCMgzJCtQPL7So7c8QcUk'
41
- }
42
-
43
- response = requests.request("GET", url, headers=headers)
44
-
45
- import pandas as pd
46
- import json
47
-
48
- # Sample JSON response
49
- json_response = response.json()
50
- # Extracting 'data' for conversion
51
- data = json_response['data']
52
-
53
- df = pd.json_normalize(data)
54
-
55
- # Concatenate the current page's DataFrame with the combined DataFrame
56
- combined_df = pd.concat([combined_df, df], ignore_index=True)
57
- except:
58
- print("data over")
59
- print("data collected....")
60
- data = combined_df[combined_df['status.name'].isin(['RETURN TO CLIENT', 'DELIVERED'])]
61
- data = data[['delivery_possibility','status.name']]
62
- data = data[data['delivery_possibility'].between(0, 100)]
63
-
64
- await asyncio.sleep(43200) # Adjust the sleep interval as needed
65
-
66
- # Create a startup event.
67
- @app.on_event("startup")
68
- async def startup_event():
69
- # Start the continuous function as a background task.
70
- asyncio.create_task(your_continuous_function())
71
-
72
- @app.get("/kpi_results")
73
- def read_root():
74
- global data
75
- status_counts_more_than_80 = data[data['delivery_possibility'] > 80]['status.name'].value_counts()
76
-
77
- status_counts_50_to_80 = data[(data['delivery_possibility'] >= 50) & (data['delivery_possibility'] <= 80)]['status.name'].value_counts()
78
 
79
- status_counts_30_to_49 = data[(data['delivery_possibility'] >= 30) & (data['delivery_possibility'] <= 49)]['status.name'].value_counts()
80
-
81
- status_counts_below_30 = data[data['delivery_possibility'] < 30]['status.name'].value_counts()
82
-
83
-
84
- kpi_result = {
85
- "kpi_result": {
86
- "status_counts_more_than_80": {
87
- "correct_values": str(status_counts_more_than_80[0]),
88
- "incorrect_values": str(status_counts_more_than_80[1])
89
- },
90
- "status_counts_50_to_80": {
91
- "correct_values": str(status_counts_50_to_80[0]),
92
- "incorrect_values": str(status_counts_50_to_80[1])
93
- },
94
- "status_counts_30_to_49": {
95
- "correct_values": str(status_counts_30_to_49[0]),
96
- "incorrect_values": str(status_counts_30_to_49[1])
97
- },
98
- "status_counts_below_30": {
99
- "correct_values": str(status_counts_below_30[0]),
100
- "incorrect_values": str(status_counts_below_30[1])
101
- }
102
- }
103
- }
104
- return kpi_result
 
1
  import asyncio
2
  from fastapi import FastAPI
3
+ from fastapi.responses import StreamingResponse
4
  import requests
5
+ import json,os,openai
6
+
7
+ api_key = os.environ["OPENAI_API_KEY"]
8
 
 
9
  app = FastAPI()
10
 
11
  # Declare the continuous function as an async function.
12
+ async def get_response():
13
+ return "hu"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+