jcnok commited on
Commit
f7dfb2c
·
verified ·
1 Parent(s): cf1bf05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -26,7 +26,7 @@ app = FastAPI()
26
  async def get_total_revenue(ano: int):
27
  with engine.connect() as conn:
28
  stmt = text(
29
- f"SELECT * FROM gold_total_revenue WHERE year = {ano}"
30
  ) # Usa a função text() para executar a consulta
31
  result = conn.execute(stmt).fetchone()
32
  if result:
@@ -39,7 +39,7 @@ async def get_total_revenue(ano: int):
39
  @app.get("/total_sales/{ano}") # Adiciona o parâmetro 'ano'
40
  async def get_total_sales(ano: int):
41
  with engine.connect() as conn:
42
- stmt = text(f"SELECT * FROM gold_total_sales WHERE year = {ano}")
43
  result = conn.execute(stmt).fetchone()
44
  if result:
45
  return {"total_sales": result[0]}
@@ -51,7 +51,7 @@ async def get_total_sales(ano: int):
51
  @app.get("/average_sale_value/{ano}") # Adiciona o parâmetro 'ano'
52
  async def get_average_sale_value(ano: int):
53
  with engine.connect() as conn:
54
- stmt = text(f"SELECT * FROM gold_average_sale_value WHERE year = {ano}")
55
  result = conn.execute(stmt).fetchone()
56
  if result:
57
  return {"average_sale_value": result[0]}
@@ -63,7 +63,7 @@ async def get_average_sale_value(ano: int):
63
  @app.get("/average_products_per_sale/{ano}") # Adiciona o parâmetro 'ano'
64
  async def get_average_products_per_sale(ano: int):
65
  with engine.connect() as conn:
66
- stmt = text(f"SELECT * FROM gold_average_products_per_sale WHERE year = {ano}")
67
  result = conn.execute(stmt).fetchone()
68
  if result:
69
  return {"average_products_per_sale": result[0]}
@@ -75,7 +75,7 @@ async def get_average_products_per_sale(ano: int):
75
  @app.get("/average_ticket/{ano}") # Adiciona o parâmetro 'ano'
76
  async def get_average_ticket(ano: int):
77
  with engine.connect() as conn:
78
- stmt = text(f"SELECT * FROM gold_average_ticket WHERE year = {ano}")
79
  result = conn.execute(stmt).fetchone()
80
  if result:
81
  return {"average_ticket": result[0]}
@@ -87,7 +87,7 @@ async def get_average_ticket(ano: int):
87
  @app.get("/best_selling_product_value/{ano}") # Adiciona o parâmetro 'ano'
88
  async def get_best_selling_product_value(ano: int):
89
  with engine.connect() as conn:
90
- stmt = text(f"SELECT * FROM gold_best_selling_product_value WHERE year = {ano}")
91
  result = conn.execute(stmt).fetchone()
92
  if result:
93
  return {"produto": result[0], "total_product_revenue": result[1]}
@@ -99,7 +99,7 @@ async def get_best_selling_product_value(ano: int):
99
  @app.get("/best_selling_product_quantity/{ano}") # Adiciona o parâmetro 'ano'
100
  async def get_best_selling_product_quantity(ano: int):
101
  with engine.connect() as conn:
102
- stmt = text(f"SELECT * FROM gold_best_selling_product_quantity WHERE year = {ano}")
103
  result = conn.execute(stmt).fetchone()
104
  if result:
105
  return {"produto": result[0], "total_product_quantity": result[1]}
@@ -111,7 +111,7 @@ async def get_best_selling_product_quantity(ano: int):
111
  @app.get("/product_revenue/{ano}") # Adiciona o parâmetro 'ano'
112
  async def get_product_revenue(ano: int):
113
  with engine.connect() as conn:
114
- results = conn.execute(text(f"SELECT * FROM gold_product_revenue WHERE year = {ano}")).fetchall()
115
  if results:
116
  return [{"produto": row[0], "product_revenue": row[1]} for row in results]
117
  else:
@@ -122,7 +122,7 @@ async def get_product_revenue(ano: int):
122
  @app.get("/top_salesperson_value/{ano}") # Adiciona o parâmetro 'ano'
