simple network logging app
This commit is contained in:
38
app.py
Normal file
38
app.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from flask import Flask, render_template
|
||||
import sqlite3
|
||||
import pandas as pd
|
||||
from config import DB_PATH
|
||||
from datetime import datetime
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def load_data():
|
||||
# Connect to SQLite database
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
query = "SELECT * FROM speed_tests"
|
||||
df = pd.read_sql(query, conn)
|
||||
conn.close()
|
||||
return df
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
df = load_data()
|
||||
|
||||
|
||||
|
||||
# Convert timestamps to human-readable format
|
||||
df['datetime'] = pd.to_datetime(df['timestamp'], unit='s')
|
||||
# Suppose your DataFrame is called `df`
|
||||
df["timestamp"] = df["timestamp"].apply(lambda ts: datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S"))
|
||||
|
||||
# Collect the data for charts
|
||||
chart_data = {
|
||||
"times": df['datetime'].dt.strftime('%Y-%m-%d %H:%M:%S').tolist(),
|
||||
"down_90th": df['down_90th'].tolist(),
|
||||
"up_90th": df['up_90th'].tolist()
|
||||
}
|
||||
|
||||
return render_template('index.html', data=df.to_dict(orient='records'), chart_data=chart_data)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
Reference in New Issue
Block a user