From 5981ff0bd7ba93b53ea403c80e87e11a9d159f1e Mon Sep 17 00:00:00 2001 From: seeyoui-2024 Date: Thu, 11 Jun 2026 17:21:19 +0800 Subject: [PATCH 1/2] Update CMD and modify socketio.run parameters Flask-SocketIO detects that you are using Werkzeug's built-in server in a production environment (or an environment it recognizes as non-development). This usage is prohibited by default, as Werkzeug is not designed for production and poses security and performance risks. --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d2204a1..626923f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,4 +5,5 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 5000 RUN pip freeze > installed_packages.txt -CMD ["python", "restapi.py"] +RUN sed -i 's/socketio.run(app, host="0.0.0.0", port=5000, debug=True)/socketio.run(app, host="0.0.0.0", port=5000, debug=True, allow_unsafe_werkzeug=True)/' /app/restapi.py +CMD ["python", "/app/restapi.py"] From fd729a935bbb1e3ae85a2cadc19ecb33d0c4cccd Mon Sep 17 00:00:00 2001 From: seeyoui-2024 Date: Thu, 11 Jun 2026 17:23:03 +0800 Subject: [PATCH 2/2] Add database initialization on startup Automatically creates the database and tables if they do not exist on application startup. --- restapi.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/restapi.py b/restapi.py index a883646..8ea9068 100644 --- a/restapi.py +++ b/restapi.py @@ -3,7 +3,7 @@ from mlmodel import guess import pandas as pd import sqlite3 - +import os from flask_cors import CORS @@ -14,6 +14,64 @@ received_data = [] DB_PATH = "sensor_data.db" +def init_db(): + """Automatically create the database and tables if they do not exist.""" + conn = sqlite3.connect(DB_PATH) + c = conn.cursor() + c.execute(""" + CREATE TABLE IF NOT EXISTS sensor_data ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + time TEXT, + rotation_speed REAL, + temperature REAL, + level REAL, + kurtosis_axial REAL, + kurtosis_vertical REAL, + kurtosis_horizontal REAL, + peak_axial REAL, + peak_vertical REAL, + peak_horizontal REAL, + vibration_acc_axial REAL, + vibration_acc_vertical REAL, + vibration_acc_horizontal REAL, + vibration_vel_axial REAL, + vibration_vel_vertical REAL, + vibration_vel_horizontal REAL, + band_0_8k REAL, + band_8_16k REAL, + band_16_24k REAL, + band_24_32k REAL, + band_32_40k REAL, + band_40_48k REAL, + band_48_56k REAL, + band_56_64k REAL, + band_64_72k REAL, + band_72_80k REAL, + band_0_200 REAL, + band_200_400 REAL, + band_400_600 REAL, + band_600_800 REAL, + band_800_1000 REAL, + band_1_1_2k REAL, + band_1_2_1_4k REAL, + band_1_4_1_6k REAL, + band_1_6_1_8k REAL, + band_1_8_2k REAL, + fault0 REAL, + fault1 REAL, + fault2 REAL, + fault3 REAL, + fault4 REAL, + fault5 REAL, + fault6 REAL, + fault7 REAL + ) + """) + conn.commit() + conn.close() + +# Automatically initialize the database on application startup +init_db() @app.route('/') @@ -126,4 +184,4 @@ def generate_csv(): if __name__ == "__main__": - socketio.run(app, host="0.0.0.0", port=5000, debug=True) \ No newline at end of file + socketio.run(app, host="0.0.0.0", port=5000, debug=True)