|
2 | 2 |
|
3 | 3 | from ._sheets_utils import *
|
4 | 4 | from .entities import *
|
| 5 | +from .sheets_api import COLUMN_FORMAT_OPTIONS |
5 | 6 | from urllib.parse import urlparse
|
6 | 7 |
|
| 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 | + |
7 | 71 | def get_outbound_links_df(analytics_params, ignore_index=True):
|
8 | 72 | """
|
9 | 73 | Get a DataFrame with outbound links from the Analytics API. Merges the builtin and custom events for outbound links.
|
|
0 commit comments