Misc cleanup

This commit is contained in:
Matthew Dillon 2015-09-02 18:21:57 -07:00
parent b394924aa8
commit b4ab8cbd1e
11 changed files with 85 additions and 80 deletions

View file

@ -1,5 +1,6 @@
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from config import config
@ -17,4 +18,3 @@ def create_app(config_name):
app.register_blueprint(main_blueprint)
return app

View file

@ -1,7 +1,7 @@
from flask import Blueprint
main = Blueprint('main', __name__)
main = Blueprint('main', __name__, template_folder='templates')
from . import views

View file

@ -2,9 +2,10 @@ from flask_wtf import Form
from wtforms import IntegerField
from wtforms.validators import NumberRange, Required
from wtforms.ext.sqlalchemy.fields import QuerySelectField
from app.models import Community, Dataset, Temperature
from sqlalchemy import func
from .models import Community, Dataset, Temperature
class AKIYearField(IntegerField):
def pre_validate(self, form):

View file

@ -1,4 +1,4 @@
from . import db
from app import db
from sqlalchemy.ext.hybrid import hybrid_property

View file

@ -14,7 +14,7 @@
</script>
<div class="container" style="max-width:90%">
<div class="page-header">
<h1>{{title}}<br><small>alaska climate data</small></h1>
<h1>{{ config['TITLE'] }}<br><small>alaska climate data</small></h1>
</div>
{% block content %}{% endblock %}
<hr>
@ -23,7 +23,7 @@
<p class="text-muted credit">
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/80x15.png" /></a> This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.
<br>
<small>Created by <a href="mailto:mrdillon@alaska.edu">Matthew Dillon</a>, 2015.</small>
<small>Created by <a href="mailto:mrdillon@alaska.edu">Matthew Dillon</a>, {{ config['COPYRIGHT_YEAR'] }}.</small>
</p>
</div>
</div>

View file

@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "main/base.html" %}
{% block content %}
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
@ -48,10 +48,8 @@
</tr>
{% endfor %}
</tbody>
</table>
<script>
var map = L.map('map').setView([{{ lat }}, {{ lon }}], 5);
L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg', {

View file

@ -1,5 +1,5 @@
{% extends "base.html" %}
{% from "_formhelpers.html" import render_field %}
{% extends "main/base.html" %}
{% from "main/_formhelpers.html" import render_field %}
{% block content %}
<p class="lead" align="justify">
@ -46,7 +46,7 @@
<div class="col-md-12">
<div class="form-group col-md-4">
<input type="submit" name="submit" class="btn btn-primary form-control"
value="Get Temperatures" >
value="Get Temperatures" />
</div>
<div class="form-group col-md-4">
<input type="button" name="reset" class="btn btn-danger form-control"
@ -112,11 +112,6 @@
</td>
</tr>
{% endif %}
{#
<tr>
<td colspan="9">&nbsp;</td>
</tr>
#}
<tr class="active">
<td colspan="9" align="center">
Saved Searches

View file

@ -1,6 +1,6 @@
import numpy
from app.models import Temperature, Dataset
from .models import Temperature, Dataset
def getTemps(datasets, community_id, minyear, maxyear):

View file

@ -1,11 +1,12 @@
from numpy import arange, hstack
from flask import session, render_template, request, redirect, current_app
from flask import session, render_template, request, redirect, url_for
from . import main
from .forms import AKIForm
from .utils import getTemps, avg_air_temp, ann_air_indices, avg_air_indices, des_air_indices
from app.models import Community, Dataset, Temperature
from .utils import getTemps, avg_air_temp, ann_air_indices, \
avg_air_indices, des_air_indices
from .models import Community, Dataset
@main.route('/', methods=['GET'])
@ -21,24 +22,27 @@ def index():
if all(key in session for key in ('minyear', 'maxyear', 'datasets')):
community = Community.query.get_or_404(community_id)
# TODO: clean this up
session['community_data'] = dict()
session['community_data']['id'] = community_id
session['community_data']['name'] = community.name
session['community_data']['latitude'] = round(community.latitude, 5)
session['community_data']['longitude'] = round(community.longitude, 5)
session['community_data'] = {
'id': community_id,
'name': community.name,
'latitude': round(community.latitude, 5),
'longitude': round(community.longitude, 5),
}
session['ds_name'] = Dataset.query. \
with_entities(Dataset.modelname, Dataset.scenario). \
filter_by(id=session['datasets']).all()
temps_arr = getTemps(session['datasets'], community_id, session['minyear'], session['maxyear'])
temps_arr = getTemps(session['datasets'],
community_id,
session['minyear'],
session['maxyear'])
session['avg_temp'] = avg_air_temp(temps_arr)
indices = ann_air_indices(temps_arr)
session['avg_indices'] = avg_air_indices(indices)
session['des_indices'] = des_air_indices(indices)
return render_template("index.html", form=form)
return render_template("main/index.html", form=form)
@main.route('/', methods=['POST'])
@ -52,20 +56,20 @@ def index_submit():
session['maxyear'] = session['minyear']
session['datasets'] = request.form['model']
return redirect('/')
return redirect(url_for('main.index'))
else:
return render_template("index.html", form=form)
return render_template("main/index.html", form=form)
@main.route('/datatypes')
def datatypes():
return render_template("datatypes.html")
return render_template("main/datatypes.html")
@main.route('/reset')
def reset():
session.clear()
return redirect('/')
return redirect(url_for('main.index'))
@main.route('/details')
@ -75,9 +79,10 @@ def details():
minyear = request.args.get('minyear', '')
maxyear = request.args.get('maxyear', '')
temps = getTemps(datasets, community_id, minyear, maxyear)
years = arange(int(minyear), int(maxyear)+1).reshape(int(maxyear)-int(minyear) + 1, 1)
years = arange(int(minyear),
int(maxyear)+1).reshape(int(maxyear)-int(minyear) + 1, 1)
temps = hstack((years, temps))
return render_template("details.html",
return render_template("main/details.html",
lat=request.args.get('lat', ''),
lon=request.args.get('lon', ''),
community_name=request.args.get('name', ''),
@ -87,28 +92,30 @@ def details():
@main.route('/save')
def save():
if 'save' in session:
i = len(session['save'])
i = str(len(session['save']))
save = session['save']
else:
save = dict()
i = 0
i = '0'
save[i] = {
'datasets': session['datasets'],
'ds_name': session['ds_name'],
'community_data': session['community_data'],
'minyear': session['minyear'],
'maxyear': session['maxyear'],
'avg_temp': session['avg_temp'],
'avg_indices': session['avg_indices'],
'des_indices': session['des_indices'],
}
save[i] = dict()
save[i]['datasets'] = session['datasets']
save[i]['ds_name'] = session['ds_name']
save[i]['community_data'] = session['community_data']
save[i]['minyear'] = session['minyear']
save[i]['maxyear'] = session['maxyear']
save[i]['avg_temp'] = session['avg_temp']
save[i]['avg_indices'] = session['avg_indices']
save[i]['des_indices'] = session['des_indices']
session.clear()
session['save'] = save
return redirect('/')
return redirect(url_for('main.index'))
@main.route('/delete')
def delete():
record = request.args.get('record', '')
session['save'].pop(record)
return redirect('/')
return redirect(url_for('main.index'))

View file

@ -1,11 +1,14 @@
import os
basedir = os.path.abspath(os.path.dirname(__file__))
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY')
APP_NAME = 'AKIndices'
APP_VERSION = '0.2.0'
TITLE = 'AKIndices'
COPYRIGHT_YEAR = 2015
CSRF_ENABLED = True
DEBUG = False
@staticmethod
def init_app(app):
@ -14,6 +17,7 @@ class Config:
class DevelopmentConfig(Config):
DEBUG = True
TITLE = 'AKIndices (test)'
SECRET_KEY = os.environ.get('SECRET_KEY') or 'top secret'
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'postgres://postgres@localhost/akindices'