Skip to content
Snippets Groups Projects
Commit 3bdaf8c3 authored by Kenny Gao's avatar Kenny Gao
Browse files

Created browserify module packages

Each module is related to one flux action
Easier to manage and easier to trace, for
each module has just one purpose, and if that purpose fails
only one module needs to change
parent 64104a7f
Branches
No related tags found
No related merge requests found
Showing
with 712 additions and 678 deletions
api2/.DS_Store 100644 → 100755
No preview for this file type
api2/Util.py 100644 → 100755
aoss_translation = {
't': 'air_temp',
'rh': 'rh',
'rh': 'rel_hum',
'td':'dewpoint',
'accum_precip':'accum_precip',
'p': 'pressure',
......@@ -9,33 +9,34 @@ aoss_translation = {
}
buoy_translation = {
't': 'air_temp',
'rh': 'rel_hum',
'wt_1': 'water_temp_1',
'wt_2': 'water_temp_2',
'wt_3': 'water_temp_3',
'wt_4': 'water_temp_4',
'wt_5': 'water_temp_5',
'wt_6': 'water_temp_6',
'wt_7': 'water_temp_7',
'wt_8': 'water_temp_8',
'wt_9': 'water_temp_9',
'wt_10': 'water_temp_10',
'wt_11': 'water_temp_11',
'wt_12': 'water_temp_12',
'wt_13': 'water_temp_13',
'wt_14': 'water_temp_14',
'wt_15': 'water_temp_15',
'wt_16': 'water_temp_16',
'wt_17': 'water_temp_17',
'wt_18': 'water_temp_18',
'wt_19': 'water_temp_19',
'wt_20': 'water_temp_20',
'wt_21': 'water_temp_21',
'wt_22': 'water_temp_22',
'wt_23': 'water_temp_23',
'do_ppm': 'doptoppm',
'do_sat': 'doptosat',
'chlor': 'chlorophyll',
'pc': 'phycocyanin'
}
\ No newline at end of file
't': 'air_temp',
'td': 'dewpoint',
'rh': 'rel_hum',
'wt_1': 'water_temp_1',
'wt_2': 'water_temp_2',
'wt_3': 'water_temp_3',
'wt_4': 'water_temp_4',
'wt_5': 'water_temp_5',
'wt_6': 'water_temp_6',
'wt_7': 'water_temp_7',
'wt_8': 'water_temp_8',
'wt_9': 'water_temp_9',
'wt_10': 'water_temp_10',
'wt_11': 'water_temp_11',
'wt_12': 'water_temp_12',
'wt_13': 'water_temp_13',
'wt_14': 'water_temp_14',
'wt_15': 'water_temp_15',
'wt_16': 'water_temp_16',
'wt_17': 'water_temp_17',
'wt_18': 'water_temp_18',
'wt_19': 'water_temp_19',
'wt_20': 'water_temp_20',
'wt_21': 'water_temp_21',
'wt_22': 'water_temp_22',
'wt_23': 'water_temp_23',
'do_ppm': 'doptoppm',
'do_sat': 'doptosat',
'chlor': 'chlorophyll',
'pc': 'phycocyanin'
}
No preview for this file type
File mode changed from 100644 to 100755
No preview for this file type
No preview for this file type
from flask import Flask, render_template, request, jsonify, Response
import ast
from flask_json import FlaskJSON, as_json_p
from flask_socketio import SocketIO, send, emit
import requests
from xml.dom.minidom import Document
from datetime import datetime as dt
from datetime import timedelta as td
import time
from queryInflux import query
from io import StringIO
import numpy as np
import pandas as pd
import modifyData
#create application
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
json = FlaskJSON(app)
@app.route('/')
#creates index page
def index():
return render_template('test.html')
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@app.errorhandler(500)
def internal_server(e):
return render_template('500.html'), 500
@app.route('/data/<fmt>')
def getData(fmt):
#print(fmt)
beginTimes = request.args.get('begin')
endTimes = request.args.get('end')
sites = request.args.get('site')
insts = request.args.get('inst')
symbols = request.args.get('symbols')
intervals = request.args.get('interval')
seps = request.args.get('sep')
callbacks = request.args.get('callback')
if(not inst or not site or not symbols):
#print("here")
return render_template('500.html'), 500
inst = ast.literal_eval(inst)
print(inst)
#site = siteHandler(site)
#inst = instHandler(inst)
#symbols = symbols.split(':')
#if(not interval):
# interval = 'value_1m'
#else:
# interval = handleInterval(interval)
# if(interval == -1):
# return render_template('500.html'), 500
#symbols = symbolsHandler(symbols)
#if(not sep):
# sep = ','
# print(begin)
# print(end)
# print(site)
# print(inst)
#print(symbols)
#print(interval)
#print(sep)
#print(callback)
#result = query(site, inst, symbols, begin, end, interval)
#frame = handleResult(result, symbols, interval, sep)
#if(fmt == 'ascii'):
# output = asciiReturn(frame, sep, symbols)
# return output.getvalue()
#elif(fmt == 'json'):
# return jsonify(**jsonReturn(frame, symbols))
#elif(fmt == 'jsonp'):
# return jsonpReturn(frame, symbols)
#elif(fmt == 'xml'):
# xmlString = xmlReturn(site, frame, symbols, sep)
# return Response(xmlString, mimetype='text/xml')
#else:
# return render_template('400.html', format=fmt), 400
if __name__ == '__main__':
app.debug = True
app.run('0.0.0.0')
......@@ -356,7 +356,10 @@ def handleResult(result, symbols, interval, sep, spd, wDir):
speed[row] = round(math.sqrt(wEast[row]*wEast[row] + wNorth[row]*wNorth[row]),4)
if wDir:
direction[row] = round(math.atan(wNorth[row]/wEast[row]) * 180 / math.pi,1)
rads = math.atan2(wNorth[row],wEast[row])
direction[row] = round(math.degrees(rads), 1)
if(direction[row] < 0):
direction[row] = 360 + direction[row]
......@@ -508,4 +511,4 @@ def combineAscii(siteList, allData, sep):
returnString.write('<br/>')
return returnString.getvalue()
\ No newline at end of file
return returnString.getvalue()
File mode changed from 100644 to 100755
When relhumidity is entered, here's the hardcoded values, yo
look up key word hardcoded
\ No newline at end of file
api2/server.py 100644 → 100755
......@@ -27,7 +27,7 @@ def index():
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
return render_template('404.html'), 404
@app.errorhandler(500)
def internal_server(e):
......@@ -154,15 +154,8 @@ def getData(fmt):
else:
return render_template('400.html'), 400
@app.route('/tower/meteorogram')
def tower_meteorogram():
return render_template('tower_meteorogram.html')
#@app.route('/buoy/meteorogram')
#def buoy_meteorogram():
# return render_template('buoy_meteorogram.html')
if __name__ == '__main__':
app.debug = True
app.run('0.0.0.0')
app.debug = False
app.run('0.0.0.0', threaded=True)
......@@ -63,8 +63,6 @@ function getHeights(graphs)
//get graph positions from local storage
var graphs = JSON.parse(localStorage.getItem("buoy_numberOfGraphs"));
console.log('graphs', graphs);
//maps positions to their heights
var heightsValues = {'temp': 0.1,
'rh': 0.1,
......@@ -99,8 +97,6 @@ function getHeights(graphs)
}
}
console.log('heights', heights);
//return mapping of variable names to heights
return heights;
}
......@@ -403,7 +399,7 @@ function updateColorBar()
var updateStyle = {};
}
Plotly.restyle(plotDiv, updateStyle, [6]);
Plotly.restyle(plotDiv, updateStyle, [7]);
}
}
......@@ -456,7 +452,6 @@ function updateAxes(axes, showFlag, varName, numberAbove, title, id, pos)
//get heights
var heights = getHeights();
console.log('heights', heights);
var updateLay = new Object();
......@@ -479,17 +474,16 @@ function updateAxes(axes, showFlag, varName, numberAbove, title, id, pos)
showBool = true;
}
updateLay[axes[axis] + '.showgrid'] = showBool;
if(axes[axis].substring(0,1) == 'y')
{
if(!(showFlag == 1 && varName == 'temp'))
if(!(showFlag == 1 && (varName == 'temp' || varName == 'wD')))
{
updateLay[axes[axis] + '.title'] = title;
}
updateLay[axes[axis] + '.showticklabels'] = showBool;
updateLay[axes[axis] + '.zeroline'] = showBool;
updateLay[axes[axis] + '.showgrid'] = showBool;
}
}
......@@ -500,6 +494,12 @@ function updateAxes(axes, showFlag, varName, numberAbove, title, id, pos)
updateLay['yaxis2.title'] = "Temp (Deg C)";
}
if(showFlag == 1 && varName == 'wD')
{
updateLay['yaxis5.title'] = "Wind Direction (Deg)";
updateLay['yaxis9.title'] = "Wind Direction";
}
//find last graph showing
for(var key in yAxes)
{
......@@ -515,8 +515,6 @@ function updateAxes(axes, showFlag, varName, numberAbove, title, id, pos)
visible: showBool
};
console.log('updateLay', updateLay);
//update div
Plotly.relayout(plotDiv, updateLay);
Plotly.restyle(plotDiv, updateTrace, pos);
......@@ -565,8 +563,6 @@ function updateAxes(axes, showFlag, varName, numberAbove, title, id, pos)
newFunction += numberAbove.toString() + ", \"" + newTitle + "\", ";
newFunction += "\"" + id + "\", " + "[" + pos.toString() + "])";
console.log('newFunction', newFunction);
//change click functionality
var box = document.getElementById(id);
box.setAttribute("onclick", newFunction);
......
This diff is collapsed.
......@@ -6,15 +6,15 @@
*/
function cN(value)
{
if(value == -99999)
{
return null;
}
else
{
return value;
}
if(value == -99999)
{
return null;
}
else
{
return value;
}
}
/**
......@@ -30,74 +30,159 @@ function cN(value)
function updateLocal(update)
{
var date = update.stamps[0];
var symbols = update.symbols;
var date = update.stamps[0];
date = date.replace("T", " ");
date = date.replace("Z", "");
//map indices and data
indices = [0,1,2,5,6,3,4],
data = [];
var data = update.data;
//for each elt in update.data[0]
for(var i = 0; i < 7; i++)
{
//update data
if(i == 0 || i == 1)
{
data.push((update.data[0][i] * 9 / 5) + 32);
}
else
{
data.push(update.data[0][indices[i]]);
}
}
updateData(date, data);
var allData = new Array();
}
//get symbols
for (var i = 0; i < symbols.length; i++)
{
if(symbols[i].substring(0,5) != 'water')
{
allData[symbols[i]] = [];
}
}
allData['water'] = [];
//put data based on key:array of values
for(var dataItr = 0; dataItr < data.length; dataItr++)
{
inData = data[dataItr];
for(inDataItr = 0; inDataItr < inData.length; inDataItr++)
{
value = inData[inDataItr];
if(symbols[inDataItr].substring(0,5) != 'water')
{
symbol = symbols[inDataItr];
allData[symbol].push(value);
}
}
}
for(var symbolItr = 0; symbolItr < symbols.length; symbolItr++)
{
if(symbols[symbolItr].substring(0,5) == 'water')
{
var row = new Array();
for(var dataItr = 0; dataItr < data.length; dataItr++)
{
row.push(data[dataItr][symbolItr]);
}
allData['water'].push(row);
}
}
//convert air data from deg C to deg F
for(var i = 0; i < allData['air_temp'].length; i++)
{
airVal = allData['air_temp'][i];
//function updateData(date, temp, DP, P, WS, WD, AP, SF)
newVal = (airVal * 9 / 5) + 32;
allData['air_temp'][i] = newVal;
}
//convert dew point from deg C to deg F
for(var i = 0; i < allData['air_temp'].length; i++)
{
dewVal = allData['dewpoint'][i];
newVal = (dewVal * 9 / 5) + 32;
allData['dewpoint'][i] = newVal;
}
updateData(date, allData);
}
/**
* The purpose of this method is to update the graphDiv's data property
* The purpose of this method is to get an array with data corresponding to graph positions
*
* @param data - array of data values corresponding to their positions in the graph
* @param allData - symbol with array of values
* @param date - date stamp for update
* no returns
*/
function updateData(date, data)
function updateData(date, allData)
{
var graphDiv = document.getElementById('graph');
//shift and push date
graphDiv.data[0]['x'].push(date);
graphDiv.data[0]['x'].shift();
for(var i = 0; i < 7; i++)
{
//push and shift
graphDiv.data[i]['y'].push(data[i]);
graphDiv.data[i]['y'].shift();
}
//map indices and data
var indices = ['air_temp', 'dewpoint', 'rel_hum', 'wind_speed', 'wind_direction', 'chlorophyll', 'phycocyanin', 'water'],
data = [];
//for each elt in update.data[0]
for(var i = 0; i < 7; i++)
{
var key = indices[i];
var getElt = allData[key];
data.push(getElt[0]);
}
data.push(allData[indices[6]]);
updateGraphData(date, data);
}
/**
* The purpose of this method is to update the graph based on the graph div
* The purpose of this method is to update the graphDiv's data property
*
* no parameters
* @param data - array of data values corresponding to their positions in the graph
* @param date - date stamp for update
* no returns
*/
function updateGraphData(date, data)
{
var graphDiv = document.getElementById('graph');
//shift and push date
graphDiv.data[0]['x'].push(date);
graphDiv.data[0]['x'].shift();
for(var i = 0; i < 7; i++)
{
//push and shift
graphDiv.data[i]['y'].push(data[i]);
graphDiv.data[i]['y'].shift();
}
for(var i = 0; i < graphDiv.data[7]['z']; i++)
{
graphDiv.data[7]['z'][i].push(data[7][i]);
graphDiv.data[7]['z'][i].shift();
}
}
/**
* * The purpose of this method is to update the graph based on the graph div
* *
* * no parameters
* * no returns
* */
function updateGraph()
{
var start = new Date();
graphDiv = document.getElementById('graph');
var start = new Date();
graphDiv = document.getElementById('graph');
//redraw graph
Plotly.redraw(graphDiv);
var end = new Date();
};
\ No newline at end of file
Plotly.redraw(graphDiv);
var end = new Date();
}
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File deleted
File deleted
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment