Spaces:
Sleeping
Sleeping
Commit ·
c1893f5
1
Parent(s): 936744c
refactor: Display insights from source data
Browse files
app.py
CHANGED
|
@@ -207,35 +207,95 @@ def _(mo):
|
|
| 207 |
|
| 208 |
|
| 209 |
@app.cell
|
| 210 |
-
def _(
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
st1 = mo.stat(
|
| 214 |
-
label="Total Revenue
|
| 215 |
bordered=True,
|
| 216 |
-
value=f"${
|
| 217 |
-
caption=f"Previous year: ${
|
| 218 |
-
direction="increase",
|
| 219 |
)
|
|
|
|
| 220 |
st2 = mo.stat(
|
| 221 |
label="Successful Deliveries",
|
| 222 |
bordered=True,
|
| 223 |
-
value=f"{
|
| 224 |
-
caption="
|
| 225 |
direction="increase",
|
| 226 |
)
|
|
|
|
| 227 |
st3 = mo.stat(
|
| 228 |
label="Uncompleted Orders",
|
| 229 |
bordered=True,
|
| 230 |
-
value=f"{
|
| 231 |
-
caption="
|
| 232 |
direction="decrease",
|
| 233 |
)
|
|
|
|
| 234 |
st4 = mo.stat(
|
| 235 |
label="Category with greater revenue",
|
| 236 |
bordered=True,
|
| 237 |
-
value=
|
| 238 |
-
caption=f"${
|
| 239 |
direction="increase",
|
| 240 |
)
|
| 241 |
|
|
@@ -436,7 +496,7 @@ def _(mo):
|
|
| 436 |
def _(mo):
|
| 437 |
mo.center(
|
| 438 |
mo.md(
|
| 439 |
-
"**Connect with me:** 💼 [Linkedin](https://www.linkedin.com/in/alex-turpo/)
|
| 440 |
)
|
| 441 |
)
|
| 442 |
return
|
|
|
|
| 207 |
|
| 208 |
|
| 209 |
@app.cell
|
| 210 |
+
def _(
|
| 211 |
+
global_amount_order_status,
|
| 212 |
+
revenue_by_month_year,
|
| 213 |
+
top_10_revenue_categories,
|
| 214 |
+
):
|
| 215 |
+
# 📌 RETRIEVE INSIGHTS VALUES
|
| 216 |
+
|
| 217 |
+
# [1]
|
| 218 |
+
total_2018 = revenue_by_month_year["Year2018"].sum()
|
| 219 |
+
total_2017 = revenue_by_month_year["Year2017"].sum()
|
| 220 |
+
|
| 221 |
+
# [2]
|
| 222 |
+
delivered = global_amount_order_status.loc[
|
| 223 |
+
global_amount_order_status["order_status"] == "delivered", "Amount"
|
| 224 |
+
].values[0]
|
| 225 |
+
|
| 226 |
+
# Get total number of orders and delivery rate as a percentage string
|
| 227 |
+
total_orders = global_amount_order_status["Amount"].sum()
|
| 228 |
+
delivery_rate = delivered / total_orders
|
| 229 |
+
percentage = f"{delivery_rate:.1%}" # e.g., '85.2%'
|
| 230 |
+
|
| 231 |
+
# [3]
|
| 232 |
+
# Uncompleted orders = total - delivered
|
| 233 |
+
uncompleted = total_orders - delivered
|
| 234 |
+
uncompleted_pct = f"{(uncompleted / total_orders) * 100:.1f}%"
|
| 235 |
+
|
| 236 |
+
# [4]
|
| 237 |
+
top_cat = top_10_revenue_categories.iloc[0]
|
| 238 |
+
|
| 239 |
+
cat_name = top_cat["Category"].replace("_", " ").title()
|
| 240 |
+
cat_num_orders = int(top_cat["Num_order"])
|
| 241 |
+
cat_revenue = top_cat["Revenue"]
|
| 242 |
+
return (
|
| 243 |
+
cat_name,
|
| 244 |
+
cat_num_orders,
|
| 245 |
+
cat_revenue,
|
| 246 |
+
delivered,
|
| 247 |
+
percentage,
|
| 248 |
+
total_2017,
|
| 249 |
+
total_2018,
|
| 250 |
+
uncompleted,
|
| 251 |
+
uncompleted_pct,
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
@app.cell
|
| 256 |
+
def _(
|
| 257 |
+
cat_name,
|
| 258 |
+
cat_num_orders,
|
| 259 |
+
cat_revenue,
|
| 260 |
+
delivered,
|
| 261 |
+
mo,
|
| 262 |
+
percentage,
|
| 263 |
+
total_2017,
|
| 264 |
+
total_2018,
|
| 265 |
+
uncompleted,
|
| 266 |
+
uncompleted_pct,
|
| 267 |
+
):
|
| 268 |
+
# 📌 DISPLAY INSIGHTS
|
| 269 |
|
| 270 |
st1 = mo.stat(
|
| 271 |
+
label="Total Revenue 2018",
|
| 272 |
bordered=True,
|
| 273 |
+
value=f"${total_2018:,.0f}",
|
| 274 |
+
caption=f"Previous year: ${total_2017:,.0f}",
|
| 275 |
+
direction="increase" if total_2018 > total_2017 else "decrease",
|
| 276 |
)
|
| 277 |
+
|
| 278 |
st2 = mo.stat(
|
| 279 |
label="Successful Deliveries",
|
| 280 |
bordered=True,
|
| 281 |
+
value=f"{delivered:,}",
|
| 282 |
+
caption=f"{percentage} of total orders",
|
| 283 |
direction="increase",
|
| 284 |
)
|
| 285 |
+
|
| 286 |
st3 = mo.stat(
|
| 287 |
label="Uncompleted Orders",
|
| 288 |
bordered=True,
|
| 289 |
+
value=f"{uncompleted:,}",
|
| 290 |
+
caption=f"{uncompleted_pct} of total orders",
|
| 291 |
direction="decrease",
|
| 292 |
)
|
| 293 |
+
|
| 294 |
st4 = mo.stat(
|
| 295 |
label="Category with greater revenue",
|
| 296 |
bordered=True,
|
| 297 |
+
value=cat_name,
|
| 298 |
+
caption=f"{cat_num_orders:,} orders • Revenue: ${cat_revenue:,.0f}",
|
| 299 |
direction="increase",
|
| 300 |
)
|
| 301 |
|
|
|
|
| 496 |
def _(mo):
|
| 497 |
mo.center(
|
| 498 |
mo.md(
|
| 499 |
+
"**Connect with me:** 💼 [Linkedin](https://www.linkedin.com/in/alex-turpo/) • 🐱 [GitHub](https://github.com/iBrokeTheCode) • 🤗 [Hugging Face](https://huggingface.co/iBrokeTheCode)"
|
| 500 |
)
|
| 501 |
)
|
| 502 |
return
|