Skip to content

Commit

Permalink
tidy, use new nowcasting_datamodel
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Dec 4, 2023
1 parent 0e543f4 commit 278d68d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
altair==4.2.2
nowcasting_datamodel==1.5.19
nowcasting_datamodel==1.5.25
pvsite-datamodel==1.0.1
numpy==1.24.1
pandas==1.5.3
Expand Down
28 changes: 11 additions & 17 deletions src/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import os
from nowcasting_datamodel.connection import DatabaseConnection
from nowcasting_datamodel.models.api import UserSQL, APIRequestSQL
from nowcasting_datamodel.read.read_user import (

Check warning on line 7 in src/users.py

View check run for this annotation

Codecov / codecov/patch

src/users.py#L1-L7

Added lines #L1 - L7 were not covered by tests
get_all_last_api_request,
get_api_requests_for_one_user,
)

from plots.users import make_api_requests_plot

Check warning on line 12 in src/users.py

View check run for this annotation

Codecov / codecov/patch

src/users.py#L12

Added line #L12 was not covered by tests

Expand All @@ -24,21 +28,18 @@ def user_page():
value=datetime.today() - timedelta(days=31),
)
end_time = st.sidebar.date_input(

Check warning on line 30 in src/users.py

View check run for this annotation

Codecov / codecov/patch

src/users.py#L30

Added line #L30 was not covered by tests
"End Date", min_value=datetime.today() - timedelta(days=365), max_value=datetime.today()
"End Date",
min_value=datetime.today() - timedelta(days=365),
max_value=datetime.today() + timedelta(days=1),
value=datetime.today() + timedelta(days=1),
)

# get last call from the database
url = os.environ["DB_URL"]
connection = DatabaseConnection(url=url, echo=True)
with connection.get_session() as session:

Check warning on line 40 in src/users.py

View check run for this annotation

Codecov / codecov/patch

src/users.py#L38-L40

Added lines #L38 - L40 were not covered by tests

last_requests_sql = (
session.query(APIRequestSQL)
.distinct(APIRequestSQL.user_uuid)
.join(UserSQL)
.order_by(APIRequestSQL.user_uuid, APIRequestSQL.created_utc.desc())
.all()
)
last_requests_sql = get_all_last_api_request(session=session)

Check warning on line 42 in src/users.py

View check run for this annotation

Codecov / codecov/patch

src/users.py#L42

Added line #L42 was not covered by tests

last_request = [

Check warning on line 44 in src/users.py

View check run for this annotation

Codecov / codecov/patch

src/users.py#L44

Added line #L44 was not covered by tests
(last_request_sql.user.email, last_request_sql.created_utc)
Expand All @@ -56,13 +57,8 @@ def user_page():

# get all calls for selected user
with connection.get_session() as session:
api_requests_sql = (
session.query(APIRequestSQL)
.join(UserSQL)
.where(UserSQL.email == email_selected)
.where(APIRequestSQL.created_utc >= start_time)
.where(APIRequestSQL.created_utc <= end_time)
.all()
api_requests_sql = get_api_requests_for_one_user(

Check warning on line 60 in src/users.py

View check run for this annotation

Codecov / codecov/patch

src/users.py#L59-L60

Added lines #L59 - L60 were not covered by tests
session=session, email=email_selected, start_datetime=start_time, end_datetime=end_time
)

api_requests = [

Check warning on line 64 in src/users.py

View check run for this annotation

Codecov / codecov/patch

src/users.py#L64

Added line #L64 was not covered by tests
Expand All @@ -73,5 +69,3 @@ def user_page():

fig = make_api_requests_plot(api_requests, email_selected, end_time, start_time)
st.plotly_chart(fig, theme="streamlit")

Check warning on line 71 in src/users.py

View check run for this annotation

Codecov / codecov/patch

src/users.py#L70-L71

Added lines #L70 - L71 were not covered by tests


0 comments on commit 278d68d

Please sign in to comment.