DT.weekly_percs2
DT.rel_dates.apprvd_titles
DT.rel_dates.owned_and_tvt

DT.groupings <- DT.weekly_percs2[, list(grouping=unique(grouping)), by=list(releaseid, category, victory, special_treatment)]

## CONFIRM: No duplicates and every releaseid is accounted for
stopifnot(DT.groupings[, !any(duplicated(releaseid))])
stopifnot(DT.groupings[, lunique(releaseid)] == nrow(DT.rel_dates.apprvd_titles) + nrow(DT.rel_dates.owned_and_tvt))

Pricing <- c(10.99, 9.99, 8.99)
Probs   <- c( 0.38, 0.38, 0.24)

DT.groupings[, Price_Wk1 := NA_real_]
DT.groupings[, Price_Wk2 := NA_real_]


## For victory, only choose between prices less than 10
DT.groupings[(victory), Price_Wk1 := sampleWithAccurateProbs(c(9.99, 8.99), .N, TRUE, prob=c(0.6, 0.4)), by=grouping]
DT.groupings[(victory), Price_Wk2 := sampleWithAccurateProbs(c(9.99, 8.99), .N, TRUE, prob=c(0.6, 0.4)), by=grouping]
DT.groupings[(victory)]

## No change for any group where category is NA
DT.groupings[grouping == "CATEGROY IS NA -- DONT CHANGE", Price_Wk1 := 8.99]
DT.groupings[grouping == "CATEGROY IS NA -- DONT CHANGE", Price_Wk2 := 8.99]

## For victory, only choose between prices less than 10
DT.groupings[(is.na(Price_Wk1)), Price_Wk1 := sampleWithAccurateProbs(Pricing, .N, TRUE, prob=Probs, verbose=FALSE), by=grouping]
DT.groupings[(is.na(Price_Wk2)), Price_Wk2 := sampleWithAccurateProbs(Pricing, .N, TRUE, prob=Probs, verbose=FALSE), by=grouping]
DT.groupings[(!special_treatment)]

## add info and fix col order
addColsFrom_(DT.groupings, rbind(DT.rel_dates.apprvd_titles, DT.rel_dates.owned_and_tvt), joinCols.r="releaseid", joinCols.g="UPC", colsToBring=c("releasedate", "source"))
setcolorderpt(DT.groupings, endCols=c("Price_Wk1", "Price_Wk2"))

DT.groupings <- DT.groupings[order(special_treatment, victory, releaseid, decreasing=TRUE)]

## OUTPUT
f.out <- out.p("EU_pricing_UPCs_with_weekly_price_change.csv")
write.csv(file=f.out, DT.groupings, row.names=FALSE)
cat(sprintf("\n\n  bringme('%s')\n\n", f.out))