Skip to content

Instantly share code, notes, and snippets.

@mshock
Created September 2, 2014 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshock/266964c264cbb9feff69 to your computer and use it in GitHub Desktop.
Save mshock/266964c264cbb9feff69 to your computer and use it in GitHub Desktop.
product pipeline algorithm
products=read.csv('stable.csv',header=TRUE)
products = cbind(products, rep(0, dim(products)[1]))
colnames(products)[dim(products)[2]] = 'Unavailable?'
pipeline=read.csv('pipeline.csv', header=TRUE)
pipeline=pipeline[,1:7]
fillLaunchWeeks = function(pipeline){
for(row in c(1:dim(pipeline)[1])){
row.niche = toString(pipeline[,1][row])
row.productType = toString(pipeline[,2][row])
row.pricePoint = toString(pipeline[,3][row])
bestProducts = findBestProducts(row.niche, row.productType, row.pricePoint)
if (dim(bestProducts)[1] > 0){
hasWritten = c()
for(week in 1:4){
ageSet = bestProducts[bestProducts[,10]>(44-week*7),]
ageSet = ageSet[!(row.names(ageSet) %in% hasWritten),]
print(ageSet)
if(dim(ageSet)[1]>0){
pipeline[,week+3][row] = toString(ageSet[1,][,1])
hasWritten = c(hasWritten, row.names(ageSet)[1])
}
}
print(pipeline[row,][4:7])
}
}
return(pipeline)
}
findBestProducts = function(niche, productType, pricePoint){
products[,11][is.na(products[,11])] = 95
products[,10][is.na(products[,10])] = 44
for (week in 1:4){
subset = products[(products[,2] == niche & products[,3] == productType & products[,4] == pricePoint & is.na(products[,15]) == TRUE),]
}
return(subset[order(-subset[,11]),])
}
fill=fillLaunchWeeks(pipeline)
write.table(fill,'newpipeline.csv',sep=',', row.names=FALSE)
newPipeline = fill
getEmptySlots = function(newPipeline){
shoppingList = matrix(ncol=4)
for(row in 1:dim(newPipeline)[1]){
weeks=as.character(which(is.na(newPipeline[row,][4:7])))
for(week in weeks){
shoppingList = rbind(shoppingList,c(as.vector(as.matrix(newPipeline[row,][1:3])),week))
}
}
return(shoppingList)
}
list=getEmptySlots(newPipeline)
write.table(list,'shoppinglist.csv',sep=',',row.names=FALSE, col.names=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment