Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
62 changes: 60 additions & 2 deletions restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mlmodel import guess
import pandas as pd
import sqlite3

import os


from flask_cors import CORS
Expand All @@ -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('/')
Expand Down Expand Up @@ -126,4 +184,4 @@ def generate_csv():


if __name__ == "__main__":
socketio.run(app, host="0.0.0.0", port=5000, debug=True)
socketio.run(app, host="0.0.0.0", port=5000, debug=True)