pradelf commited on
Commit
536a59c
·
1 Parent(s): 38246eb

fix: update Python version to 3.12 and remove unnecessary packages from Dockerfile

Browse files
Files changed (2) hide show
  1. src/app.py → app.py +49 -35
  2. src/streamlit_app.py +0 -40
src/app.py → app.py RENAMED
@@ -1,15 +1,11 @@
1
  import streamlit as st
2
  import pandas as pd
3
- import plotly.express as px
4
  import plotly.graph_objects as go
5
  import numpy as np
6
 
7
  ### CONFIG
8
- st.set_page_config(
9
- page_title="E-commerce",
10
- page_icon="💸",
11
- layout="wide"
12
- )
13
 
14
  ### TITLE AND TEXT
15
  st.title("Build dashboards with Streamlit 🎨")
@@ -22,30 +18,34 @@ st.markdown("""
22
  """)
23
 
24
  ### LOAD DATA
25
- DATA_PRICING = ('../Data/get_around_pricing_project.csv')
26
 
27
- DATA_ANALYSIS = ('../Data/get_around_delay_analysis.csv')
28
 
29
- # this lets the cache activated : usage d'un décorateur python pour ajouter des fonctionnalité
 
30
  # : st.cache_data et st.cache_resource qui remplace st.cache qui va devenir obsolète.
31
  # https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data
32
  # https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_resource
33
- @st.cache_data
34
  def load_data(file, nrows, delimiter=","):
35
- data = pd.read_csv(file, nrows=nrows,delimiter=delimiter)
36
- #data["Date"] = data["Date"].apply(lambda x: pd.to_datetime(",".join(x.split(",")[-2:])))
37
- #data["currency"] = data["currency"].apply(lambda x: pd.to_numeric(x[1:]))
38
  return data
39
 
40
- data_load_state = st.text('Loading data...')
41
- data_pricing = load_data(DATA_PRICING,1000)
42
- data_analysis = load_data(DATA_ANALYSIS,1000)
43
- data_load_state.text("") # change text from "Loading data..." to "" once the the load_data function has run
 
 
 
44
 
45
  ## Run the below code if the check is checked ✅
46
- if st.checkbox('Show raw data'):
47
- st.subheader('Raw data')
48
- st.write(data_pricing)
49
  ### SHOW GRAPH STREAMLIT
50
 
51
  price_per_model = data_pricing["price"]
@@ -64,7 +64,9 @@ st.markdown("""
64
  * ...
65
  This way, you have all the flexibility you need to build awesome dashboards. 🥰
66
  """)
67
- fig = px.histogram(data.sort_values("country"), x="country", y="currency", barmode="group")
 
 
68
  st.plotly_chart(fig, use_container_width=True)
69
 
70
 
@@ -93,24 +95,36 @@ col1, col2 = st.columns(2)
93
  with col1:
94
  # visu des widgets
95
  st.markdown("First column")
96
- car_id= st.selectbox("Select a country you want to see all time sales", data_analysis["car_id"].sort_values().unique())
 
 
 
97
  # intelligence et contrôle du widget
98
- rental_canceled = data_analysis[data_analysis["state"]=="canceled"]
99
- fig = px.histogram(rental_canceled, x="time_delta_with_previous_rental_in_minutes", y="delay_at_checkout_in_minutes")
 
 
 
 
100
  fig.update_layout(bargap=0.2)
101
  st.plotly_chart(fig, use_container_width=True)
102
 
103
  with col2:
104
  st.markdown("Second column")
105
  with st.form("average_sales_per_country"):
106
- model = st.selectbox("Select a model you want to see", data_pricing["model_key"].sort_values().unique())
107
- power = st.selectbox("Select a start date you want to see your metric",data_pricing["engine_power"].sort_values().unique())
108
- submit = st.form_submit_button("submit")
109
- if submit:
110
- model_select = data_pricing[data_pricing["model_key"]==model]
111
- power_select = data_pricing[data_pricing["power"]==power]
112
- avg_rental_price = data_pricing[model_select & power_select ]["rental_price_per_day"].mean()
113
- st.metric("Average rental price (in $)", np.round(avg_rental_price, 2))
114
-
115
-
116
-
 
 
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import plotly.express as px
4
  import plotly.graph_objects as go
