views.py
3.5 KB
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
import json
import threading
import app.api.thread_func as thread_func
import app.api.stack_func as stack_func
from . import api
from flask import request, jsonify
from app.config import HttpRequestMethod
from .response import Response, DeviceDataHeader
from flask import current_app
@api.route('/admin/add', methods=["GET", "POST"])
def add():
if request.method == "POST":
a = request.json.get("a")
b = request.json.get("b")
resp = Response(code=200, msg='ok', success=True)
print(resp.json)
return jsonify({"code": 200, "data": float(a)+float(b)})
else:
a = request.args.get("a")
b = request.args.get("b")
return jsonify({"code": 200, "data": float(a)+float(b)})
@api.route('/admin/push_data', methods=['GET', 'POST'])
def push_data():
if request.method == HttpRequestMethod.GET:
pass
elif request.method == HttpRequestMethod.POST:
json_data = request.json
_type = json_data["type"]
_cmd = json_data["cmd"]
if _type == "OGC": # 油气浓度
if _cmd == "oil_gas_concentration_value": # 实时油气浓度值上传
stack_func.set_stack(_type, json_data)
# print(stack_func.get_stack())
thread = threading.Thread(target=thread_func.gas_concentration, args=(current_app._get_current_object(), json_data["data"]))
thread.start()
elif _type == "PS": # 压力
if _cmd == "pressure_value": # 压力
stack_func.set_stack(_type, json_data)
# print(stack_func.get_stack())
thread = threading.Thread(target=thread_func.pressure,
args=(current_app._get_current_object(), json_data["data"]))
thread.start()
elif _type == "ScramButton": # 急停按钮
if _cmd == "switch_value": # 开关值
stack_func.set_stack(_type, json_data)
# print(stack_func.get_stack())
thread = threading.Thread(target=thread_func.switch,
args=(current_app._get_current_object(), json_data["data"]))
thread.start()
elif _type == "Video": # 视频分析
if _cmd == "video_alarm_data": # 事件信息
stack_func.set_stack(_type, json_data)
# print(stack_func.get_stack())
thread = threading.Thread(target=thread_func.video,
args=(current_app._get_current_object(), json_data["data"]))
thread.start()
elif _type == "Radar": # 雷达
if _cmd == "target_info_param": # 事件信息
stack_func.set_stack(_type, json_data)
# print(stack_func.get_stack())
thread = threading.Thread(target=thread_func.radar,
args=(current_app._get_current_object(), json_data["data"]))
thread.start()
elif _type == "PCM": # 用电管理
if _cmd == "power_consumption_param": # 事件信息
stack_func.set_stack(_type, json_data)
# print(stack_func.get_stack())
thread = threading.Thread(target=thread_func.pcm,
args=(current_app._get_current_object(), json_data["data"]))
thread.start()
else:
pass
return Response(code=200, msg='ok', success=True).json