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

Commit

Permalink
Keep current price if initializing a market for the first generator.
Browse files Browse the repository at this point in the history
Fixed #112.
  • Loading branch information
Christopher Peplin committed Oct 26, 2010
1 parent 82c4545 commit f3631fa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/models/fuel_market.rb
Expand Up @@ -15,7 +15,7 @@ def find_current(game)
has_many :generators, :through => :generator_types do
def find_by_game game
# Raw SQL to get around the fact that rails doesn't create the double
# join here properly.
# join here properly.
find(:all, :joins => "INNER JOIN cities ON technical_component_instances.city_id = cities.id INNER JOIN states ON cities.state_id = states.id",
:conditions => {:states => {:game_id => game}})
end
Expand Down Expand Up @@ -48,7 +48,11 @@ def clear game
last_price = market_prices.find_current(game)
old_demand = average_demand(game, last_price.created_at)
new_demand = average_demand(game)
new_price = last_price.price + (supply_slope * (new_demand - old_demand))
if old_demand == 0
new_price = last_price.price
else
new_price = last_price.price + (supply_slope * (new_demand - old_demand))
end
market_prices.create :price => new_price, :game => game
end

Expand Down

0 comments on commit f3631fa

Please sign in to comment.