5
  import numpy as np
6
 
7
  ### CONFIG
8
+ st.set_page_config(page_title="E-commerce", page_icon="💸", layout="wide")
 
 
 
 
9
 
10
  ### TITLE AND TEXT
11
  st.title("Build dashboards with Streamlit 🎨")
 
18
  """)
19
 
20
  ### LOAD DATA
21
+ DATA_PRICING = "Data/get_around_pricing_project.csv"
22
 
23
+ DATA_ANALYSIS = "Data/get_around_delay_analysis.csv"
24
 
25
+
26
+ # this lets the cache activated : usage d'un décorateur python pour ajouter des fonctionnalité
27
  # : st.cache_data et st.cache_resource qui remplace st.cache qui va devenir obsolète.
28
  # https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data
29
  # https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_resource
30
+ @st.cache_data
31
  def load_data(file, nrows, delimiter=","):
32
+ data = pd.read_csv(file, nrows=nrows, delimiter=delimiter)
33
+ # data["Date"] = data["Date"].apply(lambda x: pd.to_datetime(",".join(x.split(",")[-2:])))
34
+ # data["currency"] = data["currency"].apply(lambda x: pd.to_numeric(x[1:]))
35
  return data
36
 
37
+
38
+ data_load_state = st.text("Loading data...")
39
+ data_pricing = load_data(DATA_PRICING, 1000)
40
+ data_analysis = load_data(DATA_ANALYSIS, 1000)
41
+ data_load_state.text(
42
+ ""
43
+ ) # change text from "Loading data..." to "" once the the load_data function has run
44
 
45
  ## Run the below code if the check is checked ✅
46
+ if st.checkbox("Show raw data"):
47
+ st.subheader("Raw data")
48
+ st.write(data_pricing)
49
  ### SHOW GRAPH STREAMLIT
50
 
51
  price_per_model = data_pricing["price"]
 
64
  * ...
65
  This way, you have all the flexibility you need to build awesome dashboards. 🥰
66
  """)
67
+ fig = px.histogram(
68
+ data.sort_values("country"), x="country", y="currency", barmode="group"
69
+ )
70
  st.plotly_chart(fig, use_container_width=True)
71
 
72
 
 
95
  with col1:
96
  # visu des widgets
97
  st.markdown("First column")
98
+ car_id = st.selectbox(
99
+ "Select a country you want to see all time sales",
100
+ data_analysis["car_id"].sort_values().unique(),
101
+ )
102
  # intelligence et contrôle du widget
103
+ rental_canceled = data_analysis[data_analysis["state"] == "canceled"]
104
+ fig = px.histogram(
105
+ rental_canceled,
106
+ x="time_delta_with_previous_rental_in_minutes",
107
+ y="delay_at_checkout_in_minutes",
108
+ )
109
  fig.update_layout(bargap=0.2)
110
  st.plotly_chart(fig, use_container_width=True)
111
 
112
  with col2:
113
  st.markdown("Second column")
114
  with st.form("average_sales_per_country"):
115
+ model = st.selectbox(
116
+ "Select a model you want to see",
117
+ data_pricing["model_key"].sort_values().unique(),
118
+ )
119
+ power = st.selectbox(
120
+ "Select a start date you want to see your metric",
121
+ data_pricing["engine_power"].sort_values().unique(),
122
+ )
123
+ submit = st.form_submit_button("submit")
124
+ if submit:
125
+ model_select = data_pricing[data_pricing["model_key"] == model]
126
+ power_select = data_pricing[data_pricing["power"] == power]
127
+ avg_rental_price = data_pricing[model_select & power_select][
128
+ "rental_price_per_day"
129
+ ].mean()
130
+ st.metric("Average rental price (in $)", np.round(avg_rental_price, 2))
src/streamlit_app.py DELETED
@@ -1,40 +0,0 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
- import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))