update files
Browse files- app.py +185 -67
- get_around_pricing_project.csv +0 -0
app.py
CHANGED
|
@@ -9,12 +9,26 @@ import streamlit as st
|
|
| 9 |
import pandas as pd
|
| 10 |
import plotly.express as px
|
| 11 |
import plotly.graph_objects as go
|
| 12 |
-
import
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
DATA_URL = 'https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_delay_analysis.xlsx'
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
@st.cache_data
|
| 19 |
def load_data():
|
| 20 |
data = pd.read_excel(DATA_URL)
|
|
@@ -24,23 +38,58 @@ data = load_data()
|
|
| 24 |
print('state: ',data['state'].value_counts())
|
| 25 |
|
| 26 |
st.markdown("""
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
illustrent quelques statistiques et visualisations de données. A l'aide de cet un outil permet de suivre et comprendre les données des locations de voitures réalisé par
|
| 29 |
<a href="https://github.com/2nzi" style="text-decoration: none;">@2nzi</a> sur github.
|
|
|
|
| 30 |
""", unsafe_allow_html=True)
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
if st.checkbox('
|
| 35 |
st.subheader('Raw data')
|
| 36 |
-
st.write(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
-
data = data.drop(['time_delta_with_previous_rental_in_minutes','previous_ended_rental_id'],axis=1)
|
|
|
|
| 40 |
|
| 41 |
-
st.subheader("Part des différents types de location")
|
| 42 |
st.markdown("""
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
""", unsafe_allow_html=True)
|
| 45 |
|
| 46 |
fig = px.pie(data, values='car_id',names='checkin_type')
|
|
@@ -49,7 +98,7 @@ st.plotly_chart(fig)
|
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
-
st.subheader("Repartition des locations annulées dans chaque type de commande")
|
| 53 |
fig = px.histogram(data,x='checkin_type',color='state')
|
| 54 |
st.plotly_chart(fig)
|
| 55 |
|
|
@@ -62,24 +111,33 @@ upper_bound = col_med + 2 * col_std
|
|
| 62 |
print(col_med,lower_bound,upper_bound)
|
| 63 |
data = data[(data[col] >= lower_bound) & (data[col] <= upper_bound)]
|
| 64 |
print('state: ',data['state'].value_counts())
|
| 65 |
-
#utiliser Q1-1.5IQR et Q3+1.5IQR
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
| 68 |
mini = 0
|
| 69 |
df = data[data['delay_at_checkout_in_minutes']>mini]
|
| 70 |
-
title_late = 'Late cars'
|
| 71 |
|
| 72 |
else:
|
| 73 |
df = data
|
| 74 |
-
title_late = 'All cars'
|
| 75 |
mini = int(df['delay_at_checkout_in_minutes'].min())
|
| 76 |
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
st.subheader(title_late)
|
| 79 |
-
trsh = int(df['delay_at_checkout_in_minutes'].max()) #make the max chossable !
|
| 80 |
-
seuil = st.slider("Choose the minute threshold!", mini, int(df['delay_at_checkout_in_minutes'].max()), int(trsh*0.1))
|
| 81 |
# seuil = st.slider("Choose the minute threshold!", 0, trsh, int(trsh*0.1))
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
fig_px = px.histogram(df, color='checkin_type', x='delay_at_checkout_in_minutes')
|
| 84 |
fig = go.Figure(fig_px)
|
| 85 |
|
|
@@ -106,76 +164,136 @@ fig.update_layout(
|
|
| 106 |
yaxis_title="Count"
|
| 107 |
)
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
#
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
# day_data = data[data['dateRep']== start_time]
|
| 131 |
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
# country = st.selectbox("Select a country you want to see sales", data["countriesAndTerritories"].sort_values().unique())
|
| 137 |
|
|
|
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
-
#
|
|
|
|
| 142 |
|
| 143 |
-
# country_data = data[data["countriesAndTerritories"]==country]
|
| 144 |
|
| 145 |
-
|
| 146 |
-
# current_day = randrange(len(country_data))
|
| 147 |
-
# # current_day = int(len(country_data)/2) #take random value
|
| 148 |
|
| 149 |
-
# # st.write(country_data.iloc[current_day]['dateRep'])
|
| 150 |
-
# # st.write(country_data.iloc[current_day]['cases'])
|
| 151 |
-
# # st.write(country_data.iloc[current_day-1]['cases'])
|
| 152 |
|
|
|
|
| 153 |
|
| 154 |
-
|
| 155 |
-
#
|
| 156 |
-
|
| 157 |
-
# st.metric(label="",value = ratio, delta = diff_ratio)
|
| 158 |
-
# # st.write(f'{ratio:.2f}')
|
| 159 |
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
|
| 170 |
-
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
# fig2.add_trace(go.Scatter(x=data_date["dateRep"], y=data_date["Roldeaths"], mode='lines',name='Rolling 7-day Mean',line=dict(color='red')))
|
| 177 |
|
| 178 |
-
|
| 179 |
|
| 180 |
-
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
import pandas as pd
|
| 10 |
import plotly.express as px
|
| 11 |
import plotly.graph_objects as go
|
| 12 |
+
import requests
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
DATA_URL = 'https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_delay_analysis.xlsx'
|
| 17 |
|
| 18 |
+
st.set_page_config(layout="wide")
|
| 19 |
+
st.markdown(
|
| 20 |
+
"""
|
| 21 |
+
<style>
|
| 22 |
+
.main {
|
| 23 |
+
margin: 0 auto; /* Centers the content */
|
| 24 |
+
max-width: 1000px;
|
| 25 |
+
|
| 26 |
+
}
|
| 27 |
+
</style>
|
| 28 |
+
""",
|
| 29 |
+
unsafe_allow_html=True
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
@st.cache_data
|
| 33 |
def load_data():
|
| 34 |
data = pd.read_excel(DATA_URL)
|
|
|
|
| 38 |
print('state: ',data['state'].value_counts())
|
| 39 |
|
| 40 |
st.markdown("""
|
| 41 |
+
<div style="text-align: center;">
|
| 42 |
+
<img src="https://lever-client-logos.s3.amazonaws.com/2bd4cdf9-37f2-497f-9096-c2793296a75f-1568844229943.png" alt="GetAround logo" style="width: 80%;">
|
| 43 |
+
</div>
|
| 44 |
+
|
| 45 |
+
<br>
|
| 46 |
+
|
| 47 |
+
Bienvenue sur ce dashboard streamlit du `Projet Get Around`. Nos <a href="https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_delay_analysis.xlsx" style="text-decoration: none;">données</a>
|
| 48 |
illustrent quelques statistiques et visualisations de données. A l'aide de cet un outil permet de suivre et comprendre les données des locations de voitures réalisé par
|
| 49 |
<a href="https://github.com/2nzi" style="text-decoration: none;">@2nzi</a> sur github.
|
| 50 |
+
<br><br><br>
|
| 51 |
""", unsafe_allow_html=True)
|
| 52 |
|
| 53 |
|
| 54 |
+
st.markdown("""---""")
|
| 55 |
+
st.markdown("""<br>""", unsafe_allow_html=True)
|
| 56 |
+
st.subheader("1] Part des différents types de location")
|
| 57 |
|
| 58 |
+
if st.checkbox('Montrer les données brutes'):
|
| 59 |
st.subheader('Raw data')
|
| 60 |
+
st.write(data)
|
| 61 |
+
st.markdown("""
|
| 62 |
+
<div style="background-color: #F5EAF4; padding: 10px;">
|
| 63 |
+
|
| 64 |
+
| Nom du champ | Commentaire |
|
| 65 |
+
|-----------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
|
| 66 |
+
| **rental_id** | Identifiant unique de la location |
|
| 67 |
+
| **car_id** | Identifiant unique de la voiture |
|
| 68 |
+
| **checkin_type** | Flux utilisé pour l'enregistrement et le retour. (c'est-à-dire accès et retour de la voiture) |
|
| 69 |
+
| | - **mobile** : contrat de location signé sur le smartphone du propriétaire |
|
| 70 |
+
| | - **connect** : voiture équipée de la technologie Connect, ouverte par le conducteur avec son smartphone |
|
| 71 |
+
| | *Note : les contrats papier ont été exclus des données car nous n'avons pas de données sur leur retard lors du retour et c'est un cas d'utilisation négligeable* |
|
| 72 |
+
| **state** | annulé signifie que la location n'a pas eu lieu (a été annulée par le conducteur ou le propriétaire). |
|
| 73 |
+
| **delay_at_checkout_in_minutes** | Différence en minutes entre l'heure de fin de location demandée par le conducteur lors de la réservation de la voiture et l'heure réelle à laquelle le conducteur a terminé le retour. Les valeurs négatives signifient que le conducteur a rendu la voiture en avance. |
|
| 74 |
+
| **previous_ended_rental_id** | Identifiant de la location précédente terminée de la voiture (NULL lorsqu'il n'y a pas de location précédente ou que le délai avec la location précédente est supérieur à 12 heures). |
|
| 75 |
+
| **time_delta_with_previous_rental_in_minutes**| Différence en minutes entre l'heure de début prévue de cette location et l'heure de fin prévue de la location précédente (lorsque inférieure à 12 heures, NULL si supérieure). |
|
| 76 |
+
|
| 77 |
+
</div>
|
| 78 |
+
""", unsafe_allow_html=True)
|
| 79 |
+
|
| 80 |
|
| 81 |
|
| 82 |
+
# data = data.drop(['time_delta_with_previous_rental_in_minutes','previous_ended_rental_id'],axis=1)
|
| 83 |
+
|
| 84 |
|
|
|
|
| 85 |
st.markdown("""
|
| 86 |
+
<br>
|
| 87 |
+
|
| 88 |
+
Deux types de locations existent : Connect & Mobile.
|
| 89 |
+
|
| 90 |
+
**Mobile** : le conducteur et le propriétaire se rencontrent et signent tous deux le contrat de location sur le smartphone du propriétaire.
|
| 91 |
+
|
| 92 |
+
**Connect** : le conducteur ne rencontre pas le propriétaire et ouvre la voiture avec son smartphone.
|
| 93 |
""", unsafe_allow_html=True)
|
| 94 |
|
| 95 |
fig = px.pie(data, values='car_id',names='checkin_type')
|
|
|
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
+
st.subheader("2] Repartition des locations annulées dans chaque type de commande")
|
| 102 |
fig = px.histogram(data,x='checkin_type',color='state')
|
| 103 |
st.plotly_chart(fig)
|
| 104 |
|
|
|
|
| 111 |
print(col_med,lower_bound,upper_bound)
|
| 112 |
data = data[(data[col] >= lower_bound) & (data[col] <= upper_bound)]
|
| 113 |
print('state: ',data['state'].value_counts())
|
|
|
|
| 114 |
|
| 115 |
+
|
| 116 |
+
st.subheader("3] Retard des locations")
|
| 117 |
+
|
| 118 |
+
if st.checkbox('Montrer uniquement les voitures en retard',value=True):
|
| 119 |
mini = 0
|
| 120 |
df = data[data['delay_at_checkout_in_minutes']>mini]
|
|
|
|
| 121 |
|
| 122 |
else:
|
| 123 |
df = data
|
|
|
|
| 124 |
mini = int(df['delay_at_checkout_in_minutes'].min())
|
| 125 |
|
| 126 |
+
trsh = int(df['delay_at_checkout_in_minutes'].max())
|
| 127 |
+
seuil = st.slider("Choisir le temps de retard en minute", mini, int(df['delay_at_checkout_in_minutes'].max()), int(trsh*0.2))
|
| 128 |
+
maxi = int(df['delay_at_checkout_in_minutes'].max())
|
| 129 |
|
|
|
|
|
|
|
|
|
|
| 130 |
# seuil = st.slider("Choose the minute threshold!", 0, trsh, int(trsh*0.1))
|
| 131 |
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
move_upper_mask = df['delay_at_checkout_in_minutes']<seuil
|
| 136 |
+
lower_mask = df['delay_at_checkout_in_minutes']>mini
|
| 137 |
+
global_mask = move_upper_mask & lower_mask
|
| 138 |
+
number_of_rent = len(df[global_mask])
|
| 139 |
+
part_of_rent = 100 * len(df[move_upper_mask]) / len(df)
|
| 140 |
+
|
| 141 |
fig_px = px.histogram(df, color='checkin_type', x='delay_at_checkout_in_minutes')
|
| 142 |
fig = go.Figure(fig_px)
|
| 143 |
|
|
|
|
| 164 |
yaxis_title="Count"
|
| 165 |
)
|
| 166 |
|
| 167 |
+
fig.add_annotation(
|
| 168 |
+
x=(x+mini)/2,
|
| 169 |
+
y=0.8,
|
| 170 |
+
xref='x',
|
| 171 |
+
yref='paper',
|
| 172 |
+
text=f"{number_of_rent}",
|
| 173 |
+
showarrow=False,
|
| 174 |
+
font=dict(size=12, color="Green"),
|
| 175 |
+
)
|
| 176 |
+
fig.add_annotation(
|
| 177 |
+
x=(x+mini)/2,
|
| 178 |
+
y=0.9,
|
| 179 |
+
xref='x',
|
| 180 |
+
yref='paper',
|
| 181 |
+
text=f"{part_of_rent:.2f}%",
|
| 182 |
+
# text=f"Number of rent: {number_of_rent}",
|
| 183 |
+
showarrow=False,
|
| 184 |
+
font=dict(size=16, color="Green"),
|
| 185 |
+
)
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
|
| 188 |
+
fig.add_shape(
|
| 189 |
+
type="rect",
|
| 190 |
+
x0=x, x1=maxi, y0=0, y1=1,
|
| 191 |
+
fillcolor="Red",
|
| 192 |
+
opacity=0.2,
|
| 193 |
+
line_width=0,
|
| 194 |
+
xref='x', yref='paper'
|
| 195 |
+
)
|
| 196 |
|
| 197 |
+
fig.add_annotation(
|
| 198 |
+
x=(maxi+x)/2,
|
| 199 |
+
y=0.8,
|
| 200 |
+
xref='x',
|
| 201 |
+
yref='paper',
|
| 202 |
+
text=f"{len(df)-number_of_rent}",
|
| 203 |
+
showarrow=False,
|
| 204 |
+
font=dict(size=12, color="Red"),
|
| 205 |
+
)
|
| 206 |
+
fig.add_annotation(
|
| 207 |
+
x=(maxi+x)/2,
|
| 208 |
+
y=0.9,
|
| 209 |
+
xref='x',
|
| 210 |
+
yref='paper',
|
| 211 |
+
text=f"{100-part_of_rent:.2f}%",
|
| 212 |
+
# text=f"Number of rent: {number_of_rent}",
|
| 213 |
+
showarrow=False,
|
| 214 |
+
font=dict(size=16, color="Red"),
|
| 215 |
+
)
|
| 216 |
|
|
|
|
| 217 |
|
| 218 |
+
st.plotly_chart(fig)
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
+
#IDEE:
|
| 223 |
+
# pouvoir choisir l'id d'une voiture spécifiquement
|
| 224 |
|
|
|
|
| 225 |
|
| 226 |
+
st.subheader("4] Impact du retard sur les conducteurs suivant")
|
|
|
|
|
|
|
| 227 |
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
+
df_late_impact = df[df['previous_ended_rental_id'].notna()]
|
| 230 |
|
| 231 |
+
if st.checkbox('données brutes'):
|
| 232 |
+
# st.subheader('Raw data')
|
| 233 |
+
st.write(df_late_impact)
|
|
|
|
|
|
|
| 234 |
|
| 235 |
|
| 236 |
+
fig_px = px.histogram(df_late_impact, color='checkin_type', x='time_delta_with_previous_rental_in_minutes',nbins=35)
|
| 237 |
+
fig = go.Figure(fig_px)
|
| 238 |
|
| 239 |
+
fig.update_layout(
|
| 240 |
+
title="",
|
| 241 |
+
xaxis_title="Delay with the previous rental in Minutes",
|
| 242 |
+
yaxis_title="Count"
|
| 243 |
+
)
|
| 244 |
|
| 245 |
+
st.plotly_chart(fig)
|
| 246 |
|
| 247 |
+
car_brands = ["Citroën", "Peugeot", "PGO", "Renault", "Audi", "BMW", "other", "Mercedes", "Opel", "Volkswagen", "Ferrari", "Maserati", "Mitsubishi", "Nissan", "SEAT", "Subaru", "Toyota"]
|
| 248 |
+
fuel_types = ["diesel", "petrol", "hybrid_petrol", "electro"]
|
| 249 |
+
paint_colors = ["black", "grey", "white", "red", "silver", "blue", "orange", "beige", "brown", "green"]
|
| 250 |
+
car_types = ["convertible", "coupe", "estate", "hatchback", "sedan", "subcompact", "suv", "van"]
|
|
|
|
| 251 |
|
| 252 |
+
st.subheader("5] API de Prédiction de la Valeur des Voitures GetAround")
|
| 253 |
|
| 254 |
+
col1, col2 = st.columns(2)
|
| 255 |
|
| 256 |
+
with col1:
|
| 257 |
+
marque = st.selectbox("Marque", car_brands, index=3) # Par défaut "Renault"
|
| 258 |
+
kilometrage = st.number_input("Kilométrage", min_value=0, step=1000, value=10000)
|
| 259 |
+
puissance_moteur = st.number_input("Puissance du Moteur (HP)", min_value=0, step=10, value=100)
|
| 260 |
+
carburant = st.selectbox("Type de Carburant", fuel_types, index=0) # Par défaut "diesel"
|
| 261 |
+
couleur_peinture = st.selectbox("Couleur de la Peinture", paint_colors, index=0) # Par défaut "black"
|
| 262 |
+
type_voiture = st.selectbox("Type de Voiture", car_types, index=4) # Par défaut "sedan"
|
| 263 |
+
|
| 264 |
+
with col2:
|
| 265 |
+
parking_prive_disponible = st.checkbox("Parking Privé", value=True)
|
| 266 |
+
gps_disponible = st.checkbox("GPS Disponible", value=True)
|
| 267 |
+
climatisation_disponible = st.checkbox("Climatisation", value=True)
|
| 268 |
+
voiture_automatique = st.checkbox("Voiture Automatique", value=False)
|
| 269 |
+
getaround_connect_disponible = st.checkbox("GetAround Connect", value=True)
|
| 270 |
+
regulateur_vitesse_disponible = st.checkbox("Régulateur de Vitesse", value=True)
|
| 271 |
+
pneus_hiver = st.checkbox("Pneus Hiver", value=False)
|
| 272 |
+
|
| 273 |
+
url = "https://2nzi-getaroundapi.hf.space/predict"
|
| 274 |
+
|
| 275 |
+
if st.button("Prédire la Valeur de la Voiture"):
|
| 276 |
+
input_data = {
|
| 277 |
+
"brand": marque,
|
| 278 |
+
"mileage": kilometrage,
|
| 279 |
+
"engine_power": puissance_moteur,
|
| 280 |
+
"fuel": carburant,
|
| 281 |
+
"paint_color": couleur_peinture,
|
| 282 |
+
"car_type": type_voiture,
|
| 283 |
+
"private_parking_available": parking_prive_disponible,
|
| 284 |
+
"has_gps": gps_disponible,
|
| 285 |
+
"has_air_conditioning": climatisation_disponible,
|
| 286 |
+
"automatic_car": voiture_automatique,
|
| 287 |
+
"has_getaround_connect": getaround_connect_disponible,
|
| 288 |
+
"has_speed_regulator": regulateur_vitesse_disponible,
|
| 289 |
+
"winter_tires": pneus_hiver
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
response = requests.post(url, params=input_data)
|
| 293 |
+
|
| 294 |
+
# Afficher la réponse du serveur
|
| 295 |
+
if response.status_code == 200:
|
| 296 |
+
result = response.json()
|
| 297 |
+
st.write("Résultat de la Prédiction:", result)
|
| 298 |
+
else:
|
| 299 |
+
st.write("Erreur:", response.status_code, response.text)
|
get_around_pricing_project.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|