File size: 4,401 Bytes
7bd7bef
 
 
 
 
 
 
 
 
 
 
5b2d4e7
7bd7bef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b2d4e7
 
7bd7bef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b2d4e7
 
 
7bd7bef
 
 
 
 
 
 
5b2d4e7
 
7bd7bef
 
 
 
5b2d4e7
 
 
7bd7bef
 
 
5b2d4e7
 
7bd7bef
 
 
 
5b2d4e7
 
 
7bd7bef
 
 
5b2d4e7
 
7bd7bef
 
 
 
5b2d4e7
 
 
7bd7bef
 
 
5b2d4e7
 
7bd7bef
 
 
 
5b2d4e7
 
 
7bd7bef
 
 
 
5b2d4e7
 
 
 
 
 
 
 
 
7bd7bef
 
5b2d4e7
7bd7bef
 
5b2d4e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import streamlit as st
import psycopg2
import os
import plotly.graph_objects as go
import pandas as pd
from dotenv import load_dotenv
from server.db.db import (
    get_recipes_count,
    get_average_latency,
    get_daily_requests,
    get_total_cost,
    get_total_impact,
)

# Récupérer les données pour afficher sur le dashboard
total_recipes = get_recipes_count()
average_latency = get_average_latency()
total_cost = get_total_cost()
total_impact = get_total_impact()

# Récupérer les données des requêtes par jour
df_requests = get_daily_requests()

# Affichage de la page dashboard avec Streamlit
st.markdown(
    """

    <div class="title-container">

        DASHBOARD

    </div>

    """,
    unsafe_allow_html=True,
)

# Ajouter le CSS pour les cards avec animations et un design moderne
st.markdown(
    """ 

    <style>

        .title-container {

            background-color: #6A5ACD;

            border-radius: 10px;

            color: white;

            text-align: center;

            padding: 5px;

            margin-bottom: 20px;

            box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);

            font-family: New Icon;

            font-size: 30px;

        }



        /* Style pour les cards */

        .card {

            border-radius: 15px;

            padding: 20px;

            background: linear-gradient(to top, #cae7d4, #a7d7b8);

            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);

            margin-bottom: 20px;

            text-align: center;

            transition: transform 0.3s, box-shadow 0.3s;

            animation: fadeInUp 0.5s ease-out;

            height: 200px;

        }



        .card:hover {

            transform: translateY(-10px);

            box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);

        }



        @keyframes fadeInUp {

            0% {

                transform: translateY(20px);

                opacity: 0;

            }

            100% {

                transform: translateY(0);

                opacity: 1;

            }

        }



        .card-title {

            font-size: 1.3em;

            color: #2d3e50;

            margin-bottom: 15px;

            font-weight: bold;

            font-family: New Icon;

        }



        .card-value {

            font-size: 30px;

            color: #0099cc;

            font-weight: bold;

        }



        /* Add smooth transition for the hover effect */

        .card .card-title, .card .card-value {

            transition: color 0.3s ease;

        }



        .card:hover {

            color: #FF9A76;

        }

        .card:hover .card-value {

            color: #0086b3;

        }

    </style>

""",
    unsafe_allow_html=True,
)


# Créer des colonnes pour disposer les cards
col1, col2, col3, col4 = st.columns(4)

# Card 1
with col1:
    st.markdown(
        f"""

        <div class="card">

            <div class="card-title">🍲 Nombre de recettes suggerées</div>

            <div class="card-value">{total_recipes}</div>

        </div>

    """,
        unsafe_allow_html=True,
    )

# Card 2
with col2:
    st.markdown(
        f"""

        <div class="card">

            <div class="card-title">⏱️ Latence moyenne</div>

            <div class="card-value">{average_latency}s</div>

        </div>

    """,
        unsafe_allow_html=True,
    )

# Card 3
with col3:
    st.markdown(
        f"""

        <div class="card">

            <div class="card-title">💸 Coût total des requêtes</div>

            <div class="card-value">${total_cost}</div>

        </div>

    """,
        unsafe_allow_html=True,
    )

# Card 4
with col4:
    st.markdown(
        f"""

        <div class="card">

            <div class="card-title">🌱 Impact écologique estimé</div>

            <div class="card-value">{total_impact} kg CO2</div>

        </div>

    """,
        unsafe_allow_html=True,
    )

# Graphique des requêtes par jour
st.markdown("### 📅 Nombre de requêtes par jour")

fig = go.Figure(
    data=[
        go.Scatter(
            x=df_requests["date"],
            y=df_requests["nombre_requetes"],
            mode="lines+markers",
        )
    ]
)

fig.update_layout(
    xaxis_title="Date", yaxis_title="Nombre de requêtes", template="plotly_dark"
)

st.plotly_chart(fig)