This commit is contained in:
Zhang Muyu
2023-10-01 19:01:02 +08:00
parent c45df796a6
commit 8507d2a7ea
5 changed files with 48 additions and 4 deletions

BIN
dashboard.db Normal file

Binary file not shown.

View File

@@ -3,6 +3,7 @@ import sys
import time
import argparse
import base64
import random
sys.path.append(os.getcwd())
import svgwrite
@@ -29,7 +30,7 @@ def gen_distance(data, theme_type):
theme_color = THEME_MAP.get(theme_type) or COLOR_GREEN
data_file_name = 'distance_{}'.format(time.strftime('%Y%m%d%H%M%S'))
data_file_name = 'distance_{}_{}'.format(time.strftime('%Y%m%d%H%M%S'), random.randint(0, 9999))
svg_file_path = './output/{}.svg'.format(data_file_name)
png_file_path = './output/{}.png'.format(data_file_name)

View File

@@ -3,6 +3,7 @@ import sys
import time
import argparse
import base64
import random
sys.path.append(os.getcwd())
import svgwrite
@@ -53,7 +54,7 @@ def gen_common(data, theme_type):
bottom_name = 'exit'
exit_height = exit_item.height()
data_file_name = '{}_{}'.format(bottom_name, time.strftime('%Y%m%d%H%M%S'))
data_file_name = '{}_{}_{}'.format(bottom_name, time.strftime('%Y%m%d%H%M%S'), random.randint(0, 9999))
svg_file_path = './output/{}.svg'.format(data_file_name)
png_file_path = './output/{}.png'.format(data_file_name)

View File

@@ -3,6 +3,7 @@ import sys
import time
import argparse
import base64
import random
sys.path.append(os.getcwd())
import svgwrite
@@ -26,7 +27,7 @@ def gen_service(data):
text_size = 40 * SCALE
min_width = icon_height * 2 + safe_area_size * 2
data_file_name = 'sa_pa_{}'.format(time.strftime('%Y%m%d%H%M%S'))
data_file_name = 'sa_pa_{}_{}'.format(time.strftime('%Y%m%d%H%M%S'), random.randint(0, 9999))
svg_file_path = './output/{}.svg'.format(data_file_name)
png_file_path = './output/{}.png'.format(data_file_name)

View File

@@ -10,6 +10,8 @@ from settings import *
import json
import os
import logging
import sqlite3
import time
app = Flask(__name__)
@@ -22,12 +24,15 @@ app.logger.addHandler(handler)
CORS(app)
db_conn = sqlite3.connect('dashboard.db')
@app.route('/api/pov-element/common', methods=["GET"])
def common():
query_data = request.args.get('data')
json_data = json.loads(query_data)
theme = request.args.get('theme')
app.logger.info('[{}] {}'.format(request.remote_addr, parse.unquote(query_data)))
track_request(request.remote_addr, '直行和出口预告', parse.unquote(query_data))
data, path = gen_common(json_data, theme)
res = {
'code': 0,
@@ -43,6 +48,7 @@ def distance():
json_data = json.loads(query_data)
theme = request.args.get('theme')
app.logger.info('[{}] {}'.format(request.remote_addr, parse.unquote(query_data)))
track_request(request.remote_addr, '地点距离预告', parse.unquote(query_data))
data, path = gen_distance(json_data, theme)
res = {
'code': 0,
@@ -57,6 +63,7 @@ def service():
query_data = request.args.get('data')
json_data = json.loads(query_data)
app.logger.info('[{}] {}'.format(request.remote_addr, parse.unquote(query_data)))
track_request(request.remote_addr, '服务区预告', parse.unquote(query_data))
data, path = gen_service(json_data)
res = {
'code': 0,
@@ -66,6 +73,40 @@ def service():
AUTO_CLEAN and os.remove(path)
return response
def track_request(ip, type, data):
cursor = db_conn.cursor()
sql = """
INSERT INTO POV(TIME, IP, TYPE, DATA) VALUES(?, ?, ?, ?);
"""
param = (time.strftime('%Y-%m-%d %H:%M:%S'), ip, type, data)
try:
cursor.execute(sql, param)
except sqlite3.OperationalError as e:
app.logger.info(e)
finally:
cursor.close()
db_conn.commit()
def init_dashboard():
cursor = db_conn.cursor()
sql = """
CREATE TABLE IF NOT EXISTS POV(
TIME TEXT,
IP TEXT,
TYPE INTEGER,
DATA TEXT
);
"""
try:
cursor.execute(sql)
except sqlite3.OperationalError as e:
app.logger.info(e)
finally:
cursor.close()
db_conn.commit()
if __name__ == '__main__':
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
init_dashboard()
server = pywsgi.WSGIServer(('0.0.0.0', 5001), app)
server.serve_forever()