123
  async def get_top_salesperson_value(ano: int):
124
  with engine.connect() as conn:
125
- stmt = text(f"SELECT * FROM gold_top_salesperson_value WHERE year = {ano}")
126
  result = conn.execute(stmt).fetchone()
127
  if result:
128
  return {"email": result[0], "salesperson_total_revenue": result[1]}
@@ -134,7 +134,7 @@ async def get_top_salesperson_value(ano: int):
134
  @app.get("/top_salesperson_quantity/{ano}") # Adiciona o parâmetro 'ano'
135
  async def get_top_salesperson_quantity(ano: int):
136
  with engine.connect() as conn:
137
- stmt = text(f"SELECT * FROM gold_top_salesperson_quantity WHERE year = {ano}")
138
  result = conn.execute(stmt).fetchone()
139
  if result:
140
  return {"email": result[0], "salesperson_total_sales": result[1]}
@@ -146,7 +146,7 @@ async def get_top_salesperson_quantity(ano: int):
146
  @app.get("/sales_per_salesperson/{ano}") # Adiciona o parâmetro 'ano'
147
  async def get_sales_per_salesperson(ano: int):
148
  with engine.connect() as conn:
149
- results = conn.execute(text(f"SELECT * FROM gold_sales_per_salesperson WHERE year = {ano}")).fetchall()
150
  if results:
