Taxonomy Module
===============

## Requirements

Make sure you have installed the following software (suggested versions are given):

- [Python 2.7.7](https://www.python.org/download/releases/2.7.7/)
- [pip](http://www.pip-installer.org/en/latest/)
- [elasticsearch](http://www.elasticsearch.org/overview/elkdownloads/)
- [PostgreSQL 9.1](http://www.postgresql.org/download/)

## Setup

### Virtualenv
Create a virtualenv and *activate* it
```console
pip install virtualenv
virtualenv env
source env/bin/activate
```

### Additional configuration (OS X)
Add paths to PostgreSQL installation and ElasticSearch folder into `~/.bash_profile`. For example (your paths may differ):
```console
PATH="$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin"
PATH="~/Documents/plutof/elasticsearch-1.1.0/bin:$PATH"
export PATH
```

Restart the terminal application for these changes to take effect. Activate the virtual environment as before.

### Database
Create a new PostgreSQL database `taxonomy` with username `taxonomy` and password `taxonomy`

### Install script
Start elasticsearch server
```console
elasticsearch
```

Run the install script
```console
make install
```

Add application superuser
```console
psql -U taxonomy
INSERT INTO auth_user (password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined) VALUES (md5('password'), NOW(), true, 'username', '', '', '', true, true, NOW());
\q
```

## Tests
For running all tests elasticsearch server needs to be running. Run tests with
```console
make test
```

## Server
Start Elasticsearch.
```console
elasticsearch
```

Run the development server
```console
make server
```

You can now access the server on http://localhost:7000
For using the browsable api you should log into the system with the following credentials:
    username: username
    password: password

## Creating search indexes ([Haystack](http://django-haystack.readthedocs.org/en/latest/toc.html))

1. For creating an index use ```./manage.py rebuild_index```

2. For updating existing index use ```./manage.py update_index```

POPULATING THE SYSTEM WITH RANDOM TAXA
--------------------------------------

For populating the system with random data, run

```console
python manage.py generate_simple 1 100
```

The given script puts additional 100 taxa into tree with id 1. It requires that you have the application started and elasticsearch running.

MEASURING PERFORMANCE OF AN ENDPOINT
------------------------------------

For measuring the response time of a GET request to `/api/taxonomy/taxon` in seconds, do
```console
curl -o /dev/null -s -w %{time_total}\\n -u username:password http://localhost:7000/api/taxonomy/taxon/
```
