Created
May 5, 2011 13:40
-
-
Save callumj/957041 to your computer and use it in GitHub Desktop.
Palo data generator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_store_data | |
results = {} | |
results[:combo_meal_exclusions] = {} | |
results[:combo_meal_promotion] = {} | |
for year in 2005..2010 do | |
results[:combo_meal_exclusions][year.to_s] = {} | |
results[:combo_meal_promotion][year.to_s] = {} | |
for store_num in 1..22 do | |
results[:combo_meal_exclusions][year.to_s]["Store #{store_num}"] = [] | |
for num_exclusions in 0..rand(3) do | |
if (num_exclusions != 0) | |
combo_meal_num = (rand(6) + 1) | |
rand_str = "Combo meal #{combo_meal_num}" | |
results[:combo_meal_exclusions][year.to_s]["Store #{store_num}"] << rand_str if !results[:combo_meal_exclusions][year.to_s]["Store #{store_num}"].include?(rand_str) | |
end | |
end | |
end | |
for store_num in 1..22 do | |
results[:combo_meal_promotion][year.to_s]["Store #{store_num}"] = {} | |
for combo_meal in 1..6 do | |
results[:combo_meal_promotion][year.to_s]["Store #{store_num}"]["Combo meal #{combo_meal}"] = [] | |
results[:combo_meal_promotion][year.to_s]["Store #{store_num}"]["Combo meal #{combo_meal}"] << "No promotion" | |
for num_exclusions in 0..rand(3) do | |
if (num_exclusions != 0) | |
promotion_num = (rand(6) + 1) | |
promotion_str = "Promotion #{promotion_num}" | |
results[:combo_meal_promotion][year.to_s]["Store #{store_num}"]["Combo meal #{combo_meal}"] << promotion_str if !results[:combo_meal_promotion][year.to_s]["Store #{store_num}"]["Combo meal #{combo_meal}"].include?(promotion_str) | |
end | |
end | |
end | |
end | |
end | |
results | |
end | |
file=ARGV[0] | |
f = File.open(file, "r") | |
#business rules | |
low_priced = [1,2] | |
medium_priced = [3, 4] | |
high_priced = [5, 6] | |
pricing = {} | |
pricing[:low] = Range.new(112, 195) | |
pricing[:medium] = Range.new(210, 270) | |
pricing[:high] = Range.new(350, 470) | |
popularity_factor = {} | |
popularity_factor[:low] = 3.0 | |
popularity_factor[:medium] = 2.5 | |
popularity_factor[:high] = 2.0 | |
store_data = generate_store_data | |
combo_meal_exclusions = store_data[:combo_meal_exclusions] | |
combo_meal_promotions = store_data[:combo_meal_promotion] | |
allData = [] | |
combo_meal_dictionary = {} | |
for combo_meal_num in 1..6 do | |
combo_meal_dictionary["Combo meal #{combo_meal_num}"] = {} | |
for store_num in 1..22 do | |
combo_meal_dictionary["Combo meal #{combo_meal_num}"]["Store #{store_num}"] = {} | |
for pricing_key in [:low, :medium, :high] do | |
pricing_range = pricing[pricing_key] | |
rand_additional_value = rand(pricing_range.last - pricing_range.first) | |
finalValue = (rand_additional_value + pricing_range.first) * 1.0 | |
combo_meal_dictionary["Combo meal #{combo_meal_num}"]["Store #{store_num}"][pricing_key.to_s] = (finalValue / 100.0) | |
end | |
end | |
end | |
f.each_line { |line| | |
trun1 = line[0,line.rindex(',')] | |
trun2 = trun1[0,trun1.rindex(',')] | |
hashKey = trun2[0,trun2.rindex(',')] | |
allData << hashKey if !allData.include?(hashKey) | |
$stderr.puts allData.size | |
} | |
f.close | |
for x in allData do | |
contents = x.split(/[,]\s?/) | |
combo_meal = contents[0] | |
year = contents[1] | |
month = contents[2] | |
day_of_week = contents[3] | |
store_name = contents[4] | |
pricing_category = contents[5] | |
unit_price = 0 | |
unit_sales = 0 | |
total_generated = 0 | |
excluded_meals = combo_meal_exclusions[year][store_name] | |
if (!excluded_meals.include?(combo_meal)) | |
unit_price = combo_meal_dictionary[combo_meal][store_name][pricing_category.downcase] | |
price_symbol = nil | |
#determine what pricing category it is | |
for symbol in pricing.keys | |
rangeOfPrice = pricing[symbol] | |
price_symbol = symbol if (unit_price * 100) >= rangeOfPrice.first && rangeOfPrice.last >= (unit_price * 100) | |
end | |
unit_sales = rand(100) * popularity_factor[price_symbol] | |
total_generated = unit_price * unit_sales | |
end | |
promotions_available = combo_meal_promotions[year][store_name][combo_meal] | |
randIndex = rand(promotions_available.size) | |
promotion_target = promotions_available[randIndex] | |
#puts "#{x},Unit cost,#{unit_price}" | |
#puts "#{x},Units sold,#{unit_sales.to_i}" | |
puts "#{x},Total generated,#{promotion_target},#{total_generated}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment