Skip to content

Commit

Permalink
Merge pull request #12 from fridiculous/feature/update_docs
Browse files Browse the repository at this point in the history
Add Instructions for Notebook Use
  • Loading branch information
fridiculous committed Dec 2, 2016
2 parents 1e8cafd + b03d084 commit bdd1797
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
19 changes: 15 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,32 @@ And you can view all the atributes on the evaluation result
result.y_predicted


Using with Notebook (or without django shell)
Using with Jupyter Notebook (or without a django app)
---------------------------------------------

In order to have access to the django db, you'll need to set up the environment variable to load up your django project. In ipython, you can set the environment variable ``DJANGO_SETTINGS_MODULE`` to ``your_project_name.settings`` like so::
Django-Estimators can run as a standalone django app.In order to have access to the django db, you'll need to set up the environment variable to load up your django project. In ipython, by default you can set the environment variable ``DJANGO_SETTINGS_MODULE`` to ``estimators.template_settings`` like so
::

import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_project_name.settings")
os.environ['DJANGO_SETTINGS_MODULE'] = "estimators.template_settings"
django.setup()

Now you can continue on as usual... ::
If you're creating a new database (by default it's ``db.sqlite3``), in python, you'll need to run
::

from django.core.management import call_command
call_command('migrate')


Now you can continue you as usual... ::

from estimators.models import Estimator


To use your own custom settings, make a copy of the ``estimators.template_settings`` and edit the fields. Like above, run ``os.environ['DJANGO_SETTINGS_MODULE'] = "custom_settings_file"`` before running ``django.setup()``.


Development Installation
------------------------

Expand Down
3 changes: 3 additions & 0 deletions estimators/models/datasets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models

from estimators import DATASET_DIR
from estimators.models.base import HashableFileMixin, HashableFileQuerySet


Expand All @@ -16,6 +17,8 @@ class DataSet(HashableFileMixin):

objects = DataSetQuerySet.as_manager()

DIRECTORY = DATASET_DIR

class Meta:
db_table = 'data_sets'

Expand Down
3 changes: 3 additions & 0 deletions estimators/models/estimators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.core.exceptions import ValidationError
from django.db import models

from estimators import ESTIMATOR_DIR
from estimators.models.base import HashableFileMixin, HashableFileQuerySet


Expand Down Expand Up @@ -40,6 +41,8 @@ class Estimator(HashableFileMixin):

objects = EstimatorQuerySet.as_manager()

DIRECTORY = ESTIMATOR_DIR

class Meta:
db_table = 'estimators'

Expand Down
26 changes: 26 additions & 0 deletions estimators/template_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
SECRET_KEY = 'template settings file'

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'estimators',
)

DATABASE_ENGINE = 'sqlite3',
DATABASES = {
'default': {
'NAME': 'db.sqlite3',
'ENGINE': 'django.db.backends.sqlite3',
},
}

MIDDLEWARE_CLASSES = []

MEDIA_ROOT = 'files'

ESTIMATOR_DIR = 'estimators/'
DATASET_DIR = 'datasets/'

DEBUG = True
4 changes: 2 additions & 2 deletions estimators/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Meta:
create_date = factory.LazyFunction(datetime.now)
object_hash = factory.LazyAttribute(lambda o: compute_hash(o.estimator))
object_file = DjangoFileField(
filename=lambda o: 'files/estimators/%s' % o.object_hash)
filename=lambda o: '%s/%s' % (Estimator.DIRECTORY, o.object_hash))


class DataSetFactory(DjangoModelFactory):
Expand All @@ -57,7 +57,7 @@ class Params:
create_date = factory.LazyFunction(datetime.now)
object_hash = factory.LazyAttribute(lambda o: compute_hash(o.data))
object_file = DjangoFileField(
filename=lambda o: 'files/datasets/%s' % o.object_hash)
filename=lambda o: '%s/%s' % (DataSet.DIRECTORY, o.object_hash))


class EvaluationResultFactory(DjangoModelFactory):
Expand Down
1 change: 1 addition & 0 deletions estimators/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
MIDDLEWARE_CLASSES = []

import tempfile

MEDIA_ROOT = tempfile.gettempdir()

DEBUG = True

0 comments on commit bdd1797

Please sign in to comment.