|
2 | 2 |
|
3 | 3 | # ckanext-scientometrics |
4 | 4 |
|
5 | | -**TODO:** Put a description of your extension here: What does it do? What features does it have? Consider including some screenshots or embedding a video! |
| 5 | +Scientometrics metrics for CKAN users. The extension lets you: |
6 | 6 |
|
| 7 | +- store author identifiers (per source) in user extras (`plugin_extras`) |
| 8 | +- fetch author-level metrics from external providers |
| 9 | +- persist fetched metrics in dedicated DB tables |
| 10 | +- display selected metrics on the user page |
7 | 11 |
|
8 | | -## Requirements |
| 12 | +Supported sources (as implemented): |
9 | 13 |
|
10 | | -**TODO:** For example, you might want to mention here which versions of CKAN this |
11 | | -extension works with. |
| 14 | +- Google Scholar (author profile metrics) |
| 15 | +- Semantic Scholar (author metrics) |
| 16 | +- OpenAlex (author metrics) |
12 | 17 |
|
13 | | -If your extension works across different versions you can add the following table: |
| 18 | +## How it works |
14 | 19 |
|
15 | | -Compatibility with core CKAN versions: |
| 20 | +- User author identifiers are stored in the user `plugin_extras` under `scim`: |
| 21 | + keys like `<source>_author_id` (e.g. `google_scholar_author_id`). |
| 22 | +- Metrics are fetched via per-source extractors and stored in: |
| 23 | + - `scim_user_metric` (per user + source) |
| 24 | + - `scim_dataset_metric` (reserved for dataset metrics; currently only model/migration exist) |
| 25 | +- The user page template can render cards for enabled sources using the stored metrics. |
16 | 26 |
|
17 | | -| CKAN version | Compatible? | |
18 | | -| --------------- | ------------- | |
19 | | -| 2.6 and earlier | not tested | |
20 | | -| 2.7 | not tested | |
21 | | -| 2.8 | not tested | |
22 | | -| 2.9 | not tested | |
| 27 | +## Usage |
23 | 28 |
|
24 | | -Suggested values: |
| 29 | +### 1) Configure enabled sources |
25 | 30 |
|
26 | | -* "yes" |
27 | | -* "not tested" - I can't think of a reason why it wouldn't work |
28 | | -* "not yet" - there is an intention to get it working |
29 | | -* "no" |
| 31 | +Enable the plugin in CKAN config: |
30 | 32 |
|
| 33 | +```ini |
| 34 | +ckan.plugins = ... scientometrics |
| 35 | +``` |
31 | 36 |
|
32 | | -## Installation |
| 37 | +Configure which metric sources are enabled: |
33 | 38 |
|
34 | | -**TODO:** Add any additional install steps to the list below. |
35 | | - For example installing any non-Python dependencies or adding any required |
36 | | - config settings. |
| 39 | +```ini |
| 40 | +ckanext.scientometrics.enabled_metrics = google_scholar semantic_scholar openalex |
| 41 | +ckanext.scientometrics.show_on_user_page = true |
| 42 | +``` |
37 | 43 |
|
38 | | -To install ckanext-scientometrics: |
| 44 | +### 2) Add author IDs to a user |
39 | 45 |
|
40 | | -1. Activate your CKAN virtual environment, for example: |
| 46 | +In the user edit form, the extension adds extra fields (one per enabled source). |
| 47 | +The values are stored under `plugin_extras["scim"]` as: |
41 | 48 |
|
42 | | - . /usr/lib/ckan/default/bin/activate |
| 49 | +- `google_scholar_author_id` |
| 50 | +- `semantic_scholar_author_id` |
| 51 | +- `openalex_author_id` |
43 | 52 |
|
44 | | -2. Clone the source and install it on the virtualenv |
| 53 | +### 3) Update metrics for a user (action) |
45 | 54 |
|
46 | | - git clone https://github.com/aleks-iv/ckanext-scientometrics.git |
47 | | - cd ckanext-scientometrics |
48 | | - pip install -e . |
49 | | - pip install -r requirements.txt |
| 55 | +The extension provides actions to fetch and store metrics. A typical call: |
50 | 56 |
|
51 | | -3. Add `scientometrics` to the `ckan.plugins` setting in your CKAN |
52 | | - config file (by default the config file is located at |
53 | | - `/etc/ckan/default/ckan.ini`). |
| 57 | +- `scim_update_user_metrics` with: |
| 58 | + - `user_id` (id or name) |
| 59 | + - `requested_sources` (optional list of sources; defaults to enabled sources) |
54 | 60 |
|
55 | | -4. Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu: |
| 61 | +Stored records are keyed by `(user_id, source)` in `scim_user_metric`. |
56 | 62 |
|
57 | | - sudo service apache2 reload |
| 63 | +To retrieve stored metrics: |
58 | 64 |
|
| 65 | +- `scim_get_user_metrics` with: |
| 66 | + - `user_id` |
59 | 67 |
|
60 | | -## Config settings |
| 68 | +Returns a dict keyed by `source`, where each value is built from the stored JSON metrics |
| 69 | +plus metadata like status and external references (when present). |
61 | 70 |
|
62 | | -None at present |
| 71 | +### 4) Update metrics for all users (CLI) |
63 | 72 |
|
64 | | -**TODO:** Document any optional config settings here. For example: |
| 73 | +The extension exposes a CLI command: |
65 | 74 |
|
66 | | - # The minimum number of hours to wait before re-checking a resource |
67 | | - # (optional, default: 24). |
68 | | - ckanext.scientometrics.some_setting = some_default_value |
| 75 | +```bash |
| 76 | +ckan scim update-user-metrics |
| 77 | +``` |
69 | 78 |
|
| 79 | +Options: |
70 | 80 |
|
71 | | -## Developer installation |
| 81 | +- `--user-ids <id>` (repeatable): update only specified user IDs |
| 82 | +- `--requested-sources <source>` (repeatable): update only specified sources |
72 | 83 |
|
73 | | -To install ckanext-scientometrics for development, activate your CKAN virtualenv and |
74 | | -do: |
| 84 | +If no `--user-ids` are provided, it updates all users. |
75 | 85 |
|
76 | | - git clone https://github.com/aleks-iv/ckanext-scientometrics.git |
77 | | - cd ckanext-scientometrics |
78 | | - python setup.py develop |
79 | | - pip install -r dev-requirements.txt |
| 86 | +## Database |
80 | 87 |
|
| 88 | +This extension creates two tables: |
81 | 89 |
|
82 | | -## Tests |
| 90 | +- `scim_user_metric` |
| 91 | + - unique constraint: `(user_id, source)` |
| 92 | + - stores: |
| 93 | + - `metrics` (JSONB) |
| 94 | + - `external_id`, `external_url` |
| 95 | + - `status` |
| 96 | + - timestamps |
| 97 | + - `extras` (JSONB for future metadata) |
| 98 | + |
| 99 | +- `scim_dataset_metric` |
| 100 | + - unique constraint: `(package_id, source)` |
| 101 | + - same structure as user metrics table |
| 102 | + |
| 103 | +Foreign keys are configured with `ondelete="CASCADE"`. |
| 104 | + |
| 105 | +## Requirements |
| 106 | + |
| 107 | +Compatibility with core CKAN versions: |
| 108 | + |
| 109 | +| CKAN version | Compatible? | |
| 110 | +| --------------- | ------------- | |
| 111 | +| 2.9 and earlier | no | |
| 112 | +| 2.10+ | yes | |
83 | 113 |
|
84 | | -To run the tests, do: |
| 114 | +(Tests run in CI on a CKAN 2.11 container.) |
85 | 115 |
|
86 | | - pytest --ckan-ini=test.ini |
| 116 | +## Installation |
87 | 117 |
|
| 118 | +To install ckanext-scientometrics: |
88 | 119 |
|
89 | | -## Releasing a new version of ckanext-scientometrics |
| 120 | +1. Activate your CKAN virtual environment, for example: |
90 | 121 |
|
91 | | -If ckanext-scientometrics should be available on PyPI you can follow these steps to publish a new version: |
| 122 | + ```bash |
| 123 | + . /usr/lib/ckan/default/bin/activate |
| 124 | + ``` |
92 | 125 |
|
93 | | -1. Update the version number in the `setup.py` file. See [PEP 440](http://legacy.python.org/dev/peps/pep-0440/#public-version-identifiers) for how to choose version numbers. |
| 126 | +2. Clone the source and install it on the virtualenv: |
94 | 127 |
|
95 | | -2. Make sure you have the latest version of necessary packages: |
| 128 | + ```bash |
| 129 | + git clone https://github.com/aleks-iv/ckanext-scientometrics.git |
| 130 | + cd ckanext-scientometrics |
| 131 | + pip install -e . |
| 132 | + pip install -r requirements.txt |
| 133 | + ``` |
96 | 134 |
|
97 | | - pip install --upgrade setuptools wheel twine |
| 135 | +3. Add `scientometrics` to the `ckan.plugins` setting in your CKAN config file |
| 136 | + (by default `/etc/ckan/default/ckan.ini`). |
98 | 137 |
|
99 | | -3. Create a source and binary distributions of the new version: |
| 138 | +4. Restart CKAN (eg on Ubuntu + Apache): |
100 | 139 |
|
101 | | - python setup.py sdist bdist_wheel && twine check dist/* |
| 140 | + ```bash |
| 141 | + sudo service apache2 reload |
| 142 | + ``` |
102 | 143 |
|
103 | | - Fix any errors you get. |
| 144 | +## Config settings |
104 | 145 |
|
105 | | -4. Upload the source distribution to PyPI: |
| 146 | +- `ckanext.scientometrics.enabled_metrics` (type: list) |
| 147 | + - default: `google_scholar semantic_scholar openalex` |
| 148 | + - enabled sources; controls which user fields are shown and which sources can be updated |
106 | 149 |
|
107 | | - twine upload dist/* |
| 150 | +- `ckanext.scientometrics.show_on_user_page` (type: bool) |
| 151 | + - default: `true` |
| 152 | + - show metrics cards on the user page |
108 | 153 |
|
109 | | -5. Commit any outstanding changes: |
| 154 | +Example: |
110 | 155 |
|
111 | | - git commit -a |
112 | | - git push |
| 156 | +```ini |
| 157 | +ckan.plugins = ... scientometrics |
| 158 | + |
| 159 | +ckanext.scientometrics.enabled_metrics = openalex semantic_scholar |
| 160 | +ckanext.scientometrics.show_on_user_page = true |
| 161 | +``` |
| 162 | + |
| 163 | +## Developer installation |
| 164 | + |
| 165 | +To install for development: |
| 166 | + |
| 167 | +```bash |
| 168 | +git clone https://github.com/aleks-iv/ckanext-scientometrics.git |
| 169 | +cd ckanext-scientometrics |
| 170 | +pip install -e . |
| 171 | +pip install -r dev-requirements.txt |
| 172 | +``` |
| 173 | + |
| 174 | +## Tests |
113 | 175 |
|
114 | | -6. Tag the new release of the project on GitHub with the version number from |
115 | | - the `setup.py` file. For example if the version number in `setup.py` is |
116 | | - 0.0.1 then do: |
| 176 | +To run tests: |
117 | 177 |
|
118 | | - git tag 0.0.1 |
119 | | - git push --tags |
| 178 | +```bash |
| 179 | +pytest --ckan-ini=test.ini |
| 180 | +``` |
120 | 181 |
|
121 | 182 | ## License |
122 | 183 |
|
|
0 commit comments