Skip to content
Snippets Groups Projects
Commit 988b0e1e authored by Peter Morstein's avatar Peter Morstein
Browse files

adjust annual mean

parent d702b630
No related branches found
No related tags found
No related merge requests found
...@@ -24,12 +24,21 @@ def determineAnnualMean(stationList): ...@@ -24,12 +24,21 @@ def determineAnnualMean(stationList):
if(isinstance(stationList,list)): if(isinstance(stationList,list)):
stationList = sqlToGeoPandas(stationList) stationList = sqlToGeoPandas(stationList)
print(stationList)
stationList = stationList.sort_index(axis=1, ascending=True) stationList = stationList.sort_index(axis=1, ascending=True)
stationList = stationList.filter(regex="^20|^19|^18") stationList = stationList.filter(regex="^20|^19|^18")
stationList.columns = stationList.columns.astype(int)
stationMean = stationList.mean() stationMean = stationList.mean()
return stationMean stationMean = stationMean.dropna(axis=0)
\ No newline at end of file
annualList = []
for i, val in stationMean.items():
annualItem = {}
annualItem['date'] = i
annualItem['value'] = val
annualList.append(annualItem)
return annualList
\ No newline at end of file
import psycopg2 import psycopg2
from flask import Flask, jsonify, request from flask import Flask, jsonify, request
from flask_cors import cross_origin
from psycopg2 import sql from psycopg2 import sql
import configparser import configparser
from GetAverageData import get_interpolation_data_for_point from GetAverageData import get_interpolation_data_for_point
...@@ -92,6 +93,7 @@ def getStandardQuery(): ...@@ -92,6 +93,7 @@ def getStandardQuery():
return query return query
@app.route('/annualMean', methods=['GET']) @app.route('/annualMean', methods=['GET'])
@cross_origin()
def annualMean(): def annualMean():
query = getStandardQuery() query = getStandardQuery()
...@@ -103,7 +105,7 @@ def annualMean(): ...@@ -103,7 +105,7 @@ def annualMean():
results = cursor.fetchall()[0][0] results = cursor.fetchall()[0][0]
return s2pTool.determineAnnualMean(results).to_json() return jsonify(s2pTool.determineAnnualMean(results))
return "{}" return "{}"
......
...@@ -5,7 +5,7 @@ import unittest ...@@ -5,7 +5,7 @@ import unittest
import pickle import pickle
class Testapi(unittest.TestCase): class Testapi(unittest.TestCase):
def testSqlToGeoPandas(self): def _testSqlToGeoPandas(self):
with open("./pickle/fetchall.pickle", "rb") as pickleFile: with open("./pickle/fetchall.pickle", "rb") as pickleFile:
sqlResult = pickle.load(pickleFile) sqlResult = pickle.load(pickleFile)
...@@ -23,24 +23,24 @@ class Testapi(unittest.TestCase): ...@@ -23,24 +23,24 @@ class Testapi(unittest.TestCase):
stationList = cut.sqlToGeoPandas(sqlResult) stationList = cut.sqlToGeoPandas(sqlResult)
annualMean = cut.determineAnnualMean(stationList) annualMean = cut.determineAnnualMean(stationList)
print(annualMean)
self.assertTrue(annualMean[len(annualMean)-10]['date']>=2000)
self.assertTrue(annualMean[len(annualMean)-10]['value']>=2)
self.assertEqual(annualMean["2000"].dtype, "float64") self.assertTrue(annualMean[len(annualMean)-5]['date']>=2000)
self.assertTrue(annualMean["2000"]>=2) self.assertTrue(annualMean[len(annualMean)-5]['value']>=2)
self.assertEqual(annualMean["1992"].dtype, "float64") def _testDetermineAnnualMeanWithList(self):
self.assertTrue(annualMean["1992"]>=2)
def testDetermineAnnualMeanWithList(self):
with open("./pickle/fetchall.pickle", "rb") as pickleFile: with open("./pickle/fetchall.pickle", "rb") as pickleFile:
stationList = pickle.load(pickleFile) stationList = pickle.load(pickleFile)
annualMean = cut.determineAnnualMean(stationList) annualMean = cut.determineAnnualMean(stationList)
self.assertEqual(annualMean["2000"].dtype, "float64") self.assertEqual(annualMean[2000].dtype, "float64")
self.assertTrue(annualMean["2000"]>=2) self.assertTrue(annualMean[2000]>=2)
self.assertEqual(annualMean["1992"].dtype, "float64") self.assertEqual(annualMean[1992].dtype, "float64")
self.assertTrue(annualMean["1992"]>=2) self.assertTrue(annualMean[1992]>=2)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
This diff is collapsed.
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"build": "parcel build --public-url . index.html" "build": "parcel build --public-url . index.html"
}, },
"dependencies": { "dependencies": {
"axios": "^0.21.4",
"colormap": "^2.3.2", "colormap": "^2.3.2",
"core-js": "^3.18.0", "core-js": "^3.18.0",
"d3": "^7.0.3", "d3": "^7.0.3",
......
...@@ -163,6 +163,7 @@ import {Vue, Ref, Component, Emit, Prop } from 'vue-property-decorator'; ...@@ -163,6 +163,7 @@ import {Vue, Ref, Component, Emit, Prop } from 'vue-property-decorator';
import MapProperties from './MapProperties'; import MapProperties from './MapProperties';
import { TemperatureSeries } from './StationLayer'; import { TemperatureSeries } from './StationLayer';
import TemperatureLegendChart from './TemperatureLegendChart'; import TemperatureLegendChart from './TemperatureLegendChart';
import axios from 'axios'
@Component({}) @Component({})
export default class Legend extends Vue{ export default class Legend extends Vue{
...@@ -181,7 +182,6 @@ export default class Legend extends Vue{ ...@@ -181,7 +182,6 @@ export default class Legend extends Vue{
console.log("Legend mounted"); console.log("Legend mounted");
let series: TemperatureSeries[] = new Array<TemperatureSeries>(); let series: TemperatureSeries[] = new Array<TemperatureSeries>();
series.push({date: 2005, value: 3}); series.push({date: 2005, value: 3});
series.push({date: 2006, value: 5}); series.push({date: 2006, value: 5});
series.push({date: 2007, value: 7}); series.push({date: 2007, value: 7});
...@@ -192,12 +192,24 @@ export default class Legend extends Vue{ ...@@ -192,12 +192,24 @@ export default class Legend extends Vue{
series.push({date: 2012, value: 7}); series.push({date: 2012, value: 7});
series.push({date: 2013, value: 4}); series.push({date: 2013, value: 4});
series.push({date: 2014, value: 9}); series.push({date: 2014, value: 9});
/* let tChart1 = new TemperatureLegendChart();
let tChart1 = new TemperatureLegendChart();
tChart1.render("legendTemperature1", series); tChart1.render("legendTemperature1", series);
let tChart2 = new TemperatureLegendChart(); let tChart2 = new TemperatureLegendChart();
tChart2.render("legendTemperature2", series); tChart2.render("legendTemperature2", series); */
axios.get("http://127.0.0.1:42000/annualMean", {
headers: {'Access-Control-Allow-Origin': '*'}
}).then(resp => {
let tChart1 = new TemperatureLegendChart();
tChart1.render("legendTemperature1", resp.data);
let tChart2 = new TemperatureLegendChart();
tChart2.render("legendTemperature2", resp.data);
});
} }
public layerChanged(layer: any):void{ public layerChanged(layer: any):void{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment