An effort by eLife Sciences to provide a data store and API for accessing article-level metrics (views, downloads, citations).
This project uses the Python programming language, the Django web framework and a relational database.
API documentation can be found here:
For example, the Homo Naledi article:
would yield a response similar to:
{"total":1,"items":[{"id":9560,"views":227913,"downloads":16498,"crossref":103,"pubmed":21,"scopus":52}]}
Docker Docker Compose
The service has dependencies on the following 3rd party services:
crossref
scopus
Google Analytics
Each of these require credentials to be set in the environment. You will need to set these up in your local environment in order to ingest/generate metrics data locally.
In the .docker/app.cfg
file, you will need to set the following variables with real values:
```
[scopus]
apikey:
[crossref]
user: ``
For Google Analytics, you will need to provide a
client_secrets.jsonfile in the
.docker` directory of the project.
Example .docker/client-secrets.json
file:
json
{
"private_key_id": "<private_key_id>",
"private_key": "<private_key>",
"client_id": "<client_id>",
"client_email": "<client_email>",
"type": "service_account"
}
...
If you want to seed the local database with some data, one way is to populate the .docker/pg_import_data.sql
file with the
desired contents. In a later step you can execute the import command to load the data into the database.
bash
make build
bash
make run
bash
make import-data
```bash make stop ````
bash
make lint
bash
make test
To download a list of PMCIDs and create the relevant articles in the db run:
bash
make fetch-articles
To fetch metrics for the articles in the db:
bash
make fetch-metrics
You can also pass in the number of days and months to look back for metrics data should you need to:
bash
docker compose exec app bash -c "python src/manage.py ingest_metrics --days 999 --months 999"
(If not provided, the defaults at the time of writing are 5 days and 2 months)
For use as a debugging utility, to fetch citation counts for all versions of an article (currently Crossref only) run:
bash
make fetch-citation-counts-for-article ARTICLE_ID="85111"
(note this does not persist the data in the database)
Example output: ``` Article with id 85111 exists INFO - fetching crossref citations for 10.7554/eLife.85111 INFO - fetching crossref citations for 10.7554/eLife.85111.1 INFO - fetching crossref citations for 10.7554/eLife.85111.2 INFO - fetching crossref citations for 10.7554/eLife.85111.3
Citation data for 85111: [ {'doi': '10.7554/eLife.85111', 'num': 16, 'source': 'crossref', 'source_id': 'https://doi.org/10.7554/eLife.85111'}, {'doi': '10.7554/eLife.85111.1', 'num': 12, 'source': 'crossref', 'source_id': 'https://doi.org/10.7554/eLife.85111.1'}, {'doi': '10.7554/eLife.85111.2', 'num': 3, 'source': 'crossref', 'source_id': 'https://doi.org/10.7554/eLife.85111.2'}, {'doi': '10.7554/eLife.85111.3', 'num': 3, 'source': 'crossref', 'source_id': 'https://doi.org/10.7554/eLife.85111.3'} ]
Combined citation data for 85111: { 'doi': '10.7554/eLife.85111', 'num': 34, 'source': 'crossref', 'source_id': 'https://doi.org/10.7554/eLife.85111' } ```
git clone https://github.com/elifesciences/elife-metrics
cd elife-metrics
./install.sh
git pull
./install.sh
./migrate.sh
./project_tests.sh
./manage.sh runserver
firefox http://127.0.0.1:8000/api/docs/
Copyright 2016-2024 eLife Sciences. Licensed under the GPLv3
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.