This commit is contained in:
Zhang Muyu
2023-10-01 21:38:38 +08:00
parent dc99fcf50f
commit aa2d7be53d
2 changed files with 32 additions and 2 deletions

3
.gitignore vendored
View File

@@ -165,4 +165,5 @@ data/
*.svg
.DS_Store
.VSCodeCounter/
.vscode/
.vscode/
*.db

View File

@@ -73,6 +73,18 @@ def service():
AUTO_CLEAN and os.remove(path)
return response
@app.route('/api/pov-element/dashboard', methods=["GET"])
def dashboard():
start_time = request.args.get('start_time')
end_time = request.args.get('end_time')
data = fetch_dashboard(start_time, end_time)
res = {
'code': 0,
'image': data,
}
response = make_response(res)
return response
def track_request(ip, type, data):
cursor = db_conn.cursor()
sql = """
@@ -87,6 +99,23 @@ def track_request(ip, type, data):
cursor.close()
db_conn.commit()
def fetch_dashboard(start_time, end_time):
cursor = db_conn.cursor()
sql = """
SELECT TIME, TYPE, COUNT(*) FROM POV WHERE TIME BETWEEN ? AND ? GROUP BY TYPE, TIME;
"""
param = (start_time, end_time)
try:
cursor.execute(sql, param)
result = cursor.fetchall()
app.logger.info(result)
except sqlite3.OperationalError as e:
app.logger.info(e)
finally:
cursor.close()
db_conn.commit()
def init_dashboard():
cursor = db_conn.cursor()
sql = """
@@ -108,5 +137,5 @@ def init_dashboard():
if __name__ == '__main__':
init_dashboard()
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
server = pywsgi.WSGIServer(('0.0.0.0', 5001), app)
server.serve_forever()