Skip to content

Commit

Permalink
[analytics] use 'nightly' for version datestamps (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
bfineran authored Dec 18, 2023
1 parent ff62777 commit c035b5b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/sparsezoo/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class GoogleAnalytics:
Google Analytics client for sending events for the given package and version
:param package: the name of the package to send events for
:param version: the version of the package to send events for
:param version: the version of the package to send events for,
if the version string has a nightly datestamp, the datestamp portion will
be replaced by 'nightly'
:param package_params: optional dictionary of parameters to send with each event
"""

Expand Down Expand Up @@ -75,7 +77,7 @@ def __init__(
GoogleAnalytics.get_client_id() if not self._disabled else None
)
self._package = package
self._version = version
self._version = _maybe_replace_nightly_date(version)
self._package_params = package_params if package_params is not None else {}

def send_event_decorator(
Expand Down Expand Up @@ -159,5 +161,17 @@ def _send_request():
thread.join()


def _maybe_replace_nightly_date(version: str) -> str:
version_parts = version.split(".")
if len(version_parts) == 4 and len(version_parts[3]) == 8:
# nightly would be the 4th part of version string
# and would be 8 character YYYYMMDD, assume this check is
# sufficient, replace datestamp with 'nightly'
version_parts[3] = "nightly"
version = ".".join(version_parts)

return version


# analytics client for sparsezoo, to disable set NM_DISABLE_ANALYTICS=1
sparsezoo_analytics = GoogleAnalytics("sparsezoo", sparsezoo_version)

0 comments on commit c035b5b

Please sign in to comment.