Skip to content

Commit 3141f3e

Browse files
author
Jonah Paten
authored
feat: added missing elements to hca dx analytics sheets (#4371) (#4377)
1 parent fe23cfa commit 3141f3e

File tree

3 files changed

+75
-23
lines changed

3 files changed

+75
-23
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# CHANGE THESE VALUES TO GENERATE NEW REPORTS
22
# The start and end dates of the current month (yyyy-mm-dd)
3-
START_DATE_CURRENT = "2024-12-01"
4-
END_DATE_CURRENT = "2024-12-31"
3+
START_DATE_CURRENT = "2025-01-01"
4+
END_DATE_CURRENT = "2025-01-31"
55
# The start and end dates of the prior months
6-
START_DATE_PRIOR = "2024-11-01"
7-
END_DATE_PRIOR = "2024-11-30"
6+
START_DATE_PRIOR = "2024-12-01"
7+
END_DATE_PRIOR = "2024-12-31"
88
# The name of the folder in which to save the report
9-
PARENT_FOLDER_NAME = "December 2024 (demos)"
9+
PARENT_FOLDER_NAME = "January 2025"
1010

1111
# The name of the spreadsheet with the report
1212
SHEET_NAME = "HCA Explorer"
1313

14-
HCA_PORTAL_ID = "361323030"
14+
HCA_ID = "361323030"
1515
# Filter to exclude the Data Explorer
16-
HCA_BROWSER_EXCLUDE_FILTER = {"filter": {"fieldName": "hostName", "stringFilter": {"matchType": "EXACT", "value": "explore.data.humancellatlas.org"}}}
16+
HCA_BROWSER_ONLY_FILTER = {"filter": {"fieldName": "hostName", "stringFilter": {"matchType": "EXACT", "value": "explore.data.humancellatlas.org"}}}
1717
SECRET_NAME = "HCA_ANALYTICS_REPORTING_CLIENT_SECRET_PATH"
18-
ANALYTICS_START = "2021-01-01"
18+
ANALYTICS_START = "2024-02-01"
1919

2020
OAUTH_PORT = 8082

analytics/hca-explorer-sheets/generate_sheets_report.ipynb

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"from analytics import sheets_elements as elements\n",
2121
"from analytics import api as ga\n",
2222
"import pandas as pd\n",
23-
"from constants import *"
23+
"from constants import *\n",
24+
"import gspread"
2425
]
2526
},
2627
{
@@ -29,10 +30,11 @@
2930
"metadata": {},
3031
"outputs": [],
3132
"source": [
32-
"ga_authentication, drive_authentication = ga.authenticate(\n",
33+
"ga_authentication, drive_authentication, sheets_authentication = ga.authenticate(\n",
3334
" SECRET_NAME,\n",
3435
" ga.ga4_service_params,\n",
3536
" ga.drive_service_params,\n",
37+
" ga.sheets_service_params,\n",
3638
" port=OAUTH_PORT\n",
3739
")\n",
3840
"\n",
@@ -44,12 +46,16 @@
4446
" \"end_date\": END_DATE_CURRENT,\n",
4547
"}\n",
4648
"\n",
47-
"hca_portal_params = {\n",
49+
"hca_browser_params = {\n",
4850
" **default_params,\n",
49-
" \"base_dimension_filter\": HCA_BROWSER_EXCLUDE_FILTER,\n",
50-
" \"property\": HCA_PORTAL_ID,\n",
51+
" \"base_dimension_filter\": HCA_BROWSER_ONLY_FILTER,\n",
52+
" \"property\": HCA_ID,\n",
5153
"}\n",
52-
"\n"
54+
"\n",
55+
"hca_browser_params_all_time = {\n",
56+
" **hca_browser_params,\n",
57+
" \"start_date\": ANALYTICS_START,\n",
58+
"}"
5359
]
5460
},
5561
{
@@ -58,7 +64,9 @@
5864
"metadata": {},
5965
"outputs": [],
6066
"source": [
61-
"df_pageviews = elements.get_page_views_change(hca_portal_params, START_DATE_CURRENT, END_DATE_CURRENT, START_DATE_PRIOR, END_DATE_PRIOR) "
67+
"df_monthly_pageviews = elements.get_page_views_over_time_df(hca_browser_params_all_time)\n",
68+
"df_pageviews = elements.get_page_views_change(hca_browser_params, START_DATE_CURRENT, END_DATE_CURRENT, START_DATE_PRIOR, END_DATE_PRIOR) \n",
69+
"df_outbound = elements.get_outbound_links_change(hca_browser_params, START_DATE_CURRENT, END_DATE_CURRENT, START_DATE_PRIOR, END_DATE_PRIOR)"
6270
]
6371
},
6472
{
@@ -68,18 +76,28 @@
6876
"outputs": [],
6977
"source": [
7078
"dict_spreadsheet = {\n",
79+
" \"Explorer Summary\": df_monthly_pageviews,\n",
7180
" \"Page Views\": df_pageviews,\n",
81+
" \"Outbound Links\": df_outbound,\n",
7282
"}\n",
83+
"\n",
84+
"sheet = sheets.create_sheet_in_folder(\n",
85+
" drive_authentication,\n",
86+
" SHEET_NAME,\n",
87+
" PARENT_FOLDER_NAME,\n",
88+
" override_behavior=sheets.FILE_OVERRIDE_BEHAVIORS.OVERRIDE_IF_IN_SAME_PLACE\n",
89+
")\n",
90+
"\n",
7391
"sheets.fill_spreadsheet_with_df_dict(\n",
74-
" sheets.create_sheet_in_folder(\n",
75-
" drive_authentication,\n",
76-
" SHEET_NAME,\n",
77-
" PARENT_FOLDER_NAME,\n",
78-
" override_behavior=sheets.FILE_OVERRIDE_BEHAVIORS.OVERRIDE_IF_IN_SAME_PLACE\n",
79-
" ),\n",
92+
" sheet,\n",
8093
" dict_spreadsheet,\n",
8194
" sheets.FILE_OVERRIDE_BEHAVIORS.OVERRIDE_IF_IN_SAME_PLACE,\n",
8295
" column_formatting_options={\n",
96+
" \"Explorer Summary\": {\n",
97+
" \"Month\": sheets.COLUMN_FORMAT_OPTIONS.YEAR_MONTH_DATE,\n",
98+
" \"Users Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
99+
" \"Total Pageviews Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
100+
" },\n",
83101
" \"Outbound Links\": {\n",
84102
" \"Total Clicks Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
85103
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
@@ -88,8 +106,42 @@
88106
" \"Total Views Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
89107
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
90108
" }\n",
91-
"\n",
109+
" },\n",
110+
" sheet_formatting_options={\n",
111+
" \"Explorer Summary\": {\n",
112+
" \"extra_columns\": 1,\n",
113+
" \"extra_columns_width\": 2000\n",
114+
" }\n",
92115
" }\n",
116+
")\n",
117+
"\n",
118+
"monthly_traffic_worksheet = sheet.worksheet(\"Explorer Summary\")\n",
119+
"date_range = sheets.WorksheetRange(\n",
120+
" monthly_traffic_worksheet, \n",
121+
" gspread.cell.Cell(1, 1), \n",
122+
" gspread.cell.Cell(df_monthly_pageviews.index.size + 1, 2)\n",
123+
")\n",
124+
"users_range = sheets.WorksheetRange(\n",
125+
" monthly_traffic_worksheet, \n",
126+
" gspread.cell.Cell(1, 2), \n",
127+
" gspread.cell.Cell(df_monthly_pageviews.index.size + 1, 3)\n",
128+
")\n",
129+
"pageviews_range = sheets.WorksheetRange(\n",
130+
" monthly_traffic_worksheet, \n",
131+
" gspread.cell.Cell(1, 3), \n",
132+
" gspread.cell.Cell(df_monthly_pageviews.index.size + 1, 4)\n",
133+
")\n",
134+
"sheets.add_chart_to_sheet(\n",
135+
" sheets_authentication,\n",
136+
" sheet,\n",
137+
" monthly_traffic_worksheet,\n",
138+
" sheets.CHART_TYPES.LINE,\n",
139+
" date_range,\n",
140+
" [users_range, pageviews_range],\n",
141+
" chart_position=gspread.cell.Cell(1, 6),\n",
142+
" chart_position_offset_x=75,\n",
143+
" chart_position_offset_y=25,\n",
144+
" title=\"Pageviews and Users Over Time\"\n",
93145
")"
94146
]
95147
}

analytics/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
accessible-pygments==0.0.5
22
alabaster==0.7.16
3-
-e git+https://github.com/DataBiosphere/data-browser.git@e0ce2c7464107bbbc166f7e21fcc3c4426b6e553#egg=analytics&subdirectory=analytics/analytics_package
3+
-e git+https://github.com/DataBiosphere/data-browser.git@e2653f5605cc3220d28299bfc2cc48205c23067d#egg=analytics&subdirectory=analytics/analytics_package
44
anyio==4.7.0
55
appdirs==1.4.4
66
appnope==0.1.4

0 commit comments

Comments
 (0)