From 5fa3e78dd9860be3c6d7a72f9cda3734c681cb3d Mon Sep 17 00:00:00 2001 From: wyh <15252062643@163.com> Date: Wed, 18 Dec 2024 14:00:54 +0800 Subject: [PATCH] 1234 --- apps.py | 30 ++++-- templates/index.html | 237 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 261 insertions(+), 6 deletions(-) create mode 100644 templates/index.html diff --git a/apps.py b/apps.py index 9e0bd35..0bee2cd 100644 --- a/apps.py +++ b/apps.py @@ -1,8 +1,26 @@ -#展示Computer_status对象中的状态,以时间为轴,绘制折线图 -# -# 可以选择实时展示,每隔1s发送请求,服务器调用Computer_status.get_data_json_30s,返回json -# -# 可以选择查看指定时间端的历史信息,发送请求,包含开始时间和结束时间,服务器调用Computer_status.get_data_json,返回json +from flask import Flask, jsonify, request +from datetime import datetime +from your_database_module import ComputerStatus # 请根据实际路径引入你的数据库模块 + +app = Flask(__name__) + + +@app.route('/get_data_json_30s', methods=['GET']) +def get_data_json_30s(): + # 获取最新30秒的数据 + data = ComputerStatus.get_data_json_30s() + return jsonify(data) + + +@app.route('/get_data_json', methods=['GET']) +def get_data_json(): + time_start = int(request.args.get('time_start')) + time_end = int(request.args.get('time_end')) + + # 获取指定时间范围的数据 + data = ComputerStatus.get_data_json(time_start, time_end) + return jsonify(data) + if __name__ == '__main__': - pass \ No newline at end of file + app.run(debug=True) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..2eae346 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,237 @@ + + +
+ + +Loading...
+Loading...
+Loading...
+