Exemplo n.º 1
0
def coord(id):
    map = get_model().read_raw(id)
    if not map:
        map = get_model().read_tiff(id)

    if request.method == 'POST':
        data = request.form.to_dict(flat=True)

        points = map["refPoints"]

        if points:
            map["refPoints"].append(data)
        else:
            map["refPoints"] = [data]

        return redirect(url_for('.registration', id=map['id']))

    return render_template("coord.html", action="Edit", map=map)
Exemplo n.º 2
0
def list_tiff():
    token = request.args.get('page_token', None)
    if token:
        token = token.encode('utf-8')

    maps, next_page_token = get_model().list_tiff(cursor=token)

    return render_template(
        "list.html",
        maps=maps,
        next_page_token=next_page_token)
Exemplo n.º 3
0
def add_lazy_relation(cls, field, relation, operation):
    """
    Adds a lookup on ``cls`` when a related field is defined using a string,
    i.e.::

        class MyModel(Model):
            fk = OneOf("AnotherModel")

    This string can be:

        * RECURSIVE_RELATIONSHIP_CONSTANT (i.e. "self") to indicate a recursive
          relation.

        * The name of a model (i.e "AnotherModel") to indicate another model in
          the same app.

        * An app-label and model name (i.e. "someapp.AnotherModel") to indicate
          another model in a different app.

    If the other model hasn't yet been loaded -- almost a given if you're using
    lazy relationships -- then the relation won't be set up until the
    class_prepared signal fires at the end of model initialization.

    operation is the work that must be performed once the relation can be resolved.
    """
    # Check for recursive relations
    if relation == RECURSIVE_RELATIONSHIP_CONSTANT:
        app_label = cls.__module__ 
        model_name = cls.__name__       
    else:
        # Look for an "app.Model" relation
        try:
            app_label, model_name = relation.split(".")
        except ValueError:
            # If we can't split, assume a model in current app
            app_label = cls.__module__
            model_name = relation
        


    # Try to look up the related model, and if it's already loaded resolve the
    # string right away. If get_model returns None, it means that the related
    # model isn't loaded yet, so we need to pend the relation until the class
    # is prepared.
    from register import get_model
    model = get_model(relation)
    if model:
        operation(field, model, cls)
    else:
        key = (app_label, model_name)
        value = (cls, field, operation)
        pending_lookups.setdefault(key, []).append(value)
Exemplo n.º 4
0
def convert(id):
    map = get_model().read_raw(id)
    if not map:
        map = get_model().read_tiff(id)

    if request.method == 'POST':
        #inFile = Image.open(cStringIO.StringIO(urllib.urlopen(map['imageUrl']).read()))

        #gdalString = "gdal_translate " + str(inFile) + " " + "-of GTiff " + str(inFile) + ".tif"
        #os.system(gdalString)
        data = request.form.to_dict(flat=True)

        image_url = upload_image_file(request.files.get('image'))

        if image_url:
            data['imageUrl'] = image_url

        map = get_model().update_raw(data, id)

        return redirect(url_for('.view', id=map['id']))

    return render_template("reference.html", action="Edit", map=map)
Exemplo n.º 5
0
def add():
    if request.method == 'POST':
        data = request.form.to_dict(flat=True)

        # If an image was uploaded, update the data to point to the new image.
        # [START image_url]
        image_url = upload_image_file(request.files.get('image'))
        # [END image_url]

        # [START image_url2]
        if image_url:
            data["imageUrl"] = image_url
        # [END image_url2]

        map = get_model().create_raw(data)

        return redirect(url_for('.view', id=map['id']))

    return render_template("form.html", action="Add", map={})
Exemplo n.º 6
0
def model(monkeypatch, app):
    """This fixture provides a modified version of the app's model that tracks
    all created items and deletes them at the end of the test.

    Any tests that directly or indirectly interact with the database should use
    this to ensure that resources are properly cleaned up.

    Monkeypatch is provided by pytest and used to patch the model's create
    method.

    The app fixture is needed to provide the configuration and context needed
    to get the proper model object.
    """
    model = register.get_model()

    # Ensure no maps exist before running. This typically helps if tests
    # somehow left the database in a bad state.
    delete_all_maps(model)

    yield model

    # Delete all maps that we created during tests.
    delete_all_maps(model)
Exemplo n.º 7
0
def view(id):
    map = get_model().read_raw(id)
    if not map:
        map = get_model().read_tiff(id)

    return render_template("view.html", map=map)
Exemplo n.º 8
0
def delete(id):
    get_model().delete(id)
    return redirect(url_for('.list'))
Exemplo n.º 9
0
import numpy as np
import pandas as pd

from register import get_model

if __name__ == '__main__':

    model_config = {
        'model_id': 'random_forest',
        'n_estimators': 1000,
        'max_features': 'sqrt',
        'verbose': 1
    }

    model = get_model(**model_config)

    print('training {}'.format(model_config['model_id']))
    model.fit(x_train, y_train)

    print('R2 on training data {}'.format(model.score(x_train, y_train)))
    print('R2 on test data {}'.format(model.score(x_test, y_test)))