igroffman commited on
Commit
8722bc6
·
verified ·
1 Parent(s): 138ab75

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +10 -16
app.R CHANGED
@@ -2095,25 +2095,19 @@ standardize_stuffplus_to_league <- function(data, league_comparison_data) {
2095
  data <- ensure_stuff_inputs(data)
2096
  league_comparison_data <- ensure_stuff_inputs(league_comparison_data)
2097
 
2098
- # FIX: Convert Date columns to character in both datasets before binding
2099
- if ("Date" %in% names(data)) data$Date <- as.character(data$Date)
2100
- if ("Date" %in% names(league_comparison_data)) league_comparison_data$Date <- as.character(league_comparison_data$Date)
2101
-
2102
- # Also handle any other potentially mismatched columns
2103
- convert_to_char <- function(df, cols) {
2104
- for (col in cols) {
2105
- if (col %in% names(df)) df[[col]] <- as.character(df[[col]])
 
 
2106
  }
2107
- df
2108
  }
2109
 
2110
- problem_cols <- c("Date", "Time", "Tilt", "UTCTime" "UTCDate", "UTCDateTime", "LocalDateTime",
2111
- "HomeTeamForeignID", "AwayTeamForeignID", "GameUID",
2112
- "PitchUID", "PlayID")
2113
-
2114
- data <- convert_to_char(data, problem_cols)
2115
- league_comparison_data <- convert_to_char(league_comparison_data, problem_cols)
2116
-
2117
  data$raw_stuff <- predict(stuffplus_model, data, type = "numeric")$.pred
2118
 
2119
  data <- data %>%
 
2095
  data <- ensure_stuff_inputs(data)
2096
  league_comparison_data <- ensure_stuff_inputs(league_comparison_data)
2097
 
2098
+ common_cols <- intersect(names(data), names(league_comparison_data))
2099
+
2100
+ for (col in common_cols) {
2101
+ type1 <- class(data[[col]])[1]
2102
+ type2 <- class(league_comparison_data[[col]])[1]
2103
+
2104
+ if (type1 != type2) {
2105
+ message("Converting mismatched column '", col, "': ", type1, " vs ", type2)
2106
+ data[[col]] <- as.character(data[[col]])
2107
+ league_comparison_data[[col]] <- as.character(league_comparison_data[[col]])
2108
  }
 
2109
  }
2110
 
 
 
 
 
 
 
 
2111
  data$raw_stuff <- predict(stuffplus_model, data, type = "numeric")$.pred
2112
 
2113
  data <- data %>%