Skip to content

Commit

Permalink
Add rake task to setup STEP
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekEdwards committed Jun 5, 2017
1 parent 878122e commit 8d6a678
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions lib/tasks/cpta.rake
Original file line number Diff line number Diff line change
Expand Up @@ -803,4 +803,90 @@ namespace :oneclick do

end

############### Add Washington County ################
desc "Add STEP (Lycoming and Clinton Counties)"
task set_step: :environment do

puts 'Creating the following services'
ecolane_service = {name: "Shared Ride", external_id: "step"}

puts ecolane_service.ai

service_type = ServiceType.find_by(code: "paratransit")

# Look up service by external id and create if none exists
service = Service.find_or_create_by(external_id: ecolane_service[:external_id]) do |service|
puts 'Creating a new service for ' + ecolane_service.as_json.to_s
service.service_type = service_type
service.name = ecolane_service[:name]
end

# Create a new provider for service if none exists
service.provider ||= Provider.find_or_create_by(name: "#{ecolane_service[:external_id].titleize}") do |provider|
puts "Creating a new provider for service, called #{provider.name}."
end

service.booking_profile = BookingServices::AGENCY[:ecolane]
service.save

#Counties
primary_coverage_counties = ['Clinton', 'Lycoming']
secondary_coverage_counties = ['Clinton', 'Lycoming', 'Centre', 'Union', 'Snyder', 'Montour', 'Columbia', 'Northumberland']

#Funding Sources
funding_source_array = [['Lottery', 1, false, 'Riders 65 or older'], ['AAA', 3, false, "AAA Eligible"], ['PwD', 5, false, 'Persons with disabilities'], ['MATP', 7, 'Medicaid Eligible'], ['ADA', 9, 'ADA Eligible']]

#Sponsors
sponsor_array = [['MATP', 0],['AAA', 1]]

#Dummy User
service.fare_user = "00001"

#Get or create the ecolane_profile
ecolane_profile = EcolaneProfile.find_or_create_by(service: service)

#Optional: Disallowed Trip Purposes
#this is a comma separated string with no spaces around the commas, and all lower-case
#ecolane_profile.disallowed_purposes_text = 'ma urgent care,day care (16),outpatient program (14),psycho-social rehab (17),comm based employ (18),partial prog (12),sheltered workshop/cit (11),social rehab (13)'

#Booking System Id
ecolane_profile.system = 'step'
ecolane_profile.default_trip_purpose = 'Medical'
ecolane_profile.api_version = "8"
ecolane_profile.booking_counties = primary_coverage_counties
ecolane_profile.save

#Clear and set Funding Sources
service.funding_sources.destroy_all
funding_source_array.each do |fs|
new_funding_source = FundingSource.where(service: service, code: fs[0]).first_or_create
new_funding_source.index = fs[1]
new_funding_source.general_public = fs[2]
new_funding_source.comment = fs[3]
new_funding_source.save
end

#Clear and set Sponsors
service.sponsors.destroy_all
sponsor_array.each do |s|
new_sponsor = Sponsor.where(service: service, code: s[0]).first_or_create
new_sponsor.index = s[1]
new_sponsor.save
end

#Confirm API Token is set
if service.ecolane_profile.token.nil?
puts 'Be sure to setup a token for ' + service.name + ' STEP, service_id = ' + service.id.to_s
puts 'In console, run: Service.find(<id>).ecolane_profile.update_attributes(token: "<token>") '
end

# Build Service Coverage Area Geometries
service.primary_coverage = CoverageZone.build_coverage_area(primary_coverage_counties)
service.secondary_coverage = CoverageZone.build_coverage_area(secondary_coverage_counties)

service.save

end


end

0 comments on commit 8d6a678

Please sign in to comment.