Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -753,34 +753,34 @@ create_report_contact_chart <- function(game_data, player_name) {
|
|
| 753 |
|
| 754 |
calculate_leaderboards <- function(df, team_meta_df = team_meta) {
|
| 755 |
|
| 756 |
-
# Helper to format names from "Last, First" to "First Last"
|
| 757 |
format_name <- function(name) {
|
| 758 |
if (is.na(name)) return(name)
|
| 759 |
stringr::str_replace(name, "^\\s*(\\w+)\\s*,\\s*(\\w+)\\s*$", "\\2 \\1")
|
| 760 |
}
|
| 761 |
|
| 762 |
get_logo <- function(team_abbr) {
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
}
|
| 773 |
-
|
| 774 |
-
get_team_name <- function(abbr) {
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
|
|
|
| 784 |
|
| 785 |
# Game Info
|
| 786 |
stadium <- if ("Stadium" %in% names(df)) unique(na.omit(df$Stadium))[1] else "Unknown"
|
|
@@ -827,13 +827,6 @@ game_date <- if ("Date" %in% names(df)) {
|
|
| 827 |
team2 <- score_info$BatterTeam[2]
|
| 828 |
runs2 <- score_info$Runs[2]
|
| 829 |
|
| 830 |
-
# Get team names from TMB if available
|
| 831 |
-
get_team_name <- function(abbr) {
|
| 832 |
-
if (is.null(team_meta_df)) return(abbr)
|
| 833 |
-
name <- team_meta_df$BTeamName[team_meta_df$team_abbr == abbr]
|
| 834 |
-
if (length(name) == 0 || is.na(name[1])) return(abbr)
|
| 835 |
-
name[1]
|
| 836 |
-
}
|
| 837 |
|
| 838 |
final_score <- paste0(get_team_name(team1), " ", runs1, " - ",
|
| 839 |
get_team_name(team2), " ", runs2)
|
|
|
|
| 753 |
|
| 754 |
calculate_leaderboards <- function(df, team_meta_df = team_meta) {
|
| 755 |
|
|
|
|
| 756 |
format_name <- function(name) {
|
| 757 |
if (is.na(name)) return(name)
|
| 758 |
stringr::str_replace(name, "^\\s*(\\w+)\\s*,\\s*(\\w+)\\s*$", "\\2 \\1")
|
| 759 |
}
|
| 760 |
|
| 761 |
get_logo <- function(team_abbr) {
|
| 762 |
+
if (is.null(team_meta_df) || is.null(team_abbr) || is.na(team_abbr)) return("")
|
| 763 |
+
team_abbr <- trimws(as.character(team_abbr))
|
| 764 |
+
if (team_abbr == "") return("")
|
| 765 |
+
tmb_abbrs <- trimws(as.character(team_meta_df$team_abbr))
|
| 766 |
+
idx <- which(tmb_abbrs == team_abbr)
|
| 767 |
+
if (length(idx) > 0) return(team_meta_df$BTeamLogo[idx[1]])
|
| 768 |
+
idx <- which(tolower(tmb_abbrs) == tolower(team_abbr))
|
| 769 |
+
if (length(idx) > 0) return(team_meta_df$BTeamLogo[idx[1]])
|
| 770 |
+
""
|
| 771 |
+
}
|
| 772 |
+
|
| 773 |
+
get_team_name <- function(abbr) {
|
| 774 |
+
if (is.null(team_meta_df) || is.null(abbr) || is.na(abbr)) return(as.character(abbr))
|
| 775 |
+
abbr <- trimws(as.character(abbr))
|
| 776 |
+
if (abbr == "") return(abbr)
|
| 777 |
+
tmb_abbrs <- trimws(as.character(team_meta_df$team_abbr))
|
| 778 |
+
idx <- which(tmb_abbrs == abbr)
|
| 779 |
+
if (length(idx) > 0) return(team_meta_df$BTeamName[idx[1]])
|
| 780 |
+
idx <- which(tolower(tmb_abbrs) == tolower(abbr))
|
| 781 |
+
if (length(idx) > 0) return(team_meta_df$BTeamName[idx[1]])
|
| 782 |
+
abbr
|
| 783 |
+
}
|
| 784 |
|
| 785 |
# Game Info
|
| 786 |
stadium <- if ("Stadium" %in% names(df)) unique(na.omit(df$Stadium))[1] else "Unknown"
|
|
|
|
| 827 |
team2 <- score_info$BatterTeam[2]
|
| 828 |
runs2 <- score_info$Runs[2]
|
| 829 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 830 |
|
| 831 |
final_score <- paste0(get_team_name(team1), " ", runs1, " - ",
|
| 832 |
get_team_name(team2), " ", runs2)
|