@@ -17,6 +17,106 @@ class CleanConversations(BaseModel):
1717 monthsToKeep : int
1818
1919
20+ class ExportSalesData (BaseModel ):
21+ period : str
22+
23+
24+ @router .post ("/export-sales-data" )
25+ def export_sales_data (
26+ export_sales_data : ExportSalesData ,
27+ session : Session = Depends (get_session ),
28+ ):
29+ # todo: implement api call to get real data
30+
31+ articles_bought_prices_data = [
32+ [12.50 , 8.90 , 15.00 , 22.30 , 5.50 ],
33+ [18.75 , 11.20 , 25.80 , 9.90 , 14.60 , 33.40 ],
34+ [7.30 , 19.95 , 16.75 , 12.10 , 28.50 ],
35+ [21.40 , 13.85 , 9.60 , 17.20 , 11.95 , 24.90 , 8.75 ],
36+ [15.60 , 20.30 , 12.40 , 18.90 , 26.75 , 14.50 ],
37+ [19.80 , 8.40 , 23.70 , 16.30 , 10.95 , 29.60 ],
38+ [13.20 , 17.95 , 11.80 , 22.40 , 15.90 , 25.30 , 120.33 ],
39+ ]
40+
41+ articles_sold_prices_data = [
42+ [18.90 , 14.50 , 23.00 , 31.50 , 12.90 ],
43+ [27.40 , 19.80 , 38.50 , 16.75 , 22.90 , 45.60 ],
44+ [13.70 , 29.50 , 24.90 , 19.40 , 42.80 ],
45+ [32.10 , 21.75 , 16.20 , 26.90 , 19.95 , 37.50 , 15.40 ],
46+ [24.80 , 31.90 , 19.60 , 28.50 , 39.75 , 23.30 ],
47+ [29.70 , 15.90 , 36.40 , 25.80 , 18.95 , 44.20 ],
48+ [21.60 , 27.50 , 19.30 , 34.80 , 24.90 , 38.90 , 17.80 ],
49+ ]
50+ total_articles_bought = sum (
51+ len (articles_bought ) for articles_bought in articles_bought_prices_data
52+ )
53+ total_articles_sold = sum (
54+ len (articles_sold ) for articles_sold in articles_sold_prices_data
55+ )
56+
57+ turnover_data = [sum (articles_sold ) for articles_sold in articles_sold_prices_data ]
58+ gross_profit_data = [
59+ sum (articles_sold ) - sum (articles_bought )
60+ for articles_bought , articles_sold in zip (
61+ articles_bought_prices_data , articles_sold_prices_data
62+ )
63+ ]
64+ labels = [
65+ "Jan 24" ,
66+ "Fév 24" ,
67+ "Mar 24" ,
68+ "Avr 24" ,
69+ "Mai 24" ,
70+ "Jun 24" ,
71+ "Jul 24" ,
72+ ]
73+
74+ data = {
75+ "labels" : labels ,
76+ "turnover_data" : turnover_data ,
77+ "gross_profit_data" : gross_profit_data ,
78+ "total_turnover" : sum (turnover_data ),
79+ "maximum_turnover" : max (turnover_data ),
80+ "minimum_turnover" : min (turnover_data ),
81+ "average_turnover" : sum (turnover_data ) / len (turnover_data ),
82+ "total_gross_profit" : sum (gross_profit_data ),
83+ "maximum_gross_profit" : max (gross_profit_data ),
84+ "minimum_gross_profit" : min (gross_profit_data ),
85+ "average_gross_profit" : sum (gross_profit_data ) / len (gross_profit_data ),
86+ "articles_bought_prices_data" : articles_bought_prices_data ,
87+ "total_articles_bought" : total_articles_bought ,
88+ "average_article_bought_price" : sum (
89+ sum (articles_bought ) for articles_bought in articles_bought_prices_data
90+ )
91+ / total_articles_bought ,
92+ "average_nb_articles_bought" : total_articles_bought
93+ / len (articles_bought_prices_data ),
94+ "most_expensive_article_bought" : max (
95+ max (articles_bought ) for articles_bought in articles_bought_prices_data
96+ ),
97+ "least_expensive_article_bought" : min (
98+ min (articles_bought ) for articles_bought in articles_bought_prices_data
99+ ),
100+ "articles_sold_prices_data" : articles_sold_prices_data ,
101+ "total_articles_sold" : sum (
102+ sum (articles_sold ) for articles_sold in articles_sold_prices_data
103+ ),
104+ "average_article_sold_price" : sum (
105+ sum (articles_sold ) for articles_sold in articles_sold_prices_data
106+ )
107+ / total_articles_sold ,
108+ "average_nb_article_sold" : total_articles_sold / len (articles_sold_prices_data ),
109+ "most_expensive_article_sold" : max (
110+ max (articles_sold ) for articles_sold in articles_sold_prices_data
111+ ),
112+ "least_expensive_article_sold" : min (
113+ min (articles_sold ) for articles_sold in articles_sold_prices_data
114+ ),
115+ }
116+
117+ return data
118+
119+
20120@router .post ("/clean-conversations" )
21121async def clean_conversations (
22122 clean_conversations : CleanConversations ,
0 commit comments