-
Notifications
You must be signed in to change notification settings - Fork 119
Add RTD stats collection #764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JessicaS11
wants to merge
9
commits into
development
Choose a base branch
from
rtd-stats
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec7da0d
add read the docs analytics gh action
JessicaS11 f20ca80
add started python code to get rtd analytics (totally untested)
JessicaS11 abbca7a
add rtd data file
JessicaS11 4b70a7f
add csv files to gitignore exception and add vscode
JessicaS11 6b1e1e0
add read-the-docs environment for action
JessicaS11 cda933e
update python script given api doesn't provide analytics data
JessicaS11 7b27942
add searches data and deactivate action cron
JessicaS11 5218f00
update python function and notes
JessicaS11 9756a33
add searches csv to precommit codespell exception for misspelled sear…
JessicaS11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,45 @@ | ||
| # holder action for if/when RTD Analytics has an API endpoint (not implemented as of June 2026) | ||
| name: Get Read the Docs (RTD) analytics | ||
| on: | ||
| # schedule: | ||
| # # runs once a month on the first | ||
| # - cron: "55 20 1 * *" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| # This workflow contains a single job called "rtd_stats" | ||
| rtd_stats: | ||
| # The type of runner that the job will run on | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: read-the-docs | ||
| permissions: | ||
| contents: write # for Git to git push | ||
| if: github.repository_owner == 'icesat2py' | ||
|
|
||
| # Steps represent a sequence of tasks that will be executed as part of the job | ||
| steps: | ||
| # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| ref: "traffic" | ||
| persist-credentials: true | ||
|
|
||
| # Pulls RTD stats, adds them to existing CSV file | ||
| - name: Update rtd stats files | ||
| env: | ||
| RTD_API_TOKEN: ${{ secrets.RTD_API_TOKEN }} | ||
| run: | | ||
| pip install -U pip | ||
| pip install -r requirements.txt | ||
| python ./doc/source/tracking/rtdstats/get_rtd_stats.py | ||
|
|
||
| # Commits files to repository | ||
| - name: Commit changes | ||
| uses: EndBug/add-and-commit@290ea2c423ad77ca9c62ae0f5b224379612c0321 # v10.0.0 | ||
| with: | ||
| author_name: Jessica Scheick | ||
| message: "RTD analytics auto-update" | ||
| add: "./doc/source/tracking/rtdstats/*" | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,86 @@ | ||
| import os | ||
|
|
||
| import pandas as pd | ||
|
|
||
| cwd = os.getcwd() | ||
|
|
||
| trackpath = f"{cwd}/doc/source/tracking/rtdstats/" | ||
| pageviewfn = "pageview_data.csv" | ||
| searchfn = "searches_data.csv" | ||
|
|
||
| # rtd_token = os.environ["RTD_API_TOKEN"] | ||
| # headers = {"Authorization": f"Token {rtd_token}"} | ||
| # base = "https://app.readthedocs.org" | ||
|
|
||
|
|
||
| # Turns out you cannot yet get the analytics data from the API, only the UI | ||
| # This function has the scaffolding to get the data if it's ever implemented | ||
| # def fetch_rtd_analytics(url, headers, output_path=None): | ||
| # """Fetch analytics from a Read the Docs URL and return a DataFrame.""" | ||
| # try: | ||
| # resp = requests.get(url, headers=headers, timeout=30) | ||
| # data = resp.json() | ||
| # except Exception: | ||
| # return None | ||
|
|
||
| # if not resp.ok: | ||
| # return None | ||
|
|
||
| # if isinstance(data, dict) and "results" in data: | ||
| # results = data.get("results", []) | ||
| # if results: | ||
| # df = pd.json_normalize(results) | ||
| # if output_path: | ||
| # df.to_csv(output_path, index=False) | ||
| # return df | ||
| # return None | ||
|
|
||
| # if isinstance(data, list): | ||
| # df = pd.json_normalize(data) | ||
| # if output_path: | ||
| # df.to_csv(output_path, index=False) | ||
| # return df | ||
|
|
||
| # return None | ||
|
|
||
|
|
||
| ### Collect the analytics data and combine it with whatever already exists | ||
| ### must manually download the csv and rename it to `pageview.csv` | ||
| # pageviews = fetch_rtd_analytics( | ||
| # f"{base}/api/v3/projects/icepyx/", headers | ||
| # ) | ||
| pageviews = pd.read_csv(trackpath + "pageview.csv") | ||
| exist_pageviews = pd.read_csv(trackpath + pageviewfn) | ||
|
|
||
| pageviews = pageviews.merge( | ||
| exist_pageviews, how="outer", on=["Path", "Date", "Version", "Views"] | ||
| ) | ||
|
|
||
| # remove duplicate entries; sort default is ascending | ||
| pageviews = pageviews.sort_values(["Date"], ignore_index=True).drop_duplicates( | ||
| subset=["Date", "Version", "Path"], keep="last" | ||
| ) | ||
|
|
||
| pageviews.sort_values(["Date"], ignore_index=True).to_csv( | ||
| trackpath + pageviewfn, index=False | ||
| ) | ||
|
|
||
| # see which pages have most views | ||
| print(pageviews.groupby("Path").sum().sort_values(["Views"], ascending=False)) | ||
|
|
||
|
|
||
| # searches = fetch_rtd_analytics(f"{base}/api/v3/projects/icepyx/search-terms/", headers) | ||
|
|
||
| searches = pd.read_csv(trackpath + "searches.csv") | ||
| exist_searches = pd.read_csv(trackpath + searchfn) | ||
|
|
||
| searches = searches.merge( | ||
| exist_searches, how="outer", on=["Created Date", "Query", "Total Results"] | ||
| ) | ||
|
|
||
| searches.sort_values(["Query"], ignore_index=True).to_csv( | ||
| trackpath + searchfn, index=False | ||
| ) | ||
|
|
||
| # print out what most common query words are | ||
| print(searches.groupby("Query").count()) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.