2nzi commited on
Commit
c698239
1 Parent(s): e5170f2

upload files

Browse files
Files changed (2) hide show
  1. app.py +181 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #docker run -it -v "$(pwd):/home/app" -p 4000:4000 jedha/streamlit-fs-image
2
+ #docker run -it -v "$(pwd):/home/app" -p 4000:4000 jedha/streamlit-fs-image bash
3
+ #docker build . -t NAME_DOCKER
4
+ # docker run -it -p 4000:80 -v "$(pwd):/home/app" -e PORT:80 NAME_DOCKER bash
5
+
6
+ #http://localhost:4000
7
+
8
+ import streamlit as st
9
+ import pandas as pd
10
+ import plotly.express as px
11
+ import plotly.graph_objects as go
12
+ import numpy as np
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)
21
+ return data
22
+
23
+ data = load_data()
24
+ print('state: ',data['state'].value_counts())
25
+
26
+ st.markdown("""
27
+ Bienvenue sur ce tableau de bord streamlit du `Projet Get Around`. Nos <a href=DATA_URL style="text-decoration: none;">données</a>
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('Show raw data'):
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
+ Deux types de locations existe. Connect & Mobile.
44
+ """, unsafe_allow_html=True)
45
+
46
+ fig = px.pie(data, values='car_id',names='checkin_type')
47
+ # fig = go.Figure(data=[go.Pie(labels=data['checkin_type'], values=data['car_id'])])
48
+ 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
+
56
+
57
+ col = 'delay_at_checkout_in_minutes'
58
+ col_med = data[col].median()
59
+ col_std = data[col].std()
60
+ lower_bound = col_med - 2 * col_std
61
+ 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
+ if st.checkbox('Show on Late',value=True):
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
+
86
+ x=seuil
87
+ fig.add_shape(
88
+ type="line",
89
+ x0=x, x1=x, y0=0, y1=1,
90
+ line=dict(color="Green", width=2, dash="dash"),
91
+ xref='x', yref='paper'
92
+ )
93
+
94
+ fig.add_shape(
95
+ type="rect",
96
+ x0=mini, x1=x, y0=0, y1=1,
97
+ fillcolor="Green",
98
+ opacity=0.2,
99
+ line_width=0,
100
+ xref='x', yref='paper'
101
+ )
102
+
103
+ fig.update_layout(
104
+ title="",
105
+ xaxis_title="Delay at Checkout in Minutes",
106
+ yaxis_title="Count"
107
+ )
108
+
109
+ st.plotly_chart(fig)
110
+ col1, col2 = st.columns(2)
111
+
112
+ move_upper_mask = df['delay_at_checkout_in_minutes']<seuil
113
+ lower_mask = df['delay_at_checkout_in_minutes']>mini
114
+ global_mask = move_upper_mask & lower_mask
115
+ col1.metric("Number of rent", len(df[global_mask]))
116
+
117
+ part_of_rent = 100*len(df[move_upper_mask]) / len(df)
118
+ col2.metric("Part of rent", f'{part_of_rent:.2f}%')
119
+
120
+ # col2.metric("Part of rent", f'{100*len(df[df['delay_at_checkout_in_minutes']<seuil])/len(df['delay_at_checkout_in_minutes']):.2f}%')
121
+
122
+
123
+ #IDEE:
124
+ # pouvoir choisir l'id d'une voiture spécifiquement
125
+
126
+
127
+
128
+
129
+
130
+ # day_data = data[data['dateRep']== start_time]
131
+
132
+
133
+
134
+ # st.subheader("Analyse par pays")
135
+
136
+ # country = st.selectbox("Select a country you want to see sales", data["countriesAndTerritories"].sort_values().unique())
137
+
138
+
139
+
140
+
141
+ # st.write("Current growth rate")
142
+
143
+ # country_data = data[data["countriesAndTerritories"]==country]
144
+
145
+ # from random import randrange
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
+ # ratio = np.round((country_data.iloc[current_day]['cases'] - country_data.iloc[current_day-1]['cases'])/country_data.iloc[current_day]['cases'],2)
155
+ # ratio2 = np.round((country_data.iloc[current_day]['cases'] - country_data.iloc[current_day-2]['cases'])/country_data.iloc[current_day-1]['cases'],2)
156
+ # diff_ratio = np.round(ratio-ratio2,2)
157
+ # st.metric(label="",value = ratio, delta = diff_ratio)
158
+ # # st.write(f'{ratio:.2f}')
159
+
160
+
161
+ # #### Create two columns
162
+ # col1, col2 = st.columns(2)
163
+
164
+ # with col1:
165
+ # st.subheader('Cas positifs cases')
166
+ # fig = go.Figure()
167
+ # fig.add_trace(go.Scatter(x=data_date["dateRep"], y=data_date["cases"], mode='lines',name='new cases', line=dict(color='blue')))
168
+ # fig.add_trace(go.Scatter(x=data_date["dateRep"], y=data_date["Rolcases"], mode='lines',name='Rolling 7-day Mean',line=dict(color='red')))
169
+
170
+ # st.plotly_chart(fig)
171
+
172
+ # with col2:
173
+ # st.subheader('Cas de décès')
174
+ # fig2 = go.Figure()
175
+ # fig2.add_trace(go.Scatter(x=data_date["dateRep"], y=data_date["deaths"], mode='lines',name='new cases', line=dict(color='blue')))
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
+ # st.plotly_chart(fig2)
179
+
180
+
181
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ plotly
4
+ numpy
5
+ openpyxl