31 lines
776 B
Python
31 lines
776 B
Python
import sqlite3
|
|
import pandas as pd
|
|
from config import DB_PATH
|
|
from datetime import datetime
|
|
|
|
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
|
|
|
|
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()
|
|
}
|
|
|
|
print(df[-60:])
|
|
|
|
|