Skip to content

Commit efc0ff8

Browse files
author
Jonah Paten
authored
feat: page view report for hca data explorer (#4354)
* feat: created analytics sheets notebook for hca browser (#4317) * chore: updated analytics package version to 3.3.1 (#4317)
1 parent ba3d866 commit efc0ff8

File tree

4 files changed

+202
-1
lines changed

4 files changed

+202
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# CHANGE THESE VALUES TO GENERATE NEW REPORTS
2+
# 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"
5+
# The start and end dates of the prior months
6+
START_DATE_PRIOR = "2024-11-01"
7+
END_DATE_PRIOR = "2024-11-30"
8+
# The name of the folder in which to save the report
9+
PARENT_FOLDER_NAME = "December 2024 (demos)"
10+
11+
# The name of the spreadsheet with the report
12+
SHEET_NAME = "HCA Explorer"
13+
14+
HCA_PORTAL_ID = "361323030"
15+
# Filter to exclude the Data Explorer
16+
HCA_BROWSER_EXCLUDE_FILTER = {"filter": {"fieldName": "hostName", "stringFilter": {"matchType": "EXACT", "value": "explore.data.humancellatlas.org"}}}
17+
SECRET_NAME = "HCA_ANALYTICS_REPORTING_CLIENT_SECRET_PATH"
18+
ANALYTICS_START = "2021-01-01"
19+
20+
OAUTH_PORT = 8082
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# Update this line to the path of your ga4 credentials. Make sure these are never stored in a version controlled folder.\n",
10+
"%env HCA_ANALYTICS_REPORTING_CLIENT_SECRET_PATH=../../../do_not_commit_ga4_credentials.json"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"from analytics import sheets_api as sheets\n",
20+
"from analytics import sheets_elements as elements\n",
21+
"from analytics import api as ga\n",
22+
"import pandas as pd\n",
23+
"from constants import *"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": null,
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"ga_authentication, drive_authentication = ga.authenticate(\n",
33+
" SECRET_NAME,\n",
34+
" ga.ga4_service_params,\n",
35+
" ga.drive_service_params,\n",
36+
" port=OAUTH_PORT\n",
37+
")\n",
38+
"\n",
39+
"date_string = f\"{START_DATE_CURRENT} - {END_DATE_CURRENT}\"\n",
40+
"\n",
41+
"default_params = {\n",
42+
" \"service_system\": ga_authentication,\n",
43+
" \"start_date\": START_DATE_CURRENT,\n",
44+
" \"end_date\": END_DATE_CURRENT,\n",
45+
"}\n",
46+
"\n",
47+
"hca_portal_params = {\n",
48+
" **default_params,\n",
49+
" \"base_dimension_filter\": HCA_BROWSER_EXCLUDE_FILTER,\n",
50+
" \"property\": HCA_PORTAL_ID,\n",
51+
"}\n",
52+
"\n"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"metadata": {},
59+
"outputs": [],
60+
"source": [
61+
"df_pageviews = elements.get_page_views_change(hca_portal_params, START_DATE_CURRENT, END_DATE_CURRENT, START_DATE_PRIOR, END_DATE_PRIOR) "
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"dict_spreadsheet = {\n",
71+
" \"Page Views\": df_pageviews,\n",
72+
"}\n",
73+
"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",
80+
" dict_spreadsheet,\n",
81+
" sheets.FILE_OVERRIDE_BEHAVIORS.OVERRIDE_IF_IN_SAME_PLACE,\n",
82+
" column_formatting_options={\n",
83+
" \"Outbound Links\": {\n",
84+
" \"Total Clicks Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
85+
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
86+
" },\n",
87+
" \"Page Views\": {\n",
88+
" \"Total Views Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
89+
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
90+
" }\n",
91+
"\n",
92+
" }\n",
93+
")"
94+
]
95+
}
96+
],
97+
"metadata": {
98+
"kernelspec": {
99+
"display_name": "venv",
100+
"language": "python",
101+
"name": "python3"
102+
},
103+
"language_info": {
104+
"codemirror_mode": {
105+
"name": "ipython",
106+
"version": 3
107+
},
108+
"file_extension": ".py",
109+
"mimetype": "text/x-python",
110+
"name": "python",
111+
"nbconvert_exporter": "python",
112+
"pygments_lexer": "ipython3",
113+
"version": "3.12.8"
114+
}
115+
},
116+
"nbformat": 4,
117+
"nbformat_minor": 4
118+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Installing the environment
2+
- Use Python 3.12.4
3+
- Run `python -m venv ./venv` to create a new environment under `./venv`.
4+
- Run `source ./venv/bin/activate` to activate the environment.
5+
- Run `pip install -r ./requirements.txt` to install requirements.
6+
7+
## Deactivating/reactivating
8+
- To deactivate the environment, run `deactivate`.
9+
- To activate the environment again, run `source ./venv/bin/activate`.
10+
11+
## Generating Reports
12+
- Update `constants.py` to reflect the date ranges and file name you would like for the report
13+
- Open `./generate_sheets_report.ipynb` using your favorite IDE or by running `jupyter notebook` and selecting it from the browser window that appears.
14+
- Add a path to your Google Cloud credentials in the first cell as instructed by the comments.
15+
- Run all cells in the Jupyter notebook by pressing the button with two arrows at the top. You will be prompted to log in to your Google Account, which must have access to the relevant analytics property.
16+
- Check your Google Drive to ensure that the desired spreadsheet is present.

analytics/requirements.txt

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
accessible-pygments==0.0.5
22
alabaster==0.7.16
3-
-e git+https://github.com/DataBiosphere/data-browser.git@60dc83eb36468c1f8091136f8e0534b3cba81b44#egg=analytics&subdirectory=analytics/analytics_package
3+
-e git+https://github.com/DataBiosphere/data-browser.git@e0ce2c7464107bbbc166f7e21fcc3c4426b6e553#egg=analytics&subdirectory=analytics/analytics_package
4+
anyio==4.7.0
45
appdirs==1.4.4
56
appnope==0.1.4
7+
argon2-cffi==23.1.0
8+
argon2-cffi-bindings==21.2.0
9+
arrow==1.3.0
610
asttokens==2.4.1
11+
async-lru==2.0.4
712
attrs==24.2.0
813
babel==2.16.0
914
beautifulsoup4==4.12.3
15+
bleach==6.2.0
1016
cachetools==5.5.0
1117
certifi==2024.8.30
18+
cffi==1.17.1
1219
charset-normalizer==3.3.2
1320
click==8.1.7
1421
comm==0.2.2
1522
contourpy==1.3.0
1623
cycler==0.12.1
1724
debugpy==1.8.5
1825
decorator==5.1.1
26+
defusedxml==0.7.1
1927
docutils==0.20.1
2028
executing==2.1.0
2129
fastjsonschema==2.20.0
2230
fonttools==4.53.1
31+
fqdn==1.5.1
2332
google-api-core==2.19.2
2433
google-api-python-client==2.146.0
2534
google-auth==2.34.0
@@ -28,20 +37,37 @@ google-auth-oauthlib==1.2.1
2837
googleapis-common-protos==1.65.0
2938
gspread==6.1.4
3039
gspread-formatting==1.2.0
40+
h11==0.14.0
41+
httpcore==1.0.7
3142
httplib2==0.22.0
43+
httpx==0.28.1
3244
idna==3.10
3345
imagesize==1.4.1
3446
importlib_metadata==8.5.0
3547
ipykernel==6.29.5
3648
ipython==8.27.0
49+
ipywidgets==8.1.5
50+
isoduration==20.11.0
3751
jedi==0.19.1
3852
Jinja2==3.1.4
53+
json5==0.10.0
54+
jsonpointer==3.0.0
3955
jsonschema==4.23.0
4056
jsonschema-specifications==2023.12.1
57+
jupyter==1.1.1
4158
jupyter-book==1.0.2
4259
jupyter-cache==1.0.0
60+
jupyter-console==6.6.3
61+
jupyter-events==0.10.0
62+
jupyter-lsp==2.2.5
4363
jupyter_client==8.6.3
4464
jupyter_core==5.7.2
65+
jupyter_server==2.14.2
66+
jupyter_server_terminals==0.5.3
67+
jupyterlab==4.3.3
68+
jupyterlab_pygments==0.3.0
69+
jupyterlab_server==2.27.3
70+
jupyterlab_widgets==3.0.13
4571
kiwisolver==1.4.7
4672
latexcodec==3.0.0
4773
linkify-it-py==2.0.3
@@ -51,19 +77,26 @@ matplotlib==3.9.2
5177
matplotlib-inline==0.1.7
5278
mdit-py-plugins==0.4.2
5379
mdurl==0.1.2
80+
mistune==3.0.2
5481
myst-nb==1.1.1
5582
myst-parser==2.0.0
5683
nbclient==0.10.0
84+
nbconvert==7.16.4
5785
nbformat==5.10.4
5886
nest-asyncio==1.6.0
87+
notebook==7.3.1
88+
notebook_shim==0.2.4
5989
numpy==2.1.1
6090
oauthlib==3.2.2
91+
overrides==7.7.0
6192
packaging==24.1
6293
pandas==2.2.2
94+
pandocfilters==1.5.1
6395
parso==0.8.4
6496
pexpect==4.9.0
6597
pillow==10.4.0
6698
platformdirs==4.3.6
99+
prometheus_client==0.21.1
67100
prompt_toolkit==3.0.47
68101
proto-plus==1.24.0
69102
protobuf==5.28.1
@@ -74,22 +107,28 @@ pyasn1==0.6.1
74107
pyasn1_modules==0.4.1
75108
pybtex==0.24.0
76109
pybtex-docutils==1.0.3
110+
pycparser==2.22
77111
pydata-sphinx-theme==0.15.4
78112
pyee==11.1.1
79113
Pygments==2.18.0
80114
pyparsing==3.1.4
81115
pyppeteer==2.0.0
82116
python-dateutil==2.9.0.post0
117+
python-json-logger==3.2.1
83118
pytz==2024.2
84119
PyYAML==6.0.2
85120
pyzmq==26.2.0
86121
referencing==0.35.1
87122
requests==2.32.3
88123
requests-oauthlib==2.0.0
124+
rfc3339-validator==0.1.4
125+
rfc3986-validator==0.1.1
89126
rpds-py==0.20.0
90127
rsa==4.9
128+
Send2Trash==1.8.3
91129
setuptools==75.1.0
92130
six==1.16.0
131+
sniffio==1.3.1
93132
snowballstemmer==2.2.0
94133
soupsieve==2.6
95134
Sphinx==7.4.7
@@ -112,15 +151,23 @@ sphinxcontrib-serializinghtml==2.0.0
112151
SQLAlchemy==2.0.35
113152
stack-data==0.6.3
114153
tabulate==0.9.0
154+
terminado==0.18.1
155+
tinycss2==1.4.0
115156
tornado==6.4.1
116157
tqdm==4.66.5
117158
traitlets==5.14.3
159+
types-python-dateutil==2.9.0.20241206
118160
typing_extensions==4.12.2
119161
tzdata==2024.1
120162
uc-micro-py==1.0.3
163+
uri-template==1.3.0
121164
uritemplate==4.1.1
122165
urllib3==1.26.20
123166
wcwidth==0.2.13
167+
webcolors==24.11.1
168+
webencodings==0.5.1
169+
websocket-client==1.8.0
124170
websockets==10.4
125171
wheel==0.44.0
172+
widgetsnbextension==4.0.13
126173
zipp==3.20.2

0 commit comments

Comments
 (0)