Skip to content

Commit

Permalink
Merge pull request #9 from stbarrientos/fixing-ajax
Browse files Browse the repository at this point in the history
proper error handling
  • Loading branch information
cpolitano committed Oct 8, 2014
2 parents f631717 + 8ad4bf4 commit ba88d15
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
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

0 comments on commit ba88d15

Please sign in to comment.