diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc index b9ac065..5f4af62 100644 Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ diff --git a/app.py b/app.py index abd00e4..0d2658e 100644 --- a/app.py +++ b/app.py @@ -1,9 +1,9 @@ import os +import json import sqlite3 from flask import Flask, request, jsonify, render_template from flask_sqlalchemy import SQLAlchemy -from sqlalchemy import PickleType basedir = os.path.abspath(os.path.dirname(__file__)) @@ -15,7 +15,7 @@ db = SQLAlchemy(app) class Tracker(db.Model): id = db.Column(db.Integer, primary_key=True) distance = db.Column(db.Integer, nullable=False) - data = db.Column(PickleType(), nullable=False) + data = db.Column(db.Text, nullable=False) @app.route('/', methods=['GET']) @@ -28,9 +28,7 @@ def index(): def upload_data(): data = request.json print(data) - record = Tracker(distance=data["distance"], data=data["data"]) - - print(sum(item[0] for item in data["data"])) + record = Tracker(distance=data["distance"], data=json.dumps(data["data"])) db.session.add(record) db.session.commit() return jsonify({"message": "Data recorded"}), 200 diff --git a/database.db b/database.db index 5c1bcec..fefb04e 100644 Binary files a/database.db and b/database.db differ diff --git a/get_mouse_tracker.py b/get_mouse_tracker.py new file mode 100644 index 0000000..8958ba4 --- /dev/null +++ b/get_mouse_tracker.py @@ -0,0 +1,17 @@ + +import sqlite3 +import json + +conn = sqlite3.connect('database.db') + +cursor = conn.cursor() +cursor.execute("SELECT * FROM Tracker") + +rows = cursor.fetchall() + +for index, distance, mouse_tracker in rows: + print(f"Index: {index}, Distance: {distance}") + print(f"Mouse tracker: {json.loads(mouse_tracker)}") + +# 关闭连接 +conn.close() diff --git a/templates/index.html b/templates/index.html index 7d39303..0ecce61 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,7 +7,6 @@ - - -
- +
+
+
- - +
+ +
+