From ffa16245d307b44d1a0c078266be141fa10c4413 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 8 Aug 2023 16:06:48 +0000 Subject: [PATCH] Bug 34587: Make start and end dates in providers summary data dependent Currently the start and end dates in the summary tab are based on the earliest and latest harvest run, rather than the earliest and latest data harvested. This should be changed so that we can see the period of data harvested for each provider Signed-off-by: Jessica Zairo Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/ERM/UsageDataProviders.pm | 77 ++++++++++ .../definitions/erm_usage_data_provider.yaml | 55 +++++++ .../paths/erm_usage_data_providers.yaml | 1 - .../UsageStatisticsDataProvidersSummary.vue | 143 ++++-------------- 4 files changed, 165 insertions(+), 111 deletions(-) diff --git a/Koha/REST/V1/ERM/UsageDataProviders.pm b/Koha/REST/V1/ERM/UsageDataProviders.pm index 8aa9e71542..6a74145dd1 100644 --- a/Koha/REST/V1/ERM/UsageDataProviders.pm +++ b/Koha/REST/V1/ERM/UsageDataProviders.pm @@ -20,6 +20,7 @@ use Modern::Perl; use Mojo::Base 'Mojolicious::Controller'; use Koha::ERM::UsageDataProviders; +use Koha::ERM::MonthlyUsages; use Scalar::Util qw( blessed ); use Try::Tiny qw( catch try ); @@ -34,6 +35,7 @@ use Try::Tiny qw( catch try ); sub list { my $c = shift->openapi->valid_input or return; + use Data::Dumper; return try { my $usage_data_providers_set = Koha::ERM::UsageDataProviders->new; @@ -359,4 +361,79 @@ sub test_connection { }; } +=head3 _get_earliest_and_latest_dates + +=cut + +sub _get_earliest_and_latest_dates { + my ( $report_type, $id ) = @_; + + my @years = Koha::ERM::MonthlyUsages->search( + { + usage_data_provider_id => $id, + report_type => { -like => "%$report_type%" } + }, + { + columns => [ + { earliestYear => { min => "year" } }, + { latestYear => { max => "year" } }, + ] + } + )->unblessed; + if($years[0][0]->{earliestYear}) { + my @earliest_month = Koha::ERM::MonthlyUsages->search( + { + usage_data_provider_id => $id, + report_type => { -like => "%$report_type%" }, + year => $years[0][0]->{earliestYear}, + }, + { + columns => [ + { month => { min => "month" } }, + ] + } + )->unblessed; + my @latest_month = Koha::ERM::MonthlyUsages->search( + { + usage_data_provider_id => $id, + report_type => { -like => "%$report_type%" }, + year => $years[0][0]->{latestYear}, + }, + { + columns => [ + { month => { max => "month" } }, + ] + } + )->unblessed; + + $earliest_month[0][0]->{month} = _format_month("0$earliest_month[0][0]->{month}"); + $latest_month[0][0]->{month} = _format_month("0$latest_month[0][0]->{month}"); + + my $earliest_date = "$years[0][0]->{earliestYear}-$earliest_month[0][0]->{month}"; + my $latest_date = "$years[0][0]->{latestYear}-$latest_month[0][0]->{month}"; + + return { + earliest_date => $earliest_date, + latest_date => $latest_date, + }; + } else { + return { + earliest_date => 0, + latest_date => 0, + }; + } +} + +=head3 _format_month + +=cut + +sub _format_month { + my ( $month ) = @_; + + $month = length($month) eq 2 ? $month : "0$month"; + + return $month; +} + 1; diff --git a/api/v1/swagger/definitions/erm_usage_data_provider.yaml b/api/v1/swagger/definitions/erm_usage_data_provider.yaml index 112efa9925..238cfa6521 100644 --- a/api/v1/swagger/definitions/erm_usage_data_provider.yaml +++ b/api/v1/swagger/definitions/erm_usage_data_provider.yaml @@ -100,6 +100,61 @@ properties: description: usage titles items: $ref: erm_usage_title.yaml + erm_usage_items: + type: array + description: usage items + items: + $ref: erm_usage_item.yaml + erm_usage_platforms: + type: array + description: usage platforms + items: + $ref: erm_usage_platform.yaml + erm_usage_databases: + type: array + description: usage databases + items: + $ref: erm_usage_database.yaml + earliest_title: + description: time period of data harvested + type: + - string + - "null" + latest_title: + description: time period of data harvested + type: + - string + - "null" + earliest_platform: + description: time period of data harvested + type: + - string + - "null" + latest_platform: + description: time period of data harvested + type: + - string + - "null" + earliest_item: + description: time period of data harvested + type: + - string + - "null" + latest_item: + description: time period of data harvested + type: + - string + - "null" + earliest_database: + description: time period of data harvested + type: + - string + - "null" + latest_database: + description: time period of data harvested + type: + - string + - "null" additionalProperties: false required: diff --git a/api/v1/swagger/paths/erm_usage_data_providers.yaml b/api/v1/swagger/paths/erm_usage_data_providers.yaml index 85b759d1bf..efcd91e3c1 100644 --- a/api/v1/swagger/paths/erm_usage_data_providers.yaml +++ b/api/v1/swagger/paths/erm_usage_data_providers.yaml @@ -103,7 +103,6 @@ type: string enum: - counter_files - - erm_usage_titles.erm_usage_muses collectionFormat: csv - $ref: "../swagger.yaml#/parameters/match" - $ref: "../swagger.yaml#/parameters/order_by" diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue index 0179e269d1..002c6471c5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue @@ -76,37 +76,8 @@ export default { let url = "/api/v1/erm/usage_data_providers" return url }, - getEarliestDate(row, identifier) { - const counter_files = row.counter_files.filter(file => - file.type.includes(identifier) - ) - if (counter_files.length === 0) { - return "Not run" - } - const findData = counter_files.sort( - (a, b) => new Date(a.date_uploaded) - new Date(b.date_uploaded) - ) - const date = findData[0].date_uploaded.substr(0, 10) - return `${date}` - }, - getLatestDate(row, identifier) { - const counter_files = row.counter_files.filter(file => - file.type.includes(identifier) - ) - if (counter_files.length === 0) { - return "Not run" - } - const findData = counter_files.sort( - (a, b) => new Date(b.date_uploaded) - new Date(a.date_uploaded) - ) - const date = findData[0].date_uploaded.substr(0, 10) - return `${date}` - }, getTableColumns() { - const getEarliestDate = this.getEarliestDate - const getLatestDate = this.getLatestDate - - return [ + const columns = [ { title: __("Provider"), data: "me.erm_usage_data_provider_id:me.name", @@ -116,87 +87,39 @@ export default { return row.name }, }, - { - title: __("Start"), - data: "description", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - const date = getEarliestDate(row, "TR") - return date - }, - }, - { - title: __("End"), - data: "description", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - const date = getLatestDate(row, "TR") - return date - }, - }, - { - title: __("Start"), - data: "description", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - const date = getEarliestDate(row, "PR") - return date - }, - }, - { - title: __("End"), - data: "description", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - const date = getLatestDate(row, "PR") - return date - }, - }, - { - title: __("Start"), - data: "description", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - const date = getEarliestDate(row, "DR") - return date - }, - }, - { - title: __("End"), - data: "description", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - const date = getLatestDate(row, "DR") - return date - }, - }, - { - title: __("Start"), - data: "description", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - const date = getEarliestDate(row, "IR") - return date - }, - }, - { - title: __("End"), - data: "description", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - const date = getLatestDate(row, "IR") - return date - }, - }, ] + + const data_types = ["title", "platform", "database", "item"] + data_types.forEach(data_type => { + columns.push( + { + title: __("Start"), + data: "description", + searchable: true, + orderable: true, + render: function (data, type, row, meta) { + const date = row[`earliest_${data_type}`] + ? row[`earliest_${data_type}`] + : "N/A" + return date + }, + }, + { + title: __("End"), + data: "description", + searchable: true, + orderable: true, + render: function (data, type, row, meta) { + const date = row[`latest_${data_type}`] + ? row[`latest_${data_type}`] + : "N/A" + return date + }, + } + ) + }) + + return columns }, createTableHeader() { const table = this.$refs.table.$el.getElementsByTagName("table")[0] -- 2.39.5