Update app.py
Browse files
app.py
CHANGED
@@ -476,9 +476,7 @@ def server(input, output, session):
|
|
476 |
|
477 |
# Define the columns to subtract
|
478 |
cols_to_subtract = [
|
479 |
-
|
480 |
-
("rhh_percent", "rhh_percent_old"),
|
481 |
-
("lhh_percent", "lhh_percent_old"),
|
482 |
("start_speed", "start_speed_old"),
|
483 |
("max_start_speed", "max_start_speed_old"),
|
484 |
("ivb", "ivb_old"),
|
@@ -513,21 +511,26 @@ def server(input, output, session):
|
|
513 |
])
|
514 |
|
515 |
|
|
|
|
|
|
|
|
|
|
|
516 |
|
517 |
-
percent_cols = ['pitch_percent', 'rhh_percent', 'lhh_percent']
|
518 |
|
519 |
# Step 2: Format the columns with (value (+diff)) - exclude brackets if diff is 80
|
520 |
df_merge = df_merge.with_columns([
|
521 |
pl.when(pl.col(new + "_diff").eq(10000)) # If diff is 80, no need to include brackets
|
522 |
-
.then((pl.col(new)
|
523 |
.otherwise(
|
524 |
-
(pl.col(new)
|
525 |
"\n(" +
|
526 |
-
pl.col(new + "_diff").round(1)
|
527 |
-
.map_elements(lambda x: f"{x:+.1f}
|
528 |
")"
|
529 |
).alias(new + "_formatted")
|
530 |
-
for new, _ in
|
531 |
])
|
532 |
|
533 |
|
|
|
476 |
|
477 |
# Define the columns to subtract
|
478 |
cols_to_subtract = [
|
479 |
+
|
|
|
|
|
480 |
("start_speed", "start_speed_old"),
|
481 |
("max_start_speed", "max_start_speed_old"),
|
482 |
("ivb", "ivb_old"),
|
|
|
511 |
])
|
512 |
|
513 |
|
514 |
+
cols_to_subtract_percent = [
|
515 |
+
("pitch_percent", "pitch_percent_old"),
|
516 |
+
("rhh_percent", "rhh_percent_old"),
|
517 |
+
("lhh_percent", "lhh_percent_old"),
|
518 |
+
]
|
519 |
|
520 |
+
# percent_cols = ['pitch_percent', 'rhh_percent', 'lhh_percent']
|
521 |
|
522 |
# Step 2: Format the columns with (value (+diff)) - exclude brackets if diff is 80
|
523 |
df_merge = df_merge.with_columns([
|
524 |
pl.when(pl.col(new + "_diff").eq(10000)) # If diff is 80, no need to include brackets
|
525 |
+
.then((pl.col(new)*100).round(1).map_elements(lambda x: f"{x:.1f}%").cast(pl.Utf8)+'\n\t') # Just return the new value as string
|
526 |
.otherwise(
|
527 |
+
(pl.col(new)*100).round(1).map_elements(lambda x: f"{x:.1f}%").cast(pl.Utf8) +
|
528 |
"\n(" +
|
529 |
+
(pl.col(new + "_diff")*100).round(1)
|
530 |
+
.map_elements(lambda x: f"{x:+.1f}") +
|
531 |
")"
|
532 |
).alias(new + "_formatted")
|
533 |
+
for new, _ in cols_to_subtract_percent
|
534 |
])
|
535 |
|
536 |
|