Skip to content

Commit 873daa0

Browse files
authored
feat: add predefined formatting options and function to get periods to analytics package (#4430) (#4431)
1 parent d943aca commit 873daa0

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

Diff for: analytics/analytics_package/analytics/sheets_elements.py

+64
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,72 @@
22

33
from ._sheets_utils import *
44
from .entities import *
5+
from .sheets_api import COLUMN_FORMAT_OPTIONS
56
from urllib.parse import urlparse
67

8+
OUTBOUND_LINKS_CHANGE_FORMATTING = {
9+
SYNTHETIC_METRIC_CLICKS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
10+
METRIC_TOTAL_USERS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
11+
}
12+
13+
PAGE_VIEWS_CHANGE_FORMATTING = {
14+
METRIC_PAGE_VIEWS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
15+
METRIC_TOTAL_USERS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
16+
}
17+
18+
PAGE_VIEWS_OVER_TIME_FORMATTING = {
19+
DIMENSION_YEAR_MONTH["alias"]: COLUMN_FORMAT_OPTIONS.YEAR_MONTH_DATE,
20+
METRIC_ACTIVE_USERS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
21+
METRIC_PAGE_VIEWS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
22+
}
23+
24+
LANDING_PAGE_CHANGE_FORMATTING = {
25+
METRIC_SESSIONS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
26+
}
27+
28+
INDEX_TABLE_DOWNLOAD_CHANGE_FORMATTING = {
29+
METRIC_EVENT_COUNT["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
30+
METRIC_TOTAL_USERS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
31+
}
32+
33+
INDEX_ENTITY_SELECTED_CHANGE_FORMATTING = {
34+
METRIC_EVENT_COUNT["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
35+
METRIC_TOTAL_USERS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
36+
}
37+
38+
INDEX_ENTITY_TABLE_SORTED_CHANGE_FORMATTING = {
39+
METRIC_EVENT_COUNT["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
40+
METRIC_TOTAL_USERS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
41+
}
42+
43+
INDEX_ENTITY_TABLE_PAGINATED_CHANGE_FORMATTING = {
44+
METRIC_EVENT_COUNT["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
45+
METRIC_TOTAL_USERS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
46+
}
47+
48+
INDEX_FILTER_SELECTED_CHANGE_FORMATTING = {
49+
METRIC_EVENT_COUNT["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
50+
METRIC_TOTAL_USERS["change_alias"]: COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,
51+
}
52+
53+
def get_bounds_for_month_and_prev(month):
54+
"""
55+
Get dates of the first and last day of the given month and the month preceding it.
56+
57+
:param month: The month to get dates for, represented as a string in YYYY-MM format.
58+
:return: A dict containing entries "start_current", "end_current", "start_previous", and "end_previous", each holding a string in YYYY-MM-DD format.
59+
"""
60+
start_current = pd.to_datetime(month)
61+
end_current = start_current + pd.DateOffset(months=1) - pd.DateOffset(days=1)
62+
start_previous = start_current - pd.DateOffset(months=1)
63+
end_previous = start_current - pd.DateOffset(days=1)
64+
return {
65+
"start_current": start_current.strftime("%Y-%m-%d"),
66+
"end_current": end_current.strftime("%Y-%m-%d"),
67+
"start_previous": start_previous.strftime("%Y-%m-%d"),
68+
"end_previous": end_previous.strftime("%Y-%m-%d")
69+
}
70+
771
def get_outbound_links_df(analytics_params, ignore_index=True):
872
"""
973
Get a DataFrame with outbound links from the Analytics API. Merges the builtin and custom events for outbound links.

Diff for: analytics/analytics_package/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="analytics",
5-
version="4.2.0",
5+
version="4.3.0",
66
packages=["analytics"],
77
install_requires=["matplotlib", "pandas", "numpy", "google-auth-oauthlib", "google-api-python-client", "gspread", "gspread-formatting"],
88
)

0 commit comments

Comments
 (0)