-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made the following changes: * Delete all drains from DB that are no longer in the dataset. * Update properties on existing drains
- Loading branch information
Showing
4 changed files
with
67 additions
and
30 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,7 @@ | ||
require 'rake' | ||
|
||
namespace :data do | ||
require 'open-uri' | ||
require 'csv' | ||
|
||
task load_drains: :environment do | ||
puts 'Downloading Drains... ... ...' | ||
url = 'https://data.sfgov.org/api/views/jtgq-b7c5/rows.csv?accessType=DOWNLOAD' | ||
csv_string = open(url).read | ||
drains = CSV.parse(csv_string, headers: true) | ||
puts "Downloaded #{drains.size} Drains." | ||
|
||
drains.each do |drain| | ||
next unless ['Storm Water Inlet Drain', 'Catch Basin Drain'].include?(drain['Drain_Type']) | ||
|
||
(lat, lng) = drain['Location'].delete('()').split(',').map(&:strip) | ||
|
||
thing_hash = { | ||
name: drain['Drain_Type'], | ||
system_use_code: drain['System_Use_Code'], | ||
lat: lat, | ||
lng: lng, | ||
} | ||
|
||
thing = Thing.where(city_id: drain['PUC_Maximo_Asset_ID'].gsub!('N-', '')).first_or_initialize | ||
if thing.new_record? | ||
puts "Updating thing #{thing_hash[:city_id]}" | ||
else | ||
puts "Creating thing #{thing_hash[:city_id]}" | ||
end | ||
|
||
thing.update_attributes!(thing_hash) | ||
end | ||
Thing.load_drains('https://data.sfgov.org/api/views/jtgq-b7c5/rows.csv?accessType=DOWNLOAD') | ||
end | ||
end |
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
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