Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proper error handling #9

Merged
merged 1 commit into from
Oct 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/assets/javascripts/survival_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ function findCity(city, state){
initialize(data.response[i].Lat, data.response[i].Long, "grocery");
}
}
}
else if (data.response.length === 0){
$("#results").append("<p class='no-data'>No Data Found</p>");
} else {
$("#results").append("They didn't make it...");
}
}
});
Expand Down Expand Up @@ -68,6 +67,11 @@ function callback(results, status) {
var score = algorithm(population, stores);
$("#results").append("<p>Chance Of Survival: " + score + "%</p>");
}
} else {
runCount++;
if (runCount === 2){
$("#results").append("They didn't make it...");
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions app/models/city.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class City < ActiveRecord::Base

def initialize(name, population, x, y)
@name = name
@population = population
@x_pos = x
@y_pos = y
end

def set_delay(city_b)
distance = Math.sqrt( (@x_pos - city_b.x_pos)**2 + (@y_pos - city_b.y_pos)**2 )
@delay = distance / 10
end

def find_infection_rate
if @population > 1000000
@infection_rate
end

end
12 changes: 12 additions & 0 deletions db/migrate/20141007154526_create_cities_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateCitiesTable < ActiveRecord::Migration
def change
create_table :cities do |t|
t.integer :population
t.float :x_pos
t.float :y_pos
t.integer :delay
t.integer :infect_rate
t.string :name
end
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do
ActiveRecord::Schema.define(version: 20141007154526) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "cities", force: true do |t|
t.integer "population"
t.float "x_pos"
t.float "y_pos"
t.integer "delay"
t.integer "infect_rate"
t.string "name"
end

end