Update stats gathering functions#11844
Conversation
Removes all functions from `numbers.py` that return `0`. As all `admin_delta__*` functions have been removed, the code that calls these functions has been removed from `admin/stats.py`.
| total_edits = result[0].count | ||
| bot_ids = _get_cached_bot_accounts(thingdb=kargs['thingdb']) | ||
| q1 = ( | ||
| "SELECT count(DISTINCT t.id) AS count FROM transaction t, version v WHERE " |
There was a problem hiding this comment.
Note that this was counting distinct transaction IDs. The bot edits query uses count(*), which would count the same transaction ID multiple times.
This should now be moot, as the version table is no longer queried for these counts.
93aee05 to
bd32120
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the stats gathering functions in the admin module to improve accuracy and maintainability. It removes unimplemented stub functions, updates misleading documentation, adds bot account identification functionality, and simplifies the human/bot edit counting queries. The PR is marked as "DO NOT MERGE" and is a draft because it contains test values that must be replaced before production deployment.
Changes:
- Removes unimplemented
admin_delta__functions and their corresponding gathering logic - Adds new
get_bot_accounts()function to fetch bot account IDs from the database - Refactors
admin_range__human_edits()andadmin_range__bot_edits()to use the new bot account fetching mechanism - Updates documentation to fix typos and clarify function behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| openlibrary/admin/stats.py | Adds test prefixes to data storage (test-counts and test-admin-stats) and removes admin_delta__ function calls |
| openlibrary/admin/numbers.py | Adds bot account fetching functions, refactors human/bot edit counting, removes unimplemented functions, and updates documentation |
37e1986 to
0b18821
Compare
Removes notion of querying for bot accounts via the defunct `account` table. New functions that query the store for bot accounts have been created. `admin_range__human_edits` and `admin_range__bot_edits` have been updated to fetch bot accounts using the new functions. Additionally, a redundant DB query has been removed from `admin_range__human_edits`.
6534891 to
37b31d7
Compare
for more information, see https://pre-commit.ci
|
Data comparison data generated with this updated script: data generated with prod script: |
|
Noting that it took ~1 hour and 10 minutes to run this updated script for the previous 7 day's worth of counts. |
* Remove unimplemented stats functions Removes all functions from `numbers.py` that return `0`. As all `admin_delta__*` functions have been removed, the code that calls these functions has been removed from `admin/stats.py`. * Updates functions which count bot and human edits Removes notion of querying for bot accounts via the defunct `account` table. New functions that query the store for bot accounts have been created. `admin_range__human_edits` and `admin_range__bot_edits` have been updated to fetch bot accounts using the new functions. Additionally, a redundant DB query has been removed from `admin_range__human_edits`.
* Remove unimplemented stats functions Removes all functions from `numbers.py` that return `0`. As all `admin_delta__*` functions have been removed, the code that calls these functions has been removed from `admin/stats.py`. * Updates functions which count bot and human edits Removes notion of querying for bot accounts via the defunct `account` table. New functions that query the store for bot accounts have been created. `admin_range__human_edits` and `admin_range__bot_edits` have been updated to fetch bot accounts using the new functions. Additionally, a redundant DB query has been removed from `admin_range__human_edits`.
* Remove unimplemented stats functions Removes all functions from `numbers.py` that return `0`. As all `admin_delta__*` functions have been removed, the code that calls these functions has been removed from `admin/stats.py`. * Updates functions which count bot and human edits Removes notion of querying for bot accounts via the defunct `account` table. New functions that query the store for bot accounts have been created. `admin_range__human_edits` and `admin_range__bot_edits` have been updated to fetch bot accounts using the new functions. Additionally, a redundant DB query has been removed from `admin_range__human_edits`.
* Remove unimplemented stats functions Removes all functions from `numbers.py` that return `0`. As all `admin_delta__*` functions have been removed, the code that calls these functions has been removed from `admin/stats.py`. * Updates functions which count bot and human edits Removes notion of querying for bot accounts via the defunct `account` table. New functions that query the store for bot accounts have been created. `admin_range__human_edits` and `admin_range__bot_edits` have been updated to fetch bot accounts using the new functions. Additionally, a redundant DB query has been removed from `admin_range__human_edits`.
Supports #11714
Affects /stats page
Makes the following updates to our stats gathering functions:
thingIDs associated with bot accountsImportant Note: Functions that count the number of edits on the platform continue to count every transaction type as an edit. To fix this, we'll have to filter by
actiontype when querying thetransactiontable. I'm unsure if this filtering should be included in this PR. Some transactions are being misidentified today -- perhaps those should be fixed before filters are added to the queries.Technical
Testing
Can be tested by running
scripts/store_counts.pywith the expected arguments. Before running, it's best to update the following values inadmin/stats.py::store_data:openlibrary/openlibrary/admin/stats.py
Line 62 in b83bdda
Change to something like
"test-counts-%s" % dateto avoid clobbering existing data.openlibrary/openlibrary/admin/stats.py
Line 66 in b83bdda
Change to something like
"test-admin-stats"for easy clean-up after testing. With this change in place, you can delete the entries like this:The store entry created during testing can be compared to the most recent production
store_countsentry. Expect thetotal_*counts to be different -- human edits may be off a fair amount, while bot edits may differ slightly.Screenshot
Stakeholders