GithubHelp home page GithubHelp logo

teamdata's Introduction

Safecast API / Webapp

This is the Safecast API app, implemented using Ruby / Ruby on Rails.

Getting up and running

We're using postgresql, you'll need to install that locally.

Then:

createuser safecast

To create a local user... making sure to agree to making the user a superuser.

Ruby Version

Ruby 1.9.3 is the latest Ruby version, and includes performance fixes for require, thereby decreasing loading time significantly.

RVM

The app includes a .rvmrc file, which defines the Ruby version and a gemset. Keeping things in a gemset allows safely running of gem binaries without version conflicts.

PostGIS

Jeremy (copiousfreetime) recommended using PostGIS from the outset to ensure that our database is location aware.

Here's the steps needed to get it going on OSX with homebrew:

brew install postgis
createdb safecast_development
createdb safecast_test
cd /usr/local/share/postgis && \
psql -d safecast_development -f postgis.sql -h localhost && \
psql -d safecast_development -f spatial_ref_sys.sql -h localhost && \
psql -d safecast_test -f postgis.sql -h localhost && \
psql -d safecast_test -f spatial_ref_sys.sql -h localhost && cd -

That installs the PostGIS functions into the development and test databases.

Bootstrapping the database

Rails's builtin command will do this:

rake db:create

Then bootstrap the schema:

rake db:schema:load

And finally the test database:

rake db:test:prepare

db:test:prepare

If you've been following along at home, everything probably went fine until that last line.

The problem is that db:test:prepare wipes out everything from PostGIS in the safecast_test database.

Katrina Owen proposed a solution to create a template in psql and then use that template in the db config. The db config part is already committed, but you still need to create the template on your local db.

psql -d postgres
CREATE DATABASE template_postgis WITH TEMPLATE=template1 ENCODING='UTF8';
\c template_postgis;
CREATE LANGUAGE plpgsql;
\i /usr/local/share/postgis/postgis.sql
\i /usr/local/share/postgis/spatial_ref_sys.sql
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
GRANT ALL ON geometry_columns TO PUBLIC;
GRANT ALL ON spatial_ref_sys TO PUBLIC;

So far, this seems to work.

Tests

All tests for this app use rspec, specifically rspec 2. The app has been configured to use spork for pre-loading the Rails environment and running tests in a forked process. The process for running the tests is:

spork
rspec spec

If you are offline, you can set the environment variable CONNECTION_STATUS to offline, eg:

CONNECTION_STATUS=offline spork

You can also run an individual test this way:

rspec spec/integration/api/users_spec.rb

References

Backbone Validations https://github.com/n-time/backbone.validations Rails + PostGIS http://lassebunk.dk/2011/09/10/creating-a-location-aware-website-using-ruby-on-rails-and-postgis/

API Docs

The API docs are written in markdown and live in the /app/views/api/docs/markdown directory. How-to's live in the root markdown directory, while each resource's documentation lives in the markdown/resources directory. If you update a resource or change the behavior of the API, please make sure to update the corresponding documentation.

Cron

The measurements table is output nightly to CSV, see script/dump_measurements ... this needs to be kept in sync with the queryable CSV export via the API endpoint at /api/measurements.csv

teamdata's People

Contributors

paulca avatar eoin avatar tonydevincenzi avatar yokolet avatar

Watchers

Sławek Maderak avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.