Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statistics pages #851

Merged
merged 5 commits into from Oct 7, 2020
Merged

Add statistics pages #851

merged 5 commits into from Oct 7, 2020

Conversation

samuelcambien
Copy link
Contributor

@samuelcambien samuelcambien commented Aug 28, 2020

References

https://github.com/DSpace/Rest7Contract/blob/main/statistics-reports.md
Fixes #731

Description

This PR implements the statistics pages for DSpace 7.

Instructions for Reviewers

List of changes in this PR:

  • I've added a StatisticsPageModule for all components related to the statistics pages. Added this module to load on the 'statistics' path.
  • I've added a generic StatisticsPage component to represent a statistics page.
  • I've added subclasses to this component for the site, community, collection and item statistics pages, with the reports to show on those pages. Added corresponding routes to the statistics page routing module.
  • I've added a context-sensitive link to the sidebar menu to the relevant statistics page.
  • I've added a StatisticsTableComponent to render a usage report as a table.

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You need not complete this checklist prior to creating your PR (draft PRs are always welcome). If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes TSLint validation using yarn run lint
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • If my PR includes new, third-party dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.

@artlowel artlowel added this to Needs Reviewers Assigned in DSpace 7 Beta 4 via automation Aug 28, 2020
@artlowel artlowel added this to the 7.0beta4 milestone Aug 28, 2020
@lgtm-com
Copy link

lgtm-com bot commented Aug 28, 2020

This pull request introduces 1 alert when merging 29553b5 into cc618eb - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@heathergreerklein heathergreerklein moved this from Needs Reviewers Assigned to Under Review in DSpace 7 Beta 4 Sep 1, 2020
Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelcambien : I gave this a quick code review today & tested it with the Backend PR (DSpace/DSpace#2782). Overall, the code looks OK, but I'm not able to get it working as expected (it's possible some of the issues are backend bugs...I'm looking into it).

  1. The site-level statistics page is always empty for me (the page is entirely blank, with just a page heading). Even after browsing around to items, I cannot get anything to appear at http://localhost:4000/statistics/
  2. The "Statistics" menu item (at the top of each page) appears to be caching its path & not updating as I browse from Site to Community to Collection to Item. If you start at the Site level and browse down, it always remains http://localhost:4000/statistics/ However, if I reload a Collection page in the browser, then that "Statistics" link is updated to the full Collection statistics path.
  3. On Community, Collection and Item statistics the results shown are always zero. This might be a backend bug though, as it appears that is what is returned by my REST API even though I see successful viewevents sent each time I browse to a new object.

I've added a few more comments inline below.

templateUrl: '../statistics-page/statistics-page.component.html',
styleUrls: ['./collection-statistics-page.component.scss']
})
export class CollectionStatisticsPageComponent extends StatisticsPageComponent<Collection> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move all these new statistics components/pages under src/app/statistics-page? There's no need for the "+" in the path. See this long standing issue #327

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, renamed the directory


@Injectable()
@dataService(USAGE_REPORT)
export class UsageReportService extends DataService<UsageReport> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add TypeDocs for this new class and its methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added typedocs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this class has been wrongly created in core/submission folder, shouldn't it stay in the core/statistics folder ?


@typedObject
@inheritSerialization(HALResource)
export class UsageReport extends HALResource {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add TypeDocs for this new class, and the Point interface in this same file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added typedocs

@samuelcambien
Copy link
Contributor Author

Hi Tim,

Thanks for your feedback.
As for the missing statistics (1. and 3.), I cannot reproduce this: with my backend I have statistics on all pages.
I guess these are not front-end issues.
As for 2., the statistics links are not properly updated indeed.

One way to solve this would be

But I think this would decrease performance, so instead I simply renamed the menu id's so they are all unique :)

Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelcambien : I've retested this today after I figured out a more reliable way to generate some viewevents statistics in the backend PR.

I'm still seeing the following issues:

