Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_notebook and interactive_function_name visit field #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to interact with the database."""

from typing import Optional, Sequence

import os
Expand Down Expand Up @@ -34,6 +35,8 @@ class VisitStats(SQLModel, table=True):
is_singularity: bool
is_conda: bool
is_ci: bool
is_notebook: bool
interactive_function_name: Optional[str]
count: int


Expand Down Expand Up @@ -129,4 +132,3 @@ def insert_download_stats(df: pd.DataFrame) -> pd.DataFrame:
session.add(new_entry)
session.commit()
return df

14 changes: 14 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def update_version():
"is_singularity",
"is_conda",
"is_ci",
"is_notebook",
"interactive_function_name",
]

# Thread-safe in-memory buffer to accumulate recent visits before writing to the CSV file
Expand All @@ -106,6 +108,8 @@ async def version(
is_singularity: str = "",
is_conda: str = "",
is_ci: str = "",
is_notebook: str = "",
interactive_function_name: str = "",
):
"""
Endpoint for MultiQC that returns the latest release, and logs
Expand All @@ -121,6 +125,8 @@ async def version(
is_singularity=is_singularity,
is_conda=is_conda,
is_ci=is_ci,
is_notebook=is_notebook,
interactive_function_name=interactive_function_name,
)
return models.VersionResponse(latest_release=app.latest_release)

Expand Down Expand Up @@ -149,6 +155,8 @@ def _log_visit(
is_singularity: str = "",
is_conda: str = "",
is_ci: str = "",
is_notebook: str = "",
interactive_function_name: str = "",
):
global visit_buffer
with visit_buffer_lock:
Expand All @@ -162,6 +170,8 @@ def _log_visit(
"is_singularity": is_singularity,
"is_conda": is_conda,
"is_ci": is_ci,
"is_notebook": is_notebook,
"interactive_function_name": interactive_function_name,
}
)
logger.debug(f"Logged visit, total visits in buffer: {len(visit_buffer)}")
Expand Down Expand Up @@ -252,6 +262,8 @@ def strtobool(val) -> bool:
df["is_singularity"] = df["is_singularity"].apply(strtobool)
df["is_conda"] = df["is_conda"].apply(strtobool)
df["is_ci"] = df["is_ci"].apply(strtobool)
df["is_notebook"] = df["is_notebook"].apply(strtobool)
df["interactive_function_name"] = df["interactive_function_name"].astype(str)
df = df.drop(columns=["timestamp"])

# Summarize visits per user per time interval
Expand Down Expand Up @@ -409,6 +421,8 @@ async def version_legacy(background_tasks: BackgroundTasks, v: str = ""):
is_singularity="",
is_conda="",
is_ci="",
is_notebook="",
interactive_function_name="",
)
return app.latest_release.version

Expand Down
4 changes: 4 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class UsageCategory(str, Enum):
is_singularity = "is_singularity"
is_conda = "is_conda"
is_ci = "is_ci"
is_notebook = "is_notebook"
interactive_function_name = "interactive_function_name"


usage_category_nice_names = dict(
Expand All @@ -78,4 +80,6 @@ class UsageCategory(str, Enum):
is_singularity="Singularity",
is_conda="Conda",
is_ci="CI environment",
is_notebook="Notebook",
interactive_function_name="Interactive function",
)