実際のところ
import streamlit as st
import sqlite3
import pandas as pd
import plotly.express as px
from datetime import datetime, timedelta
con = sqlite3.connect("logging_data.db")
df = pd.read_sql_query("SELECT * FROM loggingData", con)
df['記録日時'] = pd.to_datetime(df['記録日時'])
st.title("Logging Data Visualization")
today = datetime.today()
start_date = st.slider("Start date", min_value=today - timedelta(days=100), max_value=today - timedelta(days=1), value=today - timedelta(days=100), step=timedelta(days=1))
end_date = st.slider("End date", min_value=start_date + timedelta(days=1), max_value=today, value=today, step=timedelta(days=1))
filtered_df = df[(df['記録日時'] >= start_date) & (df['記録日時'] <= end_date)]
fig = px.line(filtered_df, x='記録日時', y='測定値', color='記録装置ID', labels={'記録日時': 'Date', '測定値': 'Measurement Value'})
st.plotly_chart(fig)
devices = ["A001", "A002", "B001"]
metrics = []
for device in devices:
device_data = filtered_df[filtered_df["記録装置ID"] == device]
highest_measurement = device_data.loc[device_data["測定値"].idxmax()]
metrics.append((device, highest_measurement["記録日時"], highest_measurement["測定値"]))
cols = st.columns(3)
for i, (device, date, value) in enumerate(metrics):
cols[i].metric(label=f"Device {device}", value=value, delta=date.strftime("%Y-%m-%d %H:%M:%S"))
con.close()