  1. The site-level statistics page is still always empty for me (the page is entirely blank, with just a page heading). I cannot get anything to appear at http://localhost:4000/statistics/ I even tried to generate a viewevent on the Site object itself by running this curl command: curl -X POST 'http://localhost:8080/server/api/statistics/viewevents' -H "Content-Type:application/json" -H "X-Forwarded-For:23.249.35.27" --data '{"targetId":"6d65c6a2-3fe7-44dd-bacb-79271257c35d", "targetType":"site"}' I still do not see any data on that main page, even though I can verify (via REST and other UI pages) that I have statistics generated.
  2. The "Statistics" menu item (at the top of each page) appears to be caching its path & not updating as I browse from Site to Community to Collection to Item. I'm not sure of the best way to solve this issue, but I mentioned it to @artlowel , so hopefully he can give you some advice.

The Community/Collection/Item pages appear to work (after I generated some statistics locally). I now see report information pertaining to "Total Visits", "Total visits per month", "Top country views" and "Top city views".

As a sidenote, it looks like there's also a small merge conflict in this PR now.

@codecov
Copy link

codecov bot commented Sep 23, 2020

Codecov Report

Merging #851 into main will increase coverage by 0.03%.
The diff coverage is 85.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #851      +/-   ##
==========================================
+ Coverage   79.74%   79.77%   +0.03%     
==========================================
  Files         999     1008       +9     
  Lines       21875    21993     +118     
  Branches     2280     2291      +11     
==========================================
+ Hits        17444    17546     +102     
- Misses       3427     3443      +16     
  Partials     1004     1004              
Impacted Files Coverage Δ
src/app/core/core.module.ts 60.00% <ø> (ø)
src/app/navbar/navbar.component.ts 56.25% <ø> (ø)
...c/app/core/submission/usage-report-data.service.ts 23.52% <23.52%> (ø)
...age/statistics-table/statistics-table.component.ts 80.00% <80.00%> (ø)
src/app/shared/menu/menu.effects.ts 97.77% <95.00%> (-2.23%) ⬇️
...c/app/core/statistics/models/usage-report.model.ts 100.00% <100.00%> (ø)
...re/statistics/models/usage-report.resource-type.ts 100.00% <100.00%> (ø)
...stics-page/collection-statistics-page.component.ts 100.00% <100.00%> (ø)
...istics-page/community-statistics-page.component.ts 100.00% <100.00%> (ø)
...-statistics-page/item-statistics-page.component.ts 100.00% <100.00%> (ø)
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0414e1...c29ac36. Read the comment docs.

@samuelcambien samuelcambien force-pushed the usage-reports branch 3 times, most recently from c29ac36 to a7bf1ad Compare September 23, 2020 18:58
@samuelcambien
Copy link
Contributor Author

Hi Tim,
Thanks for your feedback.

  • The site statistics page is probably empty for you because it is not supposed to display view events on the site object, instead it shows statistics for all items in the repository, similar to the same page in DSpace 6:

I've set up the backend branch locally, but I ran into an authorization issue on the site statistics page.
This is related to 2930, so I rebased the backend branch on the latest main to have this PR included.
Then I ran the db command mentioned here:

Afterwards, I was able to generate some item stats with the request you mentioned (but with uuid of an item).
After committing the solr statistics core (or waiting for 15 minutes) I got data on the site statistics page.

  • As for the caching links, I've checked with Art and he agreed that altering the ID's would be the best solution.
    I've added an extra fix to append the uuid to the link id, so they would also be unique among items/collections/communities.

  • Rebased on the latest master to resolve conflicts.

Copy link
Contributor

@atarix83 atarix83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @samuelcambien for this PR
Generally code looks good, I've only added an inline comment.
I've also tested new statistics pages and they seem to work properly.
I've only a comment, it should be nice if the statistic page show a loading spinner while retrieving statistics from server and if any the message No data available. What happens now is that the page show immediately the No data available message that is replaced by statistics later


@Injectable()
@dataService(USAGE_REPORT)
export class UsageReportService extends DataService<UsageReport> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this class has been wrongly created in core/submission folder, shouldn't it stay in the core/statistics folder ?

@samuelcambien
Copy link
Contributor Author

Hi Guiseppe,
Thanks for your feedback.
I moved the data service and also added the ds-loading component.
The 'no data available' message is now only displayed when the reports have loaded.

Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This looks good to me now. I also ran some tests and it appears to be working. (Note though that I hit bug DSpace/DSpace#2965 again in my testing...so, other testers need to be aware you must have a dbfile installed for stats to be logged). I expect we'll want to enhance these (very basic) stats reports, but they are a good initial version

@tdonohue tdonohue moved this from Under Review to Reviewer Approved in DSpace 7 Beta 4 Oct 1, 2020
DSpace 7 Beta 4 automation moved this from Reviewer Approved to Under Review Oct 6, 2020
Copy link
Contributor

@atarix83 atarix83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelcambien thanks for addressed my feedback
however making more test, I probably found a bug. Indeed if I show statistics for a community and than trying to show statistics for other community I always get statistics of the first community I've visited. This is valid also between collections and items. Could you check it?

@samuelcambien
Copy link
Contributor Author

Hi Guiseppe, thanks for pointing this out.
This was due to a problem in the MenuEffects resolveSubstitutions method, which caused the result to be stored in the route object.
Should be resolved by the latest commit.

DSpace 7 Beta 4 automation moved this from Under Review to Reviewer Approved Oct 7, 2020
Copy link
Contributor

@atarix83 atarix83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelcambien thanks for the fix, it works properly now.
@tdonohue I have a suggestion that should be nice to improve in a follow-up PR.
Basically the breadcrumb in the statistics should include also the link of the related dspace objects, this should allow to easily navigate back to the resource for which statistics are being displayed

@tdonohue tdonohue merged commit 5bf6d0f into DSpace:main Oct 7, 2020
DSpace 7 Beta 4 automation moved this from Reviewer Approved to Done Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

DSpace (Solr) Statistics - Sitewide Usage Reports (same as v6.x)
4 participants