Skip to content

Commit

Permalink
Merge branch 'feature/graph' into feature/shoe_series_select
Browse files Browse the repository at this point in the history
  • Loading branch information
motty-mio2 committed Nov 5, 2023
2 parents 0bf3920 + f89aa13 commit 94c3b25
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dependencies = [
"alembic>=1.12.1",
"sqlalchemy>=2.0.23",
"oracledb>=1.4.2",
"streamlit>=1.28.1",
"plotly>=5.18.0",
]
readme = "README.md"
requires-python = ">= 3.11"
Expand Down
33 changes: 33 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ aenum==3.1.15
aiohttp==3.8.5
aiosignal==1.3.1
alembic==1.12.1
altair==5.1.2
annotated-types==0.6.0
anyio==3.7.1
async-timeout==4.0.3
attrs==23.1.0
black==23.10.1
blinker==1.7.0
cachetools==5.3.2
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==3.3.2
Expand All @@ -26,38 +29,68 @@ deprecated==1.2.14
fastapi==0.104.1
frozenlist==1.4.0
future==0.18.3
gitdb==4.0.11
gitpython==3.1.40
greenlet==3.0.1
h11==0.14.0
idna==3.4
importlib-metadata==6.8.0
iniconfig==2.0.0
isort==5.12.0
jinja2==3.1.2
jsonschema==4.19.2
jsonschema-specifications==2023.7.1
line-bot-sdk==3.5.0
mako==1.2.4
markdown-it-py==3.0.0
markupsafe==2.1.3
mdurl==0.1.2
multidict==6.0.4
mypy==1.6.1
mypy-extensions==1.0.0
numpy==1.26.1
oracledb==1.4.2
packaging==23.2
pandas==2.1.2
pathspec==0.11.2
pillow==10.1.0
platformdirs==3.11.0
plotly==5.18.0
pluggy==1.3.0
protobuf==4.25.0
pyarrow==14.0.0
pycparser==2.21
pydantic==2.4.2
pydantic-core==2.10.1
pydeck==0.8.1b0
pygments==2.16.1
pytest==7.4.3
python-dateutil==2.8.2
pytz==2023.3.post1
referencing==0.30.2
requests==2.31.0
rich==13.6.0
rpds-py==0.12.0
ruff==0.1.3
six==1.16.0
smmap==5.0.1
sniffio==1.3.0
sqlalchemy==2.0.23
starlette==0.27.0
streamlit==1.28.1
tenacity==8.2.3
toml==0.10.2
toolz==0.12.0
tornado==6.3.3
types-requests==2.31.0.10
types-toml==0.10.8.7
typing-extensions==4.8.0
tzdata==2023.3
tzlocal==5.2
urllib3==2.0.7
uvicorn==0.23.2
validators==0.22.0
watchdog==3.0.0
wrapt==1.15.0
yarl==1.9.2
zipp==3.17.0
34 changes: 34 additions & 0 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ aenum==3.1.15
aiohttp==3.8.5
aiosignal==1.3.1
alembic==1.12.1
altair==5.1.2
annotated-types==0.6.0
anyio==3.7.1
async-timeout==4.0.3
attrs==23.1.0
blinker==1.7.0
cachetools==5.3.2
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==3.3.2
Expand All @@ -25,26 +28,57 @@ deprecated==1.2.14
fastapi==0.104.1
frozenlist==1.4.0
future==0.18.3
gitdb==4.0.11
gitpython==3.1.40
greenlet==3.0.1
h11==0.14.0
idna==3.4
importlib-metadata==6.8.0
jinja2==3.1.2
jsonschema==4.19.2
jsonschema-specifications==2023.7.1
line-bot-sdk==3.5.0
mako==1.2.4
markdown-it-py==3.0.0
markupsafe==2.1.3
mdurl==0.1.2
multidict==6.0.4
numpy==1.26.1
oracledb==1.4.2
packaging==23.2
pandas==2.1.2
pillow==10.1.0
plotly==5.18.0
protobuf==4.25.0
pyarrow==14.0.0
pycparser==2.21
pydantic==2.4.2
pydantic-core==2.10.1
pydeck==0.8.1b0
pygments==2.16.1
python-dateutil==2.8.2
pytz==2023.3.post1
referencing==0.30.2
requests==2.31.0
rich==13.6.0
rpds-py==0.12.0
six==1.16.0
smmap==5.0.1
sniffio==1.3.0
sqlalchemy==2.0.23
starlette==0.27.0
streamlit==1.28.1
tenacity==8.2.3
toml==0.10.2
toolz==0.12.0
tornado==6.3.3
typing-extensions==4.8.0
tzdata==2023.3
tzlocal==5.2
urllib3==2.0.7
uvicorn==0.23.2
validators==0.22.0
watchdog==3.0.0
wrapt==1.15.0
yarl==1.9.2
zipp==3.17.0
5 changes: 2 additions & 3 deletions src/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from logging.config import fileConfig

from alembic import context

from kb_2315.backend.db.base import Base
from kb_2315.backend.db.session import engine

from kb_2315.backend.models import Sensor, Session, Shoe # noqa: F401
from kb_2315.backend.db.base import Base


# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
3 changes: 2 additions & 1 deletion src/alembic/versions/2023_11_05_1629-41fa0bc1e4c2_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

from alembic import op


# revision identifiers, used by Alembic.
revision: str = "41fa0bc1e4c2"
Expand Down
8 changes: 7 additions & 1 deletion src/kb_2315/backend/crud/crud_sensor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import timezone
from uuid import UUID

from sqlalchemy.orm import Query
Expand Down Expand Up @@ -48,7 +49,12 @@ def search_sensor_by(
if session_id is not None:
query = query.filter(Sensor.session_id == session_id)

return query.all()
ret: list[Sensor] = query.all()

for r in ret:
r.time = r.time.replace(tzinfo=timezone.utc)

return ret


crud_sensor = CRUD_Sensor()
73 changes: 73 additions & 0 deletions src/sample/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from datetime import timedelta, timezone
from uuid import UUID

import plotly.graph_objects as go
import streamlit as st

from kb_2315.backend.crud import crud_sensor, crud_session
from kb_2315.backend.models import Sensor


st.set_page_config(layout="wide")

# Sidebar

st.sidebar.title("Analyze")

st.sidebar.subheader("Select a Session")
sessions: list[UUID] = [i.session_id for i in crud_session.search_session_by()]

st.session_state.session_id = st.sidebar.selectbox("Session", sessions)


# Main Page

sensors: list[Sensor] = crud_sensor.search_sensor_by(session_id=st.session_state.session_id)


JST = timezone(timedelta(hours=+9), "JST")
timeseries: list[str] = [s.time.astimezone(JST).strftime("%H時%M分%S秒") for s in sensors]

external_temperatures: list[float] = [s.external_temperature for s in sensors]
external_humidities: list[float] = [s.external_humidity for s in sensors]
internal_temperatures: list[float] = [s.internal_temperature for s in sensors]
internal_humidities: list[float] = [s.internal_humidity for s in sensors]


st.subheader("温度")
figT = go.Figure(
data=[
go.Scatter(
x=timeseries,
y=external_temperatures,
name="外気温度",
mode="lines+markers",
),
go.Scatter(
x=timeseries,
y=internal_temperatures,
name="内気温度",
mode="lines+markers",
),
]
)
st.plotly_chart(figT)

st.subheader("湿度")
figH = go.Figure(
data=[
go.Scatter(
x=timeseries,
y=external_humidities,
name="外気温度",
mode="lines+markers",
),
go.Scatter(
x=timeseries,
y=internal_humidities,
name="内気温度",
mode="lines+markers",
),
]
)
st.plotly_chart(figH)

0 comments on commit 94c3b25

Please sign in to comment.