madamanastasia commited on
Commit
c84ee01
·
1 Parent(s): afa60ce

Deploy Streamlit dashboard

Browse files
Files changed (6) hide show
  1. Dockerfile +11 -13
  2. README.md +4 -13
  3. app.py +171 -0
  4. get_around_pricing_project.csv +0 -0
  5. requirements.txt +3 -2
  6. src/streamlit_app.py +0 -40
Dockerfile CHANGED
@@ -1,20 +1,18 @@
1
- FROM python:3.13.5-slim
2
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
 
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
 
14
- RUN pip3 install -r requirements.txt
15
 
16
- EXPOSE 8501
 
17
 
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
-
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ FROM python:3.10-slim
2
 
3
  WORKDIR /app
4
 
5
+ # Быстрее и чище установка
6
+ ENV PIP_NO_CACHE_DIR=1 \
7
+ PYTHONDONTWRITEBYTECODE=1 \
8
+ PYTHONUNBUFFERED=1
 
9
 
10
+ COPY requirements.txt .
11
+ RUN pip install -r requirements.txt
12
 
13
+ COPY . .
14
 
15
+ # Hugging Face обычно проксирует 7860
16
+ EXPOSE 7860
17
 
18
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
 
 
README.md CHANGED
@@ -1,19 +1,10 @@
1
  ---
2
  title: Getaround Delay Dashboard
3
- emoji: 🚀
4
- colorFrom: red
5
- colorTo: red
6
  sdk: docker
7
- app_port: 8501
8
- tags:
9
- - streamlit
10
  pinned: false
11
- short_description: Streamlit template space
12
  ---
13
 
14
- # Welcome to Streamlit!
15
-
16
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
17
-
18
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
19
- forums](https://discuss.streamlit.io).
 
1
  ---
2
  title: Getaround Delay Dashboard
3
+ emoji: 😻
4
+ colorFrom: blue
5
+ colorTo: gray
6
  sdk: docker
 
 
 
7
  pinned: false
 
8
  ---
9
 
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from pathlib import Path
5
+ import altair as alt
6
+
7
+ st.set_page_config(page_title="Getaround — Late Return Buffer Analysis", layout="wide")
8
+
9
+ APP_DIR = Path(__file__).resolve().parent
10
+ DATA_PATH = APP_DIR / "get_around_delay_analysis.csv"
11
+
12
+ @st.cache_data
13
+ def load_data():
14
+ df = pd.read_csv(DATA_PATH)
15
+ return df
16
+
17
+ df = load_data()
18
+
19
+ st.title("Getaround — Late Return Buffer (2017 analysis)")
20
+
21
+ st.markdown(
22
+ """
23
+ This dashboard explores the trade-off of introducing a **minimum buffer time** between two consecutive rentals.
24
+ A buffer reduces friction caused by late checkouts, but may reduce marketplace utilization.
25
+ """
26
+ )
27
+
28
+
29
+ with st.sidebar:
30
+ st.header("Policy settings")
31
+ scope = st.selectbox("Scope", ["All cars", "Connect only"], index=0)
32
+ threshold = st.slider("Minimum buffer (minutes)", min_value=0, max_value=360, value=120, step=5)
33
+
34
+ st.header("Visualization")
35
+ clip_mode = st.selectbox("Delay clipping", ["None", "Percentiles (1–99)", "Fixed range (±24h)"], index=1)
36
+ bins = st.slider("Histogram bins", 20, 200, 60, step=10)
37
+
38
+ st.header("Filters")
39
+ include_canceled = st.checkbox("Include canceled rentals", value=False)
40
+
41
+ work = df.copy()
42
+
43
+ if not include_canceled:
44
+ work = work[work["state"] == "ended"].copy()
45
+
46
+ if scope == "Connect only":
47
+ work = work[work["checkin_type"] == "connect"].copy()
48
+
49
+
50
+ # Build previous delay mapping to estimate impact on next driver
51
+ ended = df[df["state"] == "ended"][["rental_id", "delay_at_checkout_in_minutes"]].copy()
52
+ ended["delay_at_checkout_in_minutes"] = ended["delay_at_checkout_in_minutes"].fillna(0)
53
+
54
+ prev_delay_map = dict(zip(ended["rental_id"].astype(float), ended["delay_at_checkout_in_minutes"]))
55
+ # previous_ended_rental_id is float due to NaNs in source
56
+ work["previous_delay_min"] = work["previous_ended_rental_id"].map(prev_delay_map).fillna(0)
57
+
58
+ work["gap_min"] = work["time_delta_with_previous_rental_in_minutes"].fillna(np.inf)
59
+ work["impact_on_next_driver_min"] = np.maximum(0, work["previous_delay_min"] - work["gap_min"])
60
+
61
+ # Policy effect: rentals that would be hidden because gap < threshold
62
+ work["affected_by_policy"] = work["gap_min"] < threshold
63
+
64
+ # Problematic cases: when next driver would be impacted (wait time > 0)
65
+ work["problematic"] = work["impact_on_next_driver_min"] > 0
66
+
67
+ # Solved cases under policy: problematic cases among affected rentals
68
+ work["solved_by_policy"] = work["problematic"] & work["affected_by_policy"]
69
+
70
+ total_rentals = len(work)
71
+ affected = int(work["affected_by_policy"].sum())
72
+ problematic = int(work["problematic"].sum())
73
+ solved = int(work["solved_by_policy"].sum())
74
+
75
+ pct = lambda a, b: (100*a/b) if b else 0
76
+
77
+ col1, col2, col3, col4 = st.columns(4)
78
+ col1.metric("Ended rentals (in scope)", f"{total_rentals:,}")
79
+ col2.metric("Rentals affected by policy", f"{affected:,}", f"{pct(affected,total_rentals):.1f}%")
80
+ col3.metric("Problematic cases (wait > 0)", f"{problematic:,}", f"{pct(problematic,total_rentals):.1f}%")
81
+ col4.metric("Problematic cases solved", f"{solved:,}", f"{pct(solved,problematic):.1f}% of problematic" if problematic else "0%")
82
+
83
+ st.subheader("Distribution of checkout delays (minutes)")
84
+
85
+ delays = df["delay_at_checkout_in_minutes"].dropna().astype(float)
86
+
87
+ if clip_mode == "Percentiles (1–99)":
88
+ lo, hi = delays.quantile([0.01, 0.99])
89
+ delays_plot = delays.clip(lo, hi)
90
+ st.caption(f"Clipped to 1st–99th percentiles: [{lo:.0f}, {hi:.0f}] min")
91
+ elif clip_mode == "Fixed range (±24h)":
92
+ lo, hi = -1440, 1440
93
+ delays_plot = delays.clip(lo, hi)
94
+ st.caption("Clipped to ±24 hours: [-1440, 1440] min")
95
+ else:
96
+ delays_plot = delays
97
+ st.caption("No clipping (raw values)")
98
+
99
+ hist_df = pd.DataFrame({"delay_min": delays_plot})
100
+
101
+ chart = (
102
+ alt.Chart(hist_df)
103
+ .mark_bar()
104
+ .encode(
105
+ x=alt.X("delay_min:Q", bin=alt.Bin(maxbins=bins), title="Checkout delay (min)"),
106
+ y=alt.Y("count():Q", title="Count")
107
+ )
108
+ .properties(height=280)
109
+ )
110
+
111
+ st.altair_chart(chart, use_container_width=True)
112
+
113
+
114
+
115
+
116
+ st.divider()
117
+
118
+ st.subheader("Threshold sensitivity (quick curve)")
119
+
120
+ thresholds = np.arange(0, 361, 15)
121
+
122
+ def compute_curve(th):
123
+ affected = (work["gap_min"] < th)
124
+ solved = work["problematic"] & affected
125
+ return affected.mean(), solved.sum()
126
+
127
+ affected_share = []
128
+ solved_counts = []
129
+ for th in thresholds:
130
+ a, s = compute_curve(th)
131
+ affected_share.append(a)
132
+ solved_counts.append(s)
133
+
134
+ curve_df = pd.DataFrame({
135
+ "threshold_min": thresholds,
136
+ "affected_share": affected_share,
137
+ "solved_problematic_cases": solved_counts
138
+ })
139
+
140
+ c1, c2 = st.columns([1,1])
141
+ with c1:
142
+ st.caption("Share of rentals affected (hidden from search)")
143
+ st.line_chart(curve_df.set_index("threshold_min")["affected_share"], height=260)
144
+ with c2:
145
+ st.caption("Number of problematic cases solved")
146
+ st.line_chart(curve_df.set_index("threshold_min")["solved_problematic_cases"], height=260)
147
+
148
+ st.divider()
149
+
150
+ st.subheader("Examples of high-friction situations")
151
+ examples = work[work["problematic"]].copy()
152
+ examples["estimated_wait_min"] = examples["impact_on_next_driver_min"].round(0).astype(int)
153
+ examples = examples.sort_values("estimated_wait_min", ascending=False).head(20)
154
+
155
+ st.dataframe(
156
+ examples[[
157
+ "rental_id",
158
+ "car_id",
159
+ "checkin_type",
160
+ "gap_min",
161
+ "previous_delay_min",
162
+ "estimated_wait_min",
163
+ "affected_by_policy"
164
+ ]],
165
+ use_container_width=True
166
+ )
167
+
168
+ st.caption(
169
+ "Interpretation: estimated_wait_min approximates how long the next driver may have to wait "
170
+ "if the previous driver returns the car late and the planned gap is small."
171
+ )
get_around_pricing_project.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
- altair
2
  pandas
3
- streamlit
 
 
1
+ streamlit
2
  pandas
3
+ numpy
4
+ altair
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
- ))