Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Seed data for graphs in demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Peplin committed Nov 7, 2010
1 parent 94b54eb commit d3e887b
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions db/seeds.rb
Expand Up @@ -56,9 +56,11 @@
]

games = []
games << Factory(:game, :nickname => "Australia")
games << Factory(:game, :nickname => "United States")
games << Factory(:game, :nickname => "Pangea")
games << Factory(:game, :nickname => "Australia", :created_at => 10.days.ago)
games << Factory(:game, :nickname => "United States",
:created_at => 10.days.ago)
games << Factory(:game, :nickname => "Pangea", :created_at => 10.days.ago)


users = []
users << Factory(:user)
Expand All @@ -67,13 +69,47 @@

srand
games.each_with_index do |game, i|
(game.created_at..Time.now).step(1.day).each do |t|
FuelMarket.all.each do |market|
game.market_prices.create :fuel_market => market,
:price => market.initial_average_price + rand(10),
:created_at => Time.at(t)
end
end

users.each_with_index do |user, j|
state = Factory(:state, :game => game, :user => user,
:name => STATE_NAMES[(i + 1) * j])
:name => STATE_NAMES[(i + 1) * j],
:created_at => 10.days.ago,
:stepped_at => 10.days.ago,
:costs_deducted_at => 10.days.ago,
:customers_charged_at => 10.days.ago)

(state.created_at..Time.now).step(1.day).each do |t|
state.marginal_prices.create :created_at => Time.at(t),
:marginal_price => rand(3000)
end

state.cities.each do |city|
Factory(:generator, :city => state.cities.first,
:generator_type => GeneratorType.find(
rand(GeneratorType.all.count) + 1))
while not state.demand_met? do
generator = Factory(:generator,
:city => state.cities[rand(state.cities.length)],
:generator_type => GeneratorType.find(
rand(GeneratorType.all.count) + 1),
:created_at => (rand(9) + 1).days.ago)
(generator.created_at..Time.now).step(1.day).each do |t|
generator.average_operating_levels.create(
:operating_level => rand(100),
:created_at => Time.at(t))
end
end
end
# two more for good measure, relability constraint
Factory(:generator, :city => state.cities.first,
:generator_type => GeneratorType.find(
rand(GeneratorType.all.count) + 1))
Factory(:generator, :city => state.cities.first,
:generator_type => GeneratorType.find(
rand(GeneratorType.all.count) + 1))
end
end

0 comments on commit d3e887b

Please sign in to comment.