Skip to content

pedrokost/klubi-api

Repository files navigation

Klubi Slovenije

View performance data on Skylight View performance data on Skylight

  • Configuration

To configure the WANTED_OUTGOING_EMAIL_DISTRIBTION env variable use something like this:

# During rounding you loose precesion, need to make it again a distribution
d_unnormalized = ([0] * 6 + [1.0/12] * 15 + [0] * 3).map{ |e| e + 0.01 }
sum_d = d_unnormalized.sum.to_f
d_normalized = d_unnormalized.map{ |e| (e / sum_d).round(2) }
sum_d = d_normalized.sum.to_f
max_index = d_normalized.each_with_index.max[1]
d_normalized[max_index] += (1 - sum_d)
d_normalized[max_index] = d_normalized[max_index].round(2)
raise "Distribution does not sum to 1" unless d_normalized.sum.round(4) == 1.0
raise "Distribution is not of length 24" unless d_normalized.length == 24
p d_normalized.join(',')

This gives a tiny chance to nighly emails!

  • Database creation
sudo su - postgres
psql template1

create user zatresi with password 'pass';
CREATE DATABASE "zatresi-api_development";
GRANT ALL PRIVILEGES ON DATABASE "zatresi-api_development" to zatresi;
CREATE DATABASE "zatresi-api_test";
GRANT ALL PRIVILEGES ON DATABASE "zatresi-api_test" to zatresi;
\q
  • Database initialization
foreman run bundle exec rake db:migrate RAILS_ENV=development
foreman run bundle exec rake db:test:prepare

Import latest production backup to local db

heroku pg:backups:capture
heroku pg:backups:download

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U zatresi -d zatresi-api_development latest.dump
rm latest.dump

Altnatively, run rake db:seed to seed default data into the database.

  • How to run the test suite
foreman run bundle exec rspec spec/

Deployment instructions

https://github.com/cyberdelia/heroku-geo-buildpack/

heroku buildpacks:set https://github.com/cyberdelia/heroku-geo-buildpack.git
heroku buildpacks:add heroku/ruby
git push heroku master

Setup the cron job to execute rake sitemap:refresh regularly (e.g. daily)

Sitemap:

rake sitemap:refresh
rake sitemap:refresh:no_ping

Tasks

  1. Daily: Send an email for accepted klub updates
foreman run rake updates:send_emails
  1. Daily: Send email to request data verification to klubs
foreman run rake klubs:send_emails

foreman run rails s puma -b 'ssl://127.0.0.1:3200?key=/home/vagrant/.ssh/server.key&cert=/home/ubuntu/.ssh/server.crt'

  1. Manual: To import data

Create a new DataSource and a new Transformer for the data. Register it in data_import.rake

foreman run rake import:your_import_script

Resources

shp2pgsql -I -s 3912:4326 f1f60b8a-6513-5102-987c-4950a36c72ec.shp public.statisticne_regije_testff | psql -h localhost -U zatresi -d zatresi-api_development

Attribution

Source of administrative regions: Statistical Office of the Republic of Slovenia.