## Study 1 — clean: data/data_raw/raw_study1_(252322).csv -> data/data_cleaned/study1_clean_(252322).Rds
## Design: ai-chat / ai-nochat / chat / nochat. Keeps the AI partner rows (id "AI-…"), which the
## WoA analysis uses as session partners. Substantive recoding and analysis live in the manuscript QMD.
source(here::here("R", "_helpers.R"))

d <- read.csv(path_raw("raw_study1_(252322).csv"), stringsAsFactors = FALSE)
d$is_ai <- grepl("^AI-", d$id)   # AI partner rows (kept for the partner lookup, excluded from analysis)
d$completed_flag <- tolower(trimws(as.character(d$completed))) %in% c("1", "true", "t", "yes")
d$condition <- factor(d$treatment)
if ("initial_forecast" %in% names(d)) d$initial <- suppressWarnings(as.numeric(d$initial_forecast))
if ("revised_forecast" %in% names(d)) d$revised <- suppressWarnings(as.numeric(d$revised_forecast))

dir.create(here::here("data", "data_cleaned"), showWarnings = FALSE, recursive = TRUE)
saveRDS(d, path_clean("study1_clean_(252322).Rds"))
message(sprintf("study1_clean_(252322).Rds: %d rows, %d completed; conditions: %s",
  nrow(d), sum(d$completed_flag), paste(levels(d$condition), collapse = "/")))
