Skip to content

Commit

Permalink
statistics: add resource StatConfiguration
Browse files Browse the repository at this point in the history
* Adds REST configuration.
* Adds specific permissions.

Co-Authored-by: Valeria Granata <[email protected]>
Co-Authored-by: Renaud Michotte [email protected]
Co-Authored-by: Johnny Mariéthoz <[email protected]>
Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
3 people committed Sep 21, 2023
1 parent b1fce89 commit d4eb5dd
Show file tree
Hide file tree
Showing 26 changed files with 2,240 additions and 3 deletions.
12 changes: 12 additions & 0 deletions data/role_policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,18 @@
"pro_read_only",
"pro_full_permissions"
],
"stat_cfg-access": [
"pro_full_permissions",
"pro_statistics_manager"
],
"stat_cfg-search": [
"pro_full_permissions",
"pro_statistics_manager"
],
"stat_cfg-read": [
"pro_full_permissions",
"pro_statistics_manager"
],
"tmpl-access": [
"pro_full_permissions",
"pro_library_administrator",
Expand Down
232 changes: 232 additions & 0 deletions data/stats_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
[
{
"pid": "1",
"name": "organisation 1, no distributions",
"description": "Statistics configuration with no distributions",
"category": {
"type": "catalogue",
"indicator": {
"type": "number_of_documents"
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/1"
},
"frequency": "month",
"is_active": true
},
{
"pid": "2",
"name": "organisation 1, circulation, number of checkouts, time range month",
"description": "Statistics configuration with 1 distribution",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkouts",
"distributions": [
"time_range_month"
]
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/1"
},
"frequency": "month",
"is_active": true
},
{
"pid": "3",
"name": "organisation 1, number of checkouts, library",
"description": "Statistics configuration with 1 distribution",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkouts",
"distributions": [
"library"
]
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/1"
},
"frequency": "month",
"is_active": true
},
{
"pid": "4",
"name": "organisation 1, 2 distributions",
"description": "Statistics configuration with 2 distributions",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkins",
"distributions": [
"document_type",
"transaction_channel"
]
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/1"
},
"frequency": "month",
"is_active": true
},
{
"pid": "5",
"name": "organisation 1, 2 distributions, period 1 year",
"description": "Statistics configuration with 2 distributions",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkins",
"distributions": [
"document_type",
"transaction_channel"
],
"period": "year"
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/1"
},
"frequency": "month",
"is_active": true
},
{
"pid": "6",
"name": "organisation 1, 2 distributions, status disabled",
"description": "Statistics configuration with 2 distributions",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkins",
"distributions": [
"document_type",
"transaction_channel"
]
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/1"
},
"frequency": "month",
"is_active": false
},
{
"pid": "7",
"name": "organisation 2, no distributions",
"description": "Statistics configuration with no distributions",
"category": {
"type": "catalogue",
"indicator": {
"type": "number_of_documents"
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/2"
},
"frequency": "month",
"is_active": true
},
{
"pid": "8",
"name": "organisation 2, 1 distribution",
"description": "Statistics configuration with 1 distribution",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkouts",
"distributions": [
"time_range_month"
]
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/2"
},
"frequency": "month",
"is_active": true
},
{
"pid": "9",
"name": "organisation 2, 1 distribution",
"description": "Statistics configuration with 1 distribution",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkouts",
"distributions": [
"library"
]
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/2"
},
"frequency": "month",
"is_active": true
},
{
"pid": "10",
"name": "organisation 2, 2 distributions",
"description": "Statistics configuration with 2 distributions",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkins",
"distributions": [
"document_type",
"transaction_channel"
]
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/2"
},
"frequency": "month",
"is_active": true
},
{
"pid": "11",
"name": "organisation 2, 2 distributions, period 1 year",
"description": "Statistics configuration with 2 distributions",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkins",
"distributions": [
"document_type",
"transaction_channel"
],
"period": "year"
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/2"
},
"frequency": "month",
"is_active": true
},
{
"pid": "12",
"name": "organisation 2, 2 distributions, status disabled",
"description": "Statistics configuration with 1 distribution",
"category": {
"type": "circulation",
"indicator": {
"type": "number_of_checkins",
"distributions": [
"document_type",
"transaction_channel"
]
}
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/2"
},
"frequency": "month",
"is_active": false
}
]
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ patron_types = "rero_ils.modules.patron_types.models"
patrons = "rero_ils.modules.patrons.models"
selfcheck = "rero_ils.modules.selfcheck.models"
stats = "rero_ils.modules.stats.models"
stats_cfg = "rero_ils.modules.stats_cfg.models"
templates = "rero_ils.modules.templates.models"
vendors = "rero_ils.modules.vendors.models"

Expand Down Expand Up @@ -290,6 +291,7 @@ patron_transactions = "rero_ils.modules.patron_transactions.jsonschemas"
patron_types = "rero_ils.modules.patron_types.jsonschemas"
patrons = "rero_ils.modules.patrons.jsonschemas"
stats = "rero_ils.modules.stats.jsonschemas"
stats_cfg = "rero_ils.modules.stats_cfg.jsonschemas"
templates = "rero_ils.modules.templates.jsonschemas"
users = "rero_ils.modules.users.jsonschemas"
vendors = "rero_ils.modules.vendors.jsonschemas"
Expand Down Expand Up @@ -330,6 +332,7 @@ patron_transaction_event_id = "rero_ils.modules.patron_transaction_events.api:pa
patron_transaction_id = "rero_ils.modules.patron_transactions.api:patron_transaction_id_fetcher"
patron_type_id = "rero_ils.modules.patron_types.api:patron_type_id_fetcher"
stat_id = "rero_ils.modules.stats.api.api:stat_id_fetcher"
stat_cfg_id = "rero_ils.modules.stats_cfg.api:stat_cfg_id_fetcher"
template_id = "rero_ils.modules.templates.api:template_id_fetcher"
entity_id = "rero_ils.modules.entities.fetchers:id_fetcher"
vendor_id = "rero_ils.modules.vendors.api:vendor_id_fetcher"
Expand Down Expand Up @@ -361,6 +364,7 @@ patron_transaction_event_id = "rero_ils.modules.patron_transaction_events.api:pa
patron_transaction_id = "rero_ils.modules.patron_transactions.api:patron_transaction_id_minter"
patron_type_id = "rero_ils.modules.patron_types.api:patron_type_id_minter"
stat_id = "rero_ils.modules.stats.api.api:stat_id_minter"
stat_cfg_id = "rero_ils.modules.stats_cfg.api:stat_cfg_id_minter"
template_id = "rero_ils.modules.templates.api:template_id_minter"
entity_id = "rero_ils.modules.entities.minters:id_minter"
vendor_id = "rero_ils.modules.vendors.api:vendor_id_minter"
Expand Down Expand Up @@ -390,6 +394,7 @@ patron_transaction_events = "rero_ils.modules.patron_transaction_events.jsonreso
patron_transactions = "rero_ils.modules.patron_transactions.jsonresolver"
patron_types = "rero_ils.modules.patron_types.jsonresolver"
patrons = "rero_ils.modules.patrons.jsonresolver"
stats_cfg = "rero_ils.modules.stats_cfg.jsonresolver"
templates = "rero_ils.modules.templates.jsonresolver"
vendors = "rero_ils.modules.vendors.jsonresolver"

Expand Down Expand Up @@ -421,6 +426,7 @@ patron_transactions = "rero_ils.modules.patron_transactions.mappings"
patron_types = "rero_ils.modules.patron_types.mappings"
patrons = "rero_ils.modules.patrons.mappings"
stats = "rero_ils.modules.stats.mappings"
stats_cfg = "rero_ils.modules.stats_cfg.mappings"
templates = "rero_ils.modules.templates.mappings"
vendors = "rero_ils.modules.vendors.mappings"

Expand Down
46 changes: 45 additions & 1 deletion rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
from .modules.selfcheck.permissions import seflcheck_permission_factory
from .modules.stats.api.api import Stat
from .modules.stats.permissions import StatisticsPermissionPolicy
from .modules.stats_cfg.api import StatConfiguration
from .modules.stats_cfg.permissions import \
StatisticsConfigurationPermissionPolicy
from .modules.templates.permissions import TemplatePermissionPolicy
from .modules.users.api import get_profile_countries, \
get_readonly_profile_fields
Expand Down Expand Up @@ -802,6 +805,43 @@ def _(x):
update_permission_factory_imp=lambda record: StatisticsPermissionPolicy('update', record=record),
delete_permission_factory_imp=lambda record: StatisticsPermissionPolicy('delete', record=record)
),
stacfg=dict(
pid_type='stacfg',
pid_minter='stat_cfg_id',
pid_fetcher='stat_cfg_id',
search_class='rero_ils.modules.stats_cfg.api:StatsConfigurationSearch',
search_index='stats_cfg',
indexer_class=\
'rero_ils.modules.stats_cfg.api:StatsConfigurationIndexer',
search_type=None,
record_serializers={
'application/json': 'rero_ils.modules.serializers:json_v1_response'
},
record_serializers_aliases={
'json': 'application/json'
},
search_serializers_aliases={
'json': 'application/json'
},
search_serializers={
'application/json': 'rero_ils.modules.serializers:json_v1_search'
},
list_route='/stats_cfg/',
record_loaders={
'application/json': lambda: StatConfiguration(request.get_json()),
},
record_class='rero_ils.modules.stats_cfg.api:StatConfiguration',
item_route=('/stats_cfg/<pid(stacfg, record_class='
'"rero_ils.modules.stats_cfg.api:StatConfiguration"):pid_value>'),
default_media_type='application/json',
max_result_window=MAX_RESULT_WINDOW,
search_factory_imp='rero_ils.query:organisation_search_factory',
list_permission_factory_imp=lambda record: StatisticsConfigurationPermissionPolicy('search', record=record),
read_permission_factory_imp=lambda record: StatisticsConfigurationPermissionPolicy('read', record=record),
create_permission_factory_imp=lambda record: StatisticsConfigurationPermissionPolicy('create', record=record),
update_permission_factory_imp=lambda record: StatisticsConfigurationPermissionPolicy('update', record=record),
delete_permission_factory_imp=lambda record: StatisticsConfigurationPermissionPolicy('delete', record=record)
),
hold=dict(
pid_type='hold',
pid_minter='holding_id',
Expand Down Expand Up @@ -2779,6 +2819,9 @@ def _(x):
'rero_ils.modules.stats.permissions:access_action',
'rero_ils.modules.stats.permissions:search_action',
'rero_ils.modules.stats.permissions:read_action',
'rero_ils.modules.stats_cfg.permissions:access_action',
'rero_ils.modules.stats_cfg.permissions:search_action',
'rero_ils.modules.stats_cfg.permissions:read_action',
'rero_ils.modules.templates.permissions:access_action',
'rero_ils.modules.templates.permissions:search_action',
'rero_ils.modules.templates.permissions:read_action',
Expand Down Expand Up @@ -2877,6 +2920,7 @@ def _(x):
'ptre': '/patron_transaction_events/patron_transaction_event-v0.0.1.json',
'ptrn': '/patrons/patron-v0.0.1.json',
'stat': '/stats/stat-v0.0.1.json',
'stacfg': '/stats_cfg/stat_cfg-v0.0.1.json',
'tmpl': '/templates/template-v0.0.1.json',
'oplg': '/operation_logs/operation_log-v0.0.1.json',
'vndr': '/vendors/vendor-v0.0.1.json',
Expand All @@ -2896,7 +2940,7 @@ def _(x):

# Statistics Configuration
# ========================
# Compute the stats with a timeframe given in monthes
# Compute the stats with a timeframe given in months
RERO_ILS_STATS_BILLING_TIMEFRAME_IN_MONTHS = 3


Expand Down
Loading

0 comments on commit d4eb5dd

Please sign in to comment.