151
  return [
152
  {"email": row[0], "sales_per_salesperson": row[1]} for row in results
@@ -160,7 +160,7 @@ async def get_sales_per_salesperson(ano: int):
160
  async def get_revenue_per_salesperson(ano: int):
161
  with engine.connect() as conn:
162
  results = conn.execute(
163
- text(f"SELECT * FROM gold_revenue_per_salesperson WHERE year = {ano}")
164
  ).fetchall()
165
  if results:
166
  return [
@@ -174,7 +174,7 @@ async def get_revenue_per_salesperson(ano: int):
174
  @app.get("/sales_per_day/{ano}") # Adiciona o parâmetro 'ano'
175
  async def get_sales_per_day(ano: int):
176
  with engine.connect() as conn:
177
- results = conn.execute(text(f"SELECT * FROM gold_sales_per_day WHERE year = {ano}")).fetchall()
178
  if results:
179
  return [
180
  {"sales_date": str(row[0]), "sales_per_day": row[1]} for row in results
@@ -187,7 +187,7 @@ async def get_sales_per_day(ano: int):
187
  @app.get("/sales_per_month/{ano}") # Adiciona o parâmetro 'ano'
188
  async def get_sales_per_month(ano: int):
189
  with engine.connect() as conn:
190
- results = conn.execute(text(f"SELECT * FROM gold_sales_per_month WHERE year = {ano}")).fetchall()
191
  if results:
192
  return [
193
  {"sales_year": row[0], "sales_month": row[1], "sales_per_month": row[2]}
@@ -202,7 +202,7 @@ async def get_sales_per_month(ano: int):
202
  @app.get("/sales_per_year/{ano}") # Adiciona o parâmetro 'ano'
203
  async def get_sales_per_year(ano: int):
204
  with engine.connect() as conn:
205
- results = conn.execute(text(f"SELECT * FROM gold_sales_per_year WHERE year = {ano}")).fetchall()
206
  if results:
207
  return [{"sales_year": row[0], "sales_per_year": row[1]} for row in results]
208
  else:
@@ -213,7 +213,7 @@ async def get_sales_per_year(ano: int):
213
  @app.get("/revenue_per_day/{ano}") # Adiciona o parâmetro 'ano'
214
  async def get_revenue_per_day(ano: int):
215
  with engine.connect() as conn:
216
- results = conn.execute(text(f"SELECT * FROM gold_revenue_per_day WHERE year = {ano}")).fetchall()
217
  if results:
218
  return [
219
  {"revenue_date": str(row[0]), "revenue_per_day": row[1]}
@@ -227,7 +227,7 @@ async def get_revenue_per_day(ano: int):
227
  @app.get("/revenue_per_month/{ano}") # Adiciona o parâmetro 'ano'
228
  async def get_revenue_per_month(ano: int):
229
  with engine.connect() as conn:
230
- results = conn.execute(text(f"SELECT * FROM gold_revenue_per_month WHERE year = {ano}")).fetchall()
231
  if results:
232
  return [
233
  {"revenue_year": row[0], "revenue_month": row[1], "revenue_per_month": row[2]}
@@ -241,7 +241,7 @@ async def get_revenue_per_month(ano: int):
241
  @app.get("/revenue_per_year/{ano}") # Adiciona o parâmetro 'ano'
242
  async def get_revenue_per_year(ano: int):
243
  with engine.connect() as conn:
244
- results = conn.execute(text(f"SELECT * FROM gold_revenue_per_year WHERE year = {ano}")).fetchall()
245
  if results:
246
  return [
247
  {"revenue_year": row[0], "revenue_per_year": row[1]} for row in results
 
26
  async def get_total_revenue(ano: int):
27
  with engine.connect() as conn:
28
  stmt = text(
29
+ f"SELECT * FROM total_revenue WHERE year = {ano}"
30
  ) # Usa a função text() para executar a consulta
31
  result = conn.execute(stmt).fetchone()
32
  if result:
 
39
  @app.get("/total_sales/{ano}") # Adiciona o parâmetro 'ano'
40
  async def get_total_sales(ano: int):
41
  with engine.connect() as conn:
42
+ stmt = text(f"SELECT * FROM total_sales WHERE year = {ano}")
43
  result = conn.execute(stmt).fetchone()
44
  if result:
45
  return {"total_sales": result[0]}
 
51
  @app.get("/average_sale_value/{ano}") # Adiciona o parâmetro 'ano'
52
  async def get_average_sale_value(ano: int):
53
  with engine.connect() as conn:
54
+ stmt = text(f"SELECT * FROM average_sale_value WHERE year = {ano}")
55
  result = conn.execute(stmt).fetchone()
56
  if result:
57
  return {"average_sale_value": result[0]}
 
63
  @app.get("/average_products_per_sale/{ano}") # Adiciona o parâmetro 'ano'
64
  async def get_average_products_per_sale(ano: int):
65
  with engine.connect() as conn:
66
+ stmt = text(f"SELECT * FROM average_products_per_sale WHERE year = {ano}")
67
  result = conn.execute(stmt).fetchone()
68
  if result:
69
  return {"average_products_per_sale": result[0]}
 
75
  @app.get("/average_ticket/{ano}") # Adiciona o parâmetro 'ano'
76
  async def get_average_ticket(ano: int):
77
  with engine.connect() as conn:
78
+ stmt = text(f"SELECT * FROM average_ticket WHERE year = {ano}")
79
  result = conn.execute(stmt).fetchone()
80
  if result:
81
  return {"average_ticket": result[0]}
 
87
  @app.get("/best_selling_product_value/{ano}") # Adiciona o parâmetro 'ano'
88
  async def get_best_selling_product_value(ano: int):
89
  with engine.connect() as conn:
90
+ stmt = text(f"SELECT * FROM best_selling_product_value WHERE year = {ano}")
91
  result = conn.execute(stmt).fetchone()
92
  if result:
93
  return {"produto": result[0], "total_product_revenue": result[1]}
 
99
  @app.get("/best_selling_product_quantity/{ano}") # Adiciona o parâmetro 'ano'
100
  async def get_best_selling_product_quantity(ano: int):
101
  with engine.connect() as conn:
102
+ stmt = text(f"SELECT * FROM best_selling_product_quantity WHERE year = {ano}")
103
  result = conn.execute(stmt).fetchone()
104
  if result:
105
  return {"produto": result[0], "total_product_quantity": result[1]}
 
111
  @app.get("/product_revenue/{ano}") # Adiciona o parâmetro 'ano'
112
  async def get_product_revenue(ano: int):
113
  with engine.connect() as conn:
114
+ results = conn.execute(text(f"SELECT * FROM product_revenue WHERE year = {ano}")).fetchall()
115
  if results:
116
  return [{"produto": row[0], "product_revenue": row[1]} for row in results]
117
  else:
 
122
  @app.get("/top_salesperson_value/{ano}") # Adiciona o parâmetro 'ano'
123
  async def get_top_salesperson_value(ano: int):
124
  with engine.connect() as conn:
125
+ stmt = text(f"SELECT * FROM top_salesperson_value WHERE year = {ano}")
126
  result = conn.execute(stmt).fetchone()
127
  if result:
128
  return {"email": result[0], "salesperson_total_revenue": result[1]}
 
134
  @app.get("/top_salesperson_quantity/{ano}") # Adiciona o parâmetro 'ano'
135
  async def get_top_salesperson_quantity(ano: int):
136
  with engine.connect() as conn:
137
+ stmt = text(f"SELECT * FROM top_salesperson_quantity WHERE year = {ano}")
138
  result = conn.execute(stmt).fetchone()
139
  if result:
140
  return {"email": result[0], "salesperson_total_sales": result[1]}
 
146
  @app.get("/sales_per_salesperson/{ano}") # Adiciona o parâmetro 'ano'
147
  async def get_sales_per_salesperson(ano: int):
148
  with engine.connect() as conn:
149
+ results = conn.execute(text(f"SELECT * FROM sales_per_salesperson WHERE year = {ano}")).fetchall()
150
  if results:
151
  return [
152
  {"email": row[0], "sales_per_salesperson": row[1]} for row in results
 
160
  async def get_revenue_per_salesperson(ano: int):
161
  with engine.connect() as conn:
162
  results = conn.execute(
163
+ text(f"SELECT * FROM revenue_per_salesperson WHERE year = {ano}")
164
  ).fetchall()
165
  if results:
166
  return [
 
174
  @app.get("/sales_per_day/{ano}") # Adiciona o parâmetro 'ano'
175
  async def get_sales_per_day(ano: int):
176
  with engine.connect() as conn:
177
+ results = conn.execute(text(f"SELECT * FROM sales_per_day WHERE year = {ano}")).fetchall()
178
  if results:
179
  return [
180
  {"sales_date": str(row[0]), "sales_per_day": row[1]} for row in results
 
187
  @app.get("/sales_per_month/{ano}") # Adiciona o parâmetro 'ano'
188
  async def get_sales_per_month(ano: int):
189
  with engine.connect() as conn:
190
+ results = conn.execute(text(f"SELECT * FROM sales_per_month WHERE year = {ano}")).fetchall()
191
  if results:
192
  return [
193
  {"sales_year": row[0], "sales_month": row[1], "sales_per_month": row[2]}
 
202
  @app.get("/sales_per_year/{ano}") # Adiciona o parâmetro 'ano'
203
  async def get_sales_per_year(ano: int):
204
  with engine.connect() as conn:
205
+ results = conn.execute(text(f"SELECT * FROM sales_per_year WHERE year = {ano}")).fetchall()
206
  if results:
207
  return [{"sales_year": row[0], "sales_per_year": row[1]} for row in results]
208
  else:
 
213
  @app.get("/revenue_per_day/{ano}") # Adiciona o parâmetro 'ano'
214
  async def get_revenue_per_day(ano: int):
215
  with engine.connect() as conn:
216
+ results = conn.execute(text(f"SELECT * FROM revenue_per_day WHERE year = {ano}")).fetchall()
217
  if results:
218
  return [
219
  {"revenue_date": str(row[0]), "revenue_per_day": row[1]}
 
227
  @app.get("/revenue_per_month/{ano}") # Adiciona o parâmetro 'ano'
228
  async def get_revenue_per_month(ano: int):
229
  with engine.connect() as conn:
230
+ results = conn.execute(text(f"SELECT * FROM revenue_per_month WHERE year = {ano}")).fetchall()
231
  if results:
232
  return [
233
  {"revenue_year": row[0], "revenue_month": row[1], "revenue_per_month": row[2]}
 
241
  @app.get("/revenue_per_year/{ano}") # Adiciona o parâmetro 'ano'
242
  async def get_revenue_per_year(ano: int):
243
  with engine.connect() as conn:
244
+ results = conn.execute(text(f"SELECT * FROM revenue_per_year WHERE year = {ano}")).fetchall()
245
  if results:
246
  return [
247
  {"revenue_year": row[0], "revenue_per_year": row[1]} for row in results