Misc cleanup
This commit is contained in:
parent
b394924aa8
commit
b4ab8cbd1e
11 changed files with 85 additions and 80 deletions
|
@ -1,7 +1,7 @@
|
|||
from flask import Blueprint
|
||||
|
||||
|
||||
main = Blueprint('main', __name__)
|
||||
main = Blueprint('main', __name__, template_folder='templates')
|
||||
|
||||
|
||||
from . import views
|
||||
|
|
|
@ -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):
|
||||
|
|
52
app/main/models.py
Normal file
52
app/main/models.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
from app import db
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
|
||||
|
||||
class Community(db.Model):
|
||||
__tablename__ = 'communities'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(50), nullable=False, unique=True)
|
||||
northing = db.Column(db.Float, nullable=False)
|
||||
easting = db.Column(db.Float, nullable=False)
|
||||
latitude = db.Column(db.Float, nullable=False)
|
||||
longitude = db.Column(db.Float, nullable=False)
|
||||
temperatures = db.relationship('Temperature', backref='communities')
|
||||
|
||||
|
||||
class Dataset(db.Model):
|
||||
__tablename__ = 'datasets'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
datatype = db.Column(db.String(15), nullable=False)
|
||||
model = db.Column(db.String(15), nullable=False)
|
||||
modelname = db.Column(db.String(50), nullable=False)
|
||||
scenario = db.Column(db.String(15), nullable=False)
|
||||
resolution = db.Column(db.String(15), nullable=False)
|
||||
temperatures = db.relationship('Temperature', backref='datasets')
|
||||
|
||||
@hybrid_property
|
||||
def type(self):
|
||||
return self.datatype.lower().capitalize()
|
||||
|
||||
|
||||
class Temperature(db.Model):
|
||||
__tablename__ = 'temperatures'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
dataset_id = db.Column(db.Integer, db.ForeignKey('datasets.id'))
|
||||
community_id = db.Column(db.Integer, db.ForeignKey('communities.id'))
|
||||
year = db.Column(db.Integer, nullable=False)
|
||||
january = db.Column(db.Float, nullable=False)
|
||||
february = db.Column(db.Float, nullable=False)
|
||||
march = db.Column(db.Float, nullable=False)
|
||||
april = db.Column(db.Float, nullable=False)
|
||||
may = db.Column(db.Float, nullable=False)
|
||||
june = db.Column(db.Float, nullable=False)
|
||||
july = db.Column(db.Float, nullable=False)
|
||||
august = db.Column(db.Float, nullable=False)
|
||||
september = db.Column(db.Float, nullable=False)
|
||||
october = db.Column(db.Float, nullable=False)
|
||||
november = db.Column(db.Float, nullable=False)
|
||||
december = db.Column(db.Float, nullable=False)
|
||||
updated = db.Column(db.DateTime, nullable=True)
|
12
app/main/templates/main/_formhelpers.html
Normal file
12
app/main/templates/main/_formhelpers.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
{% macro render_field(field) %}
|
||||
{{ field(**kwargs)|safe }}
|
||||
{% if field.errors %}
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
{% for error in field.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
31
app/main/templates/main/base.html
Normal file
31
app/main/templates/main/base.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{{ config['TITLE'] }}</title>
|
||||
<link href="/static/css/bootstrap-readable.min.css" rel="stylesheet">
|
||||
<link href="/static/css/akindices.css" rel="stylesheet">
|
||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="/static/js/bootstrap.min.js"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
<script type=text/javascript>
|
||||
var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
|
||||
</script>
|
||||
<div class="container" style="max-width:90%">
|
||||
<div class="page-header">
|
||||
<h1>{{ config['TITLE'] }}<br><small>alaska climate data</small></h1>
|
||||
</div>
|
||||
{% block content %}{% endblock %}
|
||||
<hr>
|
||||
|
||||
<div id="footer">
|
||||
<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>, {{ config['COPYRIGHT_YEAR'] }}.</small>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
64
app/main/templates/main/details.html
Normal file
64
app/main/templates/main/details.html
Normal file
|
@ -0,0 +1,64 @@
|
|||
{% extends "main/base.html" %}
|
||||
{% block content %}
|
||||
|
||||
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
|
||||
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
|
||||
|
||||
<h2>{{ community_name }}</h4>
|
||||
|
||||
<div id="map" style="width: 500px; height: 300px"></div>
|
||||
<br>
|
||||
|
||||
<h3>Monthly Temperatures</h3>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-condensed table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Year<br> </th>
|
||||
<th>January<br>°C</th>
|
||||
<th>February<br>°C</th>
|
||||
<th>March<br>°C</th>
|
||||
<th>April<br>°C</th>
|
||||
<th>May<br>°C</th>
|
||||
<th>June<br>°C</th>
|
||||
<th>July<br>°C</th>
|
||||
<th>August<br>°C</th>
|
||||
<th>September<br>°C</th>
|
||||
<th>October<br>°C</th>
|
||||
<th>November<br>°C</th>
|
||||
<th>December<br>°C</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for temp in temps %}
|
||||
<tr>
|
||||
<td>{{ temp[0]|int }}</td>
|
||||
<td>{{ temp[1]|round(2) }}</td>
|
||||
<td>{{ temp[2]|round(2) }}</td>
|
||||
<td>{{ temp[3]|round(2) }}</td>
|
||||
<td>{{ temp[4]|round(2) }}</td>
|
||||
<td>{{ temp[5]|round(2) }}</td>
|
||||
<td>{{ temp[6]|round(2) }}</td>
|
||||
<td>{{ temp[7]|round(2) }}</td>
|
||||
<td>{{ temp[8]|round(2) }}</td>
|
||||
<td>{{ temp[9]|round(2) }}</td>
|
||||
<td>{{ temp[10]|round(2) }}</td>
|
||||
<td>{{ temp[11]|round(2) }}</td>
|
||||
<td>{{ temp[12]|round(2) }}</td>
|
||||
</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', {
|
||||
maxZoom: 18,
|
||||
attribution: '{{ community_name }}, AK'
|
||||
}).addTo(map);
|
||||
var marker_1 = L.marker([{{ lat }}, {{ lon }}]);
|
||||
marker_1.bindPopup("{{ community_name }}, AK<br>{{ lat }}° N, {{ lon }}° W");
|
||||
map.addLayer(marker_1)
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
225
app/main/templates/main/index.html
Normal file
225
app/main/templates/main/index.html
Normal file
|
@ -0,0 +1,225 @@
|
|||
{% extends "main/base.html" %}
|
||||
{% from "main/_formhelpers.html" import render_field %}
|
||||
{% block content %}
|
||||
|
||||
<p class="lead" align="justify">
|
||||
Air temperature data from over 400 communities, reduced to relevant engineering parameters
|
||||
(<a href="#info">Additional info</a>)
|
||||
</p>
|
||||
|
||||
<h3>Search</h3>
|
||||
|
||||
<form action="" method="post" role="form">
|
||||
{{ form.csrf_token }}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="communityinput">Community</label>
|
||||
{{ render_field(form.community, class='form-control', id='communityinput') }}
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="modelinput">Dataset</label>
|
||||
{{ render_field(form.model, class='form-control', id='modelinput') }}
|
||||
<small>Historical (1901-2009) or Projection (2001-2099)<br>
|
||||
<a href="{{ url_for('main.datatypes') }}" target="_blank">
|
||||
Learn more about the models and scenarios
|
||||
</a></small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="minyearinput">Start Year</label>
|
||||
{{ render_field(form.minyear, class='form-control', id='minyearinput') }}
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="maxyearinput">End Year</label>
|
||||
{{ render_field(form.maxyear, class='form-control', id='maxyearinput') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<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" />
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<input type="button" name="reset" class="btn btn-danger form-control"
|
||||
onclick="window.location.href='{{ url_for('main.reset') }}'"
|
||||
value="Clear All Data" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h3>Results</h3>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-condensed table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Community<br> </th>
|
||||
<th>Years<br> </th>
|
||||
<th>T<sub>avg</sub><br>°C</th>
|
||||
<th>ATI<br>°C-days</th>
|
||||
<th>AFI<br>°C-days</th>
|
||||
<th>DTI<br>°C-days</th>
|
||||
<th>DFI<br>°C-days</th>
|
||||
<th>Type<br> </th>
|
||||
<th width="50px">Add/<br>Remove</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="active">
|
||||
<td colspan="9" align="center">
|
||||
Current Search
|
||||
</td>
|
||||
</tr>
|
||||
{% if session['avg_temp'] %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('main.details', lat=session['community_data']['latitude'],
|
||||
lon=session['community_data']['longitude'],
|
||||
name=session['community_data']['name'],
|
||||
datasets=session['datasets'],
|
||||
community_id=session['community_data']['id'],
|
||||
minyear=session['minyear'],
|
||||
maxyear=session['maxyear']) }}"
|
||||
target="_blank">
|
||||
{{ session['community_data']['name'] }}<br>
|
||||
<small>{{ session['community_data']['latitude'] }}° N,
|
||||
{{ session['community_data']['longitude'] }}° W</small></a></td>
|
||||
<td>{{ session['minyear'] }} - {{ session['maxyear'] }}</td>
|
||||
<td>{{ session['avg_temp']|round(1) }}</td>
|
||||
<td>{{ session['avg_indices'][0] }}</td>
|
||||
<td>{{ session['avg_indices'][1] }}</td>
|
||||
<td>{{ session['des_indices'][0] }}</td>
|
||||
<td>{{ session['des_indices'][1] }}</td>
|
||||
<td>{{ session['ds_name'][0][0] }} ({{ session['ds_name'][0][1] }})</td>
|
||||
<td><button type="button" class="btn btn-success btn-sm"
|
||||
onclick="window.location.href='{{ url_for('main.save') }}'"
|
||||
title="Click to save this search">
|
||||
<span class="glyphicon glyphicon-plus-sign"></span>
|
||||
</button></td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="9" align="center">
|
||||
[no data]
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr class="active">
|
||||
<td colspan="9" align="center">
|
||||
Saved Searches
|
||||
</td>
|
||||
</tr>
|
||||
{% if session.save %}
|
||||
{% for key, value in session.save|dictsort %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('main.details', lat=value['community_data']['latitude'],
|
||||
lon=value['community_data']['longitude'],
|
||||
name=value['community_data']['name'],
|
||||
datasets=value['datasets'],
|
||||
community_id=value['community_data']['id'],
|
||||
minyear=value['minyear'],
|
||||
maxyear=value['maxyear']) }}"
|
||||
target="_blank">
|
||||
{{ value['community_data']['name'] }}<br>
|
||||
<small>{{ value['community_data']['latitude'] }}° N,
|
||||
{{ value['community_data']['longitude'] }}° W</small></a></td>
|
||||
<td>{{ value['minyear'] }} - {{ value['maxyear'] }}</td>
|
||||
<td>{{ value['avg_temp']|round(1) }}</td>
|
||||
<td>{{ value['avg_indices'][0] }}</td>
|
||||
<td>{{ value['avg_indices'][1] }}</td>
|
||||
<td>{{ value['des_indices'][0] }}</td>
|
||||
<td>{{ value['des_indices'][1] }}</td>
|
||||
<td>{{ value['ds_name'][0][0] }} ({{ value['ds_name'][0][1] }})</td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm"
|
||||
onclick="window.location.href='{{ url_for('main.delete', record=key) }}'"
|
||||
title="Click to delete this search">
|
||||
<span class="glyphicon glyphicon-trash"></span></button></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="9" align="center">
|
||||
[no data]
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
<strong>
|
||||
NOTE: The parameters calculated by AKIndices are based on average monthly temperatures,
|
||||
not average daily temperatures. As well, derived data is provided without any rounding or
|
||||
consideration for significant digits, allowing the user to decide what is appropriate for
|
||||
their analysis.
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<div align="justify">
|
||||
<a name="info"></a>
|
||||
<h3>Info</h3>
|
||||
<dl class="dl-horizontal">
|
||||
<dt>What</dt>
|
||||
<dd>AKIndices provides basic engineering climate parameters that are commonly used for engineering and
|
||||
site-development purposes. These parameters include:
|
||||
<ul>
|
||||
<li><strong>T<sub>avg</sub>:</strong> The average (arithmetic mean) air temperature, based on all of
|
||||
the monthly air temperatures for the specified range of years.
|
||||
</li>
|
||||
<li><strong>ATI:</strong> The average (arithmetic mean) annual thawing index. The thawing index is the
|
||||
total number of degree-days above the freezing point. The number displayed by AKIndices is the
|
||||
average of the annual indices for the specified range of years.
|
||||
</li>
|
||||
<li><strong>AFI:</strong> The average (arithmetic mean) annual freezing index. The freezing index is the
|
||||
total number of degree-days below the freezing point. The number displayed by AKIndices is the
|
||||
average of the annual indices for the specified range of years.
|
||||
</li>
|
||||
<li><strong>DTI:</strong> The design thawing index. The number displayed by AKIndices is the
|
||||
arithmetic mean of the three warmest thawing indices for the specified range of years. If less
|
||||
than three years are displayed, the DTI is listed as 'None.' Typically, the DTI is calculated
|
||||
over a 30-year or 10-year time span.
|
||||
</li>
|
||||
<li><strong>DFI:</strong> The design freezing index. The number displayed by AKIndices is the
|
||||
arithmetic mean of the three coolest freezing indices for the specified range of years. If less
|
||||
than three years are displayed, the DFI is listed as 'None.' Typically, the DFI is calculated
|
||||
over a 30-year or 10-year time span.
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
<dt>Why</dt>
|
||||
<dd>AKIndices provides quick and simple access to the massive amounts of data released by the SNAP
|
||||
group. It does not aim to replace, modify, or build on SNAP's work, but rather provide an alternative
|
||||
means for users to explore and understand the data.</dd>
|
||||
<dt>How</dt>
|
||||
<dd>AKIndices is built with <a href="http://www.python.org" target="_blank">python</a>. Check out
|
||||
<a href="http://github.com/thermokarst/AKExtract" target="_blank">AKExtract</a> and
|
||||
<a href="http://github.com/thermokarst/AKIndices" target="_blank">AKIndices</a> on GitHub for more info
|
||||
on how to install on your own machine, fork the project, or submit
|
||||
<a href="http://github.com/thermokarst/AKIndices/issues" target="_blank">bug reports.</a>
|
||||
In a nutshell, AKExtract takes a list of communities and their coordinates, as well as SNAP datasets,
|
||||
and extracts the air temperature data from the data point closest to a community's location. AKIndices
|
||||
is the front-end for interacting with that extracted data.
|
||||
</dd>
|
||||
<dt>Who</dt>
|
||||
<dd>This project is the work of <a href="mailto:mrdillon@alaska.edu">Matthew Dillon.</a>
|
||||
While this project would not exist without <a href="http://www.snap.uaf.edu" target="_blank">SNAP</a>,
|
||||
AKIndices is <em>not endorsed or supported by SNAP in any way.</em> Before utilizing the derived data
|
||||
from AKIndices make sure to take a look at SNAP's page to learn about the science
|
||||
and the methods behind their products.<br>
|
||||
</dd>
|
||||
</dl>
|
||||
<h4>This product is provided as-is, with no warranty express or implied. Use at your own risk.</h4>
|
||||
<h4>Commercial use disclaimer: It is the sole responsibility of the user to execute any agreements
|
||||
with SNAP <a href="http://www.snap.uaf.edu/people.php?topic=data#contact" target="_blank">regarding commercial
|
||||
use</a> of the SNAP data (potentially including the derived products found on this page).</h4>
|
||||
<h4>Question? Comment? Find a problem? <a href="mailto:mrdillon@alaska.edu">Email me</a>
|
||||
or <a href="http://github.com/thermokarst/AKIndices/issues" target="_blank">submit a bug report!</a></h4>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -1,22 +1,22 @@
|
|||
import numpy
|
||||
|
||||
from app.models import Temperature, Dataset
|
||||
from .models import Temperature, Dataset
|
||||
|
||||
|
||||
def getTemps(datasets, community_id, minyear, maxyear):
|
||||
temps = Temperature.query.join(Dataset). \
|
||||
filter(Dataset.id == Temperature.dataset_id,
|
||||
Dataset.id == datasets,
|
||||
Temperature.community_id == community_id,
|
||||
Temperature.year >= minyear,
|
||||
Temperature.year <= maxyear)
|
||||
filter(Dataset.id == Temperature.dataset_id,
|
||||
Dataset.id == datasets,
|
||||
Temperature.community_id == community_id,
|
||||
Temperature.year >= minyear,
|
||||
Temperature.year <= maxyear)
|
||||
|
||||
length = int(maxyear) - int(minyear)
|
||||
temps_arr = numpy.zeros((length+1, 12))
|
||||
|
||||
i = 0
|
||||
for t in temps.all():
|
||||
temps_arr[i,:] = [t.january, t.february, t.march,
|
||||
temps_arr[i, :] = [t.january, t.february, t.march,
|
||||
t.april, t.may, t.june,
|
||||
t.july, t.august, t.september,
|
||||
t.october, t.november, t.december]
|
||||
|
@ -58,8 +58,8 @@ def avg_air_indices(indices):
|
|||
|
||||
def des_air_indices(indices):
|
||||
if indices.shape[0] > 2:
|
||||
ati = numpy.sort(indices[:,0])
|
||||
afi = numpy.sort(indices[:,1])
|
||||
ati = numpy.sort(indices[:, 0])
|
||||
afi = numpy.sort(indices[:, 1])
|
||||
dti = (ati[-1] + ati[-2] + ati[-3]) / 3.0
|
||||
dfi = (afi[0] + afi[1] + afi[2]) / 3.0
|
||||
return (int(dti), int(dfi))
|
||||
|
|
|
@ -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,40 +79,43 @@ 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",
|
||||
lat=request.args.get('lat', ''),
|
||||
lon=request.args.get('lon', ''),
|
||||
community_name=request.args.get('name', ''),
|
||||
temps=temps)
|
||||
return render_template("main/details.html",
|
||||
lat=request.args.get('lat', ''),
|
||||
lon=request.args.get('lon', ''),
|
||||
community_name=request.args.get('name', ''),
|
||||
temps=temps)
|
||||
|
||||
|
||||
@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'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue