Skip to content
Snippets Groups Projects
Commit 215b72fb authored by Wortman, Elliot (UG - Comp Sci & Elec Eng)'s avatar Wortman, Elliot (UG - Comp Sci & Elec Eng)
Browse files

Graph data from `/past-values` endpoint

parent 873731fa
No related branches found
No related tags found
2 merge requests!5Replace Vue3 template site with NanoPatch UI & API,!4Modify passing x-axis-data as refering to function was causing errors in production build
...@@ -15,6 +15,20 @@ def values(): ...@@ -15,6 +15,20 @@ def values():
values = [{"N": 10}, {"P": 11}, {"K": 12}, {"T": 5}, {"H": 6}, {"M": 7}] values = [{"N": 10}, {"P": 11}, {"K": 12}, {"T": 5}, {"H": 6}, {"M": 7}]
return jsonify(values) return jsonify(values)
@app.route("/past-values")
def pastValues():
past_values = {"npkData": {
"nitrogen": [10, 22, 15, 18, 25, 30, 35],
"phosphorus": [5, 8, 10, 12, 20, 22, 25],
"potassium": [8, 12, 13, 17, 23, 28, 33]
},
"thmData": {
"temperature": [4, 15, 16, 18, 20, 10, 12],
"humidity": [25, 12, 2, 22, 19, 16, 25],
"moisture": [8, 12, 13, 33, 23, 28, 10]
}}
return jsonify(past_values)
@app.route('/favicon.ico') @app.route('/favicon.ico')
def favicon(): def favicon():
......
...@@ -3,6 +3,7 @@ import ValueTabs from "./components/ValueTabs.vue"; ...@@ -3,6 +3,7 @@ import ValueTabs from "./components/ValueTabs.vue";
</script> </script>
<script> <script>
import axios from "axios"
import MultiLineChart from './components/MultiLineChart.vue'; import MultiLineChart from './components/MultiLineChart.vue';
import MultiAxisChart from './components/MultiAxisChart.vue'; import MultiAxisChart from './components/MultiAxisChart.vue';
...@@ -11,7 +12,18 @@ export default { ...@@ -11,7 +12,18 @@ export default {
MultiLineChart, MultiLineChart,
MultiAxisChart MultiAxisChart
}, },
mounted() {
this.getPastValues();
},
methods: { methods: {
getPastValues() {
axios
.get('http://127.0.0.1:5000/past-values')
.then((response) => {
this.npkData = response.data.npkData
this.thmData = response.data.thmData
})
},
getPastSevenDays() { getPastSevenDays() {
const dates = []; const dates = [];
for (let i = 6; i >= 0; i--) { for (let i = 6; i >= 0; i--) {
...@@ -25,16 +37,8 @@ export default { ...@@ -25,16 +37,8 @@ export default {
}, },
data() { data() {
return { return {
npkData: { npkData: null,
nitrogen: [10, 22, 15, 18, 25, 30, 35], thmData: null
phosphorus: [5, 8, 10, 12, 20, 22, 25],
potassium: [8, 12, 13, 17, 23, 28, 33]
},
thmData: {
temperature: [4, 15, 16, 18, 20, 10, 12],
humidity: [25, 12, 2, 22, 19, 16, 25],
moisture: [8, 12, 13, 33, 23, 28, 10]
}
} }
} }
} }
...@@ -51,8 +55,8 @@ export default { ...@@ -51,8 +55,8 @@ export default {
</div> </div>
</div> </div>
<div class="bottom-section"> <div class="bottom-section">
<MultiLineChart :chart-data="npkData" :x-axis-data=this.getPastSevenDays() /> <MultiLineChart v-if="npkData" :chart-data="npkData" :x-axis-data=this.getPastSevenDays() />
<MultiAxisChart :chart-data="thmData" :x-axis-data=this.getPastSevenDays() /> <MultiAxisChart v-if="thmData" :chart-data="thmData" :x-axis-data=this.getPastSevenDays() />
</div> </div>
</div> </div>
</template> </template>
......
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