-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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)
- Loading branch information
Showing
4 changed files
with
202 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# CHANGE THESE VALUES TO GENERATE NEW REPORTS | ||
# The start and end dates of the current month (yyyy-mm-dd) | ||
START_DATE_CURRENT = "2024-12-01" | ||
END_DATE_CURRENT = "2024-12-31" | ||
# The start and end dates of the prior months | ||
START_DATE_PRIOR = "2024-11-01" | ||
END_DATE_PRIOR = "2024-11-30" | ||
# The name of the folder in which to save the report | ||
PARENT_FOLDER_NAME = "December 2024 (demos)" | ||
|
||
# The name of the spreadsheet with the report | ||
SHEET_NAME = "HCA Explorer" | ||
|
||
HCA_PORTAL_ID = "361323030" | ||
# Filter to exclude the Data Explorer | ||
HCA_BROWSER_EXCLUDE_FILTER = {"filter": {"fieldName": "hostName", "stringFilter": {"matchType": "EXACT", "value": "explore.data.humancellatlas.org"}}} | ||
SECRET_NAME = "HCA_ANALYTICS_REPORTING_CLIENT_SECRET_PATH" | ||
ANALYTICS_START = "2021-01-01" | ||
|
||
OAUTH_PORT = 8082 |
118 changes: 118 additions & 0 deletions
118
analytics/hca-explorer-sheets/generate_sheets_report.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Update this line to the path of your ga4 credentials. Make sure these are never stored in a version controlled folder.\n", | ||
"%env HCA_ANALYTICS_REPORTING_CLIENT_SECRET_PATH=../../../do_not_commit_ga4_credentials.json" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from analytics import sheets_api as sheets\n", | ||
"from analytics import sheets_elements as elements\n", | ||
"from analytics import api as ga\n", | ||
"import pandas as pd\n", | ||
"from constants import *" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ga_authentication, drive_authentication = ga.authenticate(\n", | ||
" SECRET_NAME,\n", | ||
" ga.ga4_service_params,\n", | ||
" ga.drive_service_params,\n", | ||
" port=OAUTH_PORT\n", | ||
")\n", | ||
"\n", | ||
"date_string = f\"{START_DATE_CURRENT} - {END_DATE_CURRENT}\"\n", | ||
"\n", | ||
"default_params = {\n", | ||
" \"service_system\": ga_authentication,\n", | ||
" \"start_date\": START_DATE_CURRENT,\n", | ||
" \"end_date\": END_DATE_CURRENT,\n", | ||
"}\n", | ||
"\n", | ||
"hca_portal_params = {\n", | ||
" **default_params,\n", | ||
" \"base_dimension_filter\": HCA_BROWSER_EXCLUDE_FILTER,\n", | ||
" \"property\": HCA_PORTAL_ID,\n", | ||
"}\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df_pageviews = elements.get_page_views_change(hca_portal_params, START_DATE_CURRENT, END_DATE_CURRENT, START_DATE_PRIOR, END_DATE_PRIOR) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dict_spreadsheet = {\n", | ||
" \"Page Views\": df_pageviews,\n", | ||
"}\n", | ||
"sheets.fill_spreadsheet_with_df_dict(\n", | ||
" sheets.create_sheet_in_folder(\n", | ||
" drive_authentication,\n", | ||
" SHEET_NAME,\n", | ||
" PARENT_FOLDER_NAME,\n", | ||
" override_behavior=sheets.FILE_OVERRIDE_BEHAVIORS.OVERRIDE_IF_IN_SAME_PLACE\n", | ||
" ),\n", | ||
" dict_spreadsheet,\n", | ||
" sheets.FILE_OVERRIDE_BEHAVIORS.OVERRIDE_IF_IN_SAME_PLACE,\n", | ||
" column_formatting_options={\n", | ||
" \"Outbound Links\": {\n", | ||
" \"Total Clicks Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n", | ||
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n", | ||
" },\n", | ||
" \"Page Views\": {\n", | ||
" \"Total Views Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n", | ||
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n", | ||
" }\n", | ||
"\n", | ||
" }\n", | ||
")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Installing the environment | ||
- Use Python 3.12.4 | ||
- Run `python -m venv ./venv` to create a new environment under `./venv`. | ||
- Run `source ./venv/bin/activate` to activate the environment. | ||
- Run `pip install -r ./requirements.txt` to install requirements. | ||
|
||
## Deactivating/reactivating | ||
- To deactivate the environment, run `deactivate`. | ||
- To activate the environment again, run `source ./venv/bin/activate`. | ||
|
||
## Generating Reports | ||
- Update `constants.py` to reflect the date ranges and file name you would like for the report | ||
- Open `./generate_sheets_report.ipynb` using your favorite IDE or by running `jupyter notebook` and selecting it from the browser window that appears. | ||
- Add a path to your Google Cloud credentials in the first cell as instructed by the comments. | ||
- 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. | ||
- Check your Google Drive to ensure that the desired spreadsheet is present. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters