-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
103 lines (77 loc) · 3.43 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from flask import Flask, jsonify, render_template, request, session
import os
import pandas as pd
import helpers
app = Flask(__name__)
app.secret_key = os.urandom(24)
results = helpers.load_data("csv/ahs_air_output_saved.csv")
current_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(current_dir)
# "cd ~/1_Programming/Energize_Andover/Assignments/4_Assignment/ ;
@app.route("/", methods={"GET"})
def index():
message = "Please wait for data"
return render_template("index.html")
@app.route("/update_all", methods={"GET"})
def update(): # sends JSON containing the updated data
global results
print("Updating")
#os.system('python3 ahs_air.py -h 10.12.4.98 -p 8000 ; wait')
results = helpers.load_data("csv/ahs_air_output.csv")
# save the temporary values into permanent storage
os.system('cp ahs_air_output.csv ahs_air_output_saved.csv ; wait')
return jsonify(results)
@app.route("/load_saved_data", methods={"GET"})
def load_saved_data(): # sends JSON containing saved data
global results
results = helpers.load_data("csv/ahs_air_output_saved.csv")
print("data to be sent: ")
print(results)
json = jsonify(results)
return json
@app.route("/update_area", methods={"GET"})
def update_area():
os.system("pgrep python3 > process_id.txt")
file = open("process_id.txt", 'r')
process_id = file.read()
print(process_id)
file.close()
if process_id != "":
# kill any other queries, there can be only one
os.system("kill -9 " + str(process_id))
wing = request.args.get("wing")
floor = request.args.get("floor")
#os.system('python3 query_specific.py -h 10.12.4.98 -p 8000 -w ' + wing + ' -f ' + floor + ' ; wait')
global results
area_results = helpers.load_data("csv/ahs_air_specific_output.csv")
results = helpers.update_data(results, area_results, ord(wing) - ord('A'), int(floor))
return jsonify(results)
@app.route("/update_floor", methods={"GET"})
def update_floor():
global results
os.system("pgrep python3 > process_id.txt")
file = open("process_id.txt", 'r')
process_id = file.read()
print(process_id)
file.close()
if process_id != "":
# kill any other queries, there can be only one
os.system("kill -9 " + str(process_id))
floor = request.args.get("floor")
os.system('python3 query_specific.py -h 10.12.4.98 -p 8000 -w A -f ' + floor + ' ; wait')
area_results = helpers.load_data("csv/ahs_air_specific_output.csv")
results = helpers.update_data(results, area_results, ord('A') - ord('A'), int(floor))
print("A", results)
os.system('python3 query_specific.py -h 10.12.4.98 -p 8000 -w B -f ' + floor + ' ; wait')
area_results = helpers.load_data("csv/ahs_air_specific_output.csv")
results = helpers.update_data(results, area_results, ord('B') - ord('A'), int(floor))
print("B", results)
os.system('python3 query_specific.py -h 10.12.4.98 -p 8000 -w C -f ' + floor + ' ; wait')
area_results = helpers.load_data("csv/ahs_air_specific_output.csv")
results = helpers.update_data(results, area_results, ord('C') - ord('A'), int(floor))
print("C", results)
os.system('python3 query_specific.py -h 10.12.4.98 -p 8000 -w D -f ' + floor + ' ; wait')
area_results = helpers.load_data("csv/ahs_air_specific_output.csv")
results = helpers.update_data(results, area_results, ord('D') - ord('A'), int(floor))
print("D", results)
return jsonify(results)