diff --git a/app/models/office_of_citywide_event_coordination_and_management/nyc_permitted_event_information.rb b/app/models/office_of_citywide_event_coordination_and_management/nyc_permitted_event_information.rb new file mode 100644 index 0000000..ffc746b --- /dev/null +++ b/app/models/office_of_citywide_event_coordination_and_management/nyc_permitted_event_information.rb @@ -0,0 +1,94 @@ +require 'open-uri' +require 'csv' + +module OfficeOfCitywideEventCoordinationAndManagement + class NycPermittedEventInformation < ApplicationRecord + self.table_name = :nyc_permitted_event_informations + + CSV_SODA2_API_ENDPOINT = "https://data.cityofnewyork.us/resource/bkfu-528j.csv" + + def self.url + "https://data.cityofnewyork.us/City-Government/NYC-Permitted-Event-Information/tvpp-9vvx/about_data" + end + + def self.name + "NYC Permitted Event Information" + end + + def self.description + "This list contains information on approved event applications that will occur within the next month. Please note that Permitted Film Events only reflect those permits which will impact one or more streets for at least five days." + end + + def self.data_provided_by + "Office of Citywide Event Coordination and Management (CECM)" + end + + # Dataset Information + def self.agency + "Office of Citywide Event Coordination and Management (CECM)" + end + + # Update + def self.update_frequency + "Daily" + end + + def self.automation + "Yes" + end + + def self.date_made_public + "11/19/2013" + end + + # Topics + def self.category + "City Government" + end + + def self.tags + "event, to do, activity, park, block party, festival, nyc permitted event information, otm, office of the mayor" + end + + # Download + def self.download_csv_with_soda2 + URI.open(CSV_SODA2_API_ENDPOINT) do |f| + f.each_line.each_with_index do |line, index| + next if index == 0 + + data = CSV.parse_line(line) + + event_id = data[0] + event_name = data[1] + start_date_time = data[2] + end_date_time = data[3] + event_agency = data[4] + event_type = data[5] + event_borough = data[6] + event_location = data[7] + event_street_side = data[8] + street_closure_type = data[9] + community_board = data[10] + police_precinct = data[11] + + next if NycPermittedEventInformation.find_by(event_id: event_id).present? + + NycPermittedEventInformation.create!( + event_id: event_id, + event_name: event_name, + start_date_time: start_date_time, + end_date_time: end_date_time, + event_agency: event_agency, + event_type: event_type, + event_borough: event_borough, + event_location: event_location, + event_street_side: event_street_side, + street_closure_type: street_closure_type, + community_board: community_board, + police_precinct: police_precinct + ) + end + end + end + end +end diff --git a/db/migrate/20251119213645_create_nyc_permitted_event_information.rb b/db/migrate/20251119213645_create_nyc_permitted_event_information.rb new file mode 100755 index 0000000..c8a42ce --- /dev/null +++ b/db/migrate/20251119213645_create_nyc_permitted_event_information.rb @@ -0,0 +1,20 @@ +class CreateNycPermittedEventInformation < ActiveRecord::Migration[7.2] + def change + create_table :nyc_permitted_event_informations do |t| + t.integer :event_id + t.string :event_name + t.datetime :start_date_time + t.datetime :end_date_time + t.string :event_agency + t.string :event_type + t.string :event_borough + t.string :event_location + t.string :event_street_side + t.string :street_closure_type + t.string :community_board + t.string :police_precinct + + t.timestamps + end + end +end diff --git a/db/migrate/20251119214325_add_index_to_event_id_for_nyc_permitted_events.rb b/db/migrate/20251119214325_add_index_to_event_id_for_nyc_permitted_events.rb new file mode 100755 index 0000000..237fa5b --- /dev/null +++ b/db/migrate/20251119214325_add_index_to_event_id_for_nyc_permitted_events.rb @@ -0,0 +1,5 @@ +class AddIndexToEventIdForNycPermittedEvents < ActiveRecord::Migration[7.2] + def change + add_index :nyc_permitted_event_informations, :event_id, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3d0c488..be5741c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2025_11_19_212902) do +ActiveRecord::Schema[7.2].define(version: 2025_11_19_214325) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -28,4 +28,22 @@ t.datetime "updated_at", null: false t.index ["original_id"], name: "index_bicycle_counters_on_original_id", unique: true end + + create_table "nyc_permitted_event_informations", force: :cascade do |t| + t.integer "event_id" + t.string "event_name" + t.datetime "start_date_time" + t.datetime "end_date_time" + t.string "event_agency" + t.string "event_type" + t.string "event_borough" + t.string "event_location" + t.string "event_street_side" + t.string "street_closure_type" + t.string "community_board" + t.string "police_precinct" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["event_id"], name: "index_nyc_permitted_event_informations_on_event_id", unique: true + end end