-
Notifications
You must be signed in to change notification settings - Fork 56
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
Updated load_drains rake task. #198
Closed
squidarth
wants to merge
6
commits into
sfbrigade:production
from
squidarth:sid-shanker/update-rake-task
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
431115f
Updated load_drains rake task.
squidarth 9ae7bc4
Pass rubocop checks.
squidarth 544c8f0
Test new drain creation.
squidarth 7aa3911
Improved drain deletion.
squidarth 526a597
Allow reintroducing deleted rains.
squidarth b9815c9
Added thing email report, refactored load_drains.
squidarth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Hi Adopt a drain admin! | ||
|
||
Just notifying you that drain with PUC_Maximo_Asset_ID: <%= @thing.city_id %>, and rails id <% @thing.id %>, has been removed from the database. |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<h3>Drain Import Report</h3> | ||
|
||
<% if @deleted_drain_ids_with_adoptee.present? %> | ||
<table border="1"> | ||
<thead> | ||
<tr> | ||
<td><b>Drains With Adoptee Removed</b></td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @deleted_drain_ids_with_adoptee.each do |drain_id| %> | ||
<tr> | ||
<td><%= drain_id %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> | ||
|
||
<% if @deleted_drain_ids_with_no_adoptee.present? %> | ||
<table border="1"> | ||
<thead> | ||
<tr> | ||
<td><b>Drains With No Adoptee Removed</b></td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @deleted_drain_ids_with_no_adoptee.each do |drain_id| %> | ||
<tr> | ||
<td><%= drain_id %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> | ||
|
||
<% if @created_drain_ids.present? %> | ||
<table border="1"> | ||
<thead> | ||
<tr> | ||
<td><b>Drains Added</b></td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @created_drain_ids.each do |drain_id| %> | ||
<tr> | ||
<td><%= drain_id %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddDeletedAtToThings < ActiveRecord::Migration | ||
def change | ||
add_column :things, :deleted_at, :datetime | ||
add_index :things, :deleted_at | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,21 @@ class ThingMailerTest < ActionMailer::TestCase | |
assert_equal ['[email protected]'], email.to | ||
assert_equal 'We really do love you, Erik!', email.subject | ||
end | ||
|
||
test 'drain_update_report' do | ||
admin_1 = users(:admin) | ||
admin_2 = users(:admin) | ||
admin_2.update(email: '[email protected]') | ||
email = nil | ||
deleted_thing = things(:thing_1) | ||
|
||
assert_emails(1) do | ||
email = ThingMailer.drain_update_report([deleted_thing], [], []).deliver_now | ||
end | ||
|
||
assert_includes email.to, admin_1.email | ||
assert_includes email.to, admin_2.email | ||
|
||
assert_equal email.subject, 'Adopt-a-Drain import (1 adopted drains removed, 0 drains added, 0 removed)' | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still used?