-
Notifications
You must be signed in to change notification settings - Fork 479
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
Census auto update new map #20575
Merged
Merged
Census auto update new map #20575
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# The map on code.org/yourschool is run off of a Google Fusion Table | ||
# (documentation: https://developers.google.com/maps/documentation/javascript/fusiontableslayer). | ||
# This script updates the fusion table using the REST API | ||
# (documentation: https://developers.google.com/fusiontables/docs/v2/using), | ||
# populating it with all rows from the census_summaries table for the appropriate school year. | ||
|
||
# After setting up authentication, provide the following CDO.* attributes: | ||
# CDO.hoc_map_account: (JSON of a credential which can edit the FusionTables table) | ||
# CDO.census_map_table_id: (the id of the fusion table) | ||
|
||
require_relative '../../dashboard/config/environment' | ||
require 'cdo/properties' | ||
|
||
require 'google/apis/fusiontables_v2' | ||
require 'googleauth' | ||
|
||
TABLE_ID = CDO.census_map_table_id.freeze | ||
|
||
def make_location(lat, long) | ||
return nil if lat.nil? || long.nil? | ||
|
||
"#{format('%.6f', lat)}, #{format('%.6f', long)}" | ||
end | ||
|
||
# The map should show the data from the school year that began | ||
# in the previous calendar year. So, Aug-Dec we show the previous school | ||
# year's data and then switch over to the current school year in Jan. | ||
year = Date.today.year - 1 | ||
|
||
file = Tempfile.new(['data', '.csv']) | ||
begin | ||
CSV.open(file.path, 'w') do |csv| | ||
Census::CensusSummary.where(school_year: year).find_each do |summary| | ||
school = summary.school | ||
location = make_location(school.latitude, school.longitude) | ||
csv << [school.id, year, school.name.titleize, school.city.titleize, school.state, location, summary.teaches_cs] | ||
end | ||
end | ||
ensure | ||
file.close | ||
end | ||
|
||
tables = Google::Apis::FusiontablesV2::FusiontablesService.new | ||
|
||
tables.authorization = Google::Auth::ServiceAccountCredentials.make_creds( | ||
scope: 'https://www.googleapis.com/auth/fusiontables', | ||
json_key_io: StringIO.new(CDO.hoc_map_account.to_json) | ||
) | ||
|
||
tables.replace_table_rows(TABLE_ID, content_type: 'application/octet-stream', upload_source: file.path) |
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 |
---|---|---|
|
@@ -46,6 +46,7 @@ def load_configuration | |
'build_apps' => false, | ||
'build_dashboard' => true, | ||
'build_pegasus' => true, | ||
'census_map_table_id' => rack_env == :production ? '1AUZYRjLMI5NiQsDeDBGFsOIFpL_rLGsnxNpSyR13' : nil, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any downside to this being in the repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. You can see the value if you view source on the page. |
||
'chef_local_mode' => rack_env == :adhoc, | ||
'dcdo_table_name' => "dcdo_#{rack_env}", | ||
'dashboard_assets_dir' => "#{root_dir}/dashboard/public/assets", | ||
|
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.
We can still set these via locals.yml?
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.
Yes. That is how I'm testing.