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

Stats widget #18

Open
T-Engel opened this issue Apr 22, 2024 · 14 comments
Open

Stats widget #18

T-Engel opened this issue Apr 22, 2024 · 14 comments

Comments

@T-Engel
Copy link
Collaborator

T-Engel commented Apr 22, 2024

Dear @MortenHofft,
could you please help us with the stats widget on the homepage? We would like to show the number of occurrences, number of datasets and number of occurrences with photos.
So far, I was only able to hardcode the values here:

stats:

Could you help us so it updates automatically? I'm not very familiar with the API..
Thnak you very much!

@MortenHofft
Copy link
Member

MortenHofft commented Apr 25, 2024

To help with this scenario the theme comes with a little script that runs on all pages.
It is documented here https://hp-theme.gbif-staging.org/dynamic-values
API documentation here: https://techdocs.gbif.org/en/openapi/

example usage: https://github.com/gbif/hp-colombian-biodiversity/blob/master/_data/home.yml
Does that help?

@T-Engel
Copy link
Collaborator Author

T-Engel commented Apr 29, 2024

Thanks this is helpful. However, I was wondering how to automatically use the predicates of our portal here. In the case of the Colombian example, they seem to count everything that is published by columbia (i.e. "publishing_country=CO"), but we would like to count only those datasets and occurences that we included in our portal. Is there a way to directly draw this information from our portal configuration?

@MortenHofft
Copy link
Member

MortenHofft commented Apr 29, 2024

https://github.com/gbif/hp-colombian-biodiversity/blob/master/_data/home.yml#L7

in this line they do a graphql query. It isn't automatically taken from their site configuration though. They explicitly added what query they wanted to make.

So in your case the number of occurrences is this graphql query given your current filter

publisher count

The attribute data-ajax-path="data.occurrenceSearch.documents.total" defines what value to look at

and for images only you would have to extend the search predicate with {type: equals, key: "mediaType", value: "StillImage"},

@T-Engel
Copy link
Collaborator Author

T-Engel commented May 6, 2024

Thanks, Morten!
I was wondering whether we can somehow avoid having to touch this code every time we add new datasets to the Portal.
The basic counts that we want here are essentially the same ones that are shown in the top left corner here: https://land.gbif.de/occurrence/search/
image
And then also the respective numbers from the gallery and dataset tabs. Is it possible to pull these numbers somehow directly?

@MortenHofft
Copy link
Member

Hi - I can see how it is a but cumbersome for you as your scope is a long list of datasets.

It isn't something I have implemented. But you can implement it. It is a Jekyll site with a theme and you control it completely. You can add your own script and a shared variable with the list of datasets.

I added a little script as part of the theme to make it simple to show counts. If it is awkward in your case, then it is perfectly reasonable to write a script that fits your needs better.

It could be done with a custom javascript function or by putting the list of dataset keys in a Liquid variable.

@T-Engel
Copy link
Collaborator Author

T-Engel commented Jul 1, 2024

Thanks for the response. It sounds like that would be a good solution. Unfortunately, I'm not a developer and I have no idea how to do this. Is there any chance you could help us with this?

@MortenHofft
Copy link
Member

Here is a very simple solution

- title: |
        <span id="datasetCount">10</span>
        <script>
          document.getElementById('datasetCount').innerHTML = siteConfig.occurrence.rootPredicate.predicates[0].values.length;
        </script>
      description: Datensätze
      background: /assets/icons/datasets.png
      href: /occurrence/search/?view=DATASETS

It isn't perfect in that it has assumptions, but for what you nede it is probably fine.

Assumptions

  • the way the predicate is structured must remain the same. If you change the way you construct your root scope it will fail
  • If some dataset do not have data within the rest of scope (not german records) it will still show in the list despite not providing records.

@jholetschek
Copy link
Collaborator

I think there is no way to convert our filter to a simple GET call, which (as far as I see) is need for that.
I've asked Andrea and Tim if there is a way to convert LAND into a network based on a filter (as we did it for https://vh.gbif.de).

@MortenHofft
Copy link
Member

You can make graphql queries with GET as in the example above and now below. So unless your list of datasets grow a lot the size of that won't be an issue. But using a network will be simpler for you. But it is also possible to do it with the current setup

So in your case the number of occurrences is this graphql query given your current filter

@jholetschek
Copy link
Collaborator

Thanks Morten... I missed that GraphQL query.
What would be the GET request for the query to be executed, not the GraphQL interface?

@MortenHofft
Copy link
Member

MortenHofft commented Oct 9, 2024

that is decided by the requested content type. In your case the simplest is probably just to write a small script that gets the needed counts and updates some named tags you know exists.
I can also try to do something generic, but in essence it is this:
construct query, use predicate from siteConfig. fetch the results. update some elements that you have added IDs to.

That said, I can see how this is so generic that adding something on theme level could make sense. Not everyone likes writting javascript. And even those that know how to do not always like it.

the most tricky part is to know what endpoint to use (dev/uat/staging/prod) - which is a variable we inject at build time into the _config.yml if not already defined. let me check that part. But even if hardcoded to staging it wouldn't be an issue for you and the end users

@MortenHofft
Copy link
Member

MortenHofft commented Oct 9, 2024

I think this should do it. I'll look into something on a theme level. Just not sure how to make it general enough to be useful

9e3a276

update: Available in staging now

@jholetschek
Copy link
Collaborator

Wow - that was quick. I wonder what you can do after the second coffee!
Thanks a lot, that would have taken me a lot of time to do. i don't do JavaScript often.

@MortenHofft
Copy link
Member

In that case it was the right distribution of skills.
https://github.com/gbif/hp-land/blob/master/_includes/js/script.js#L18

It simply replace content if an element has one of these ids
occurrenceCount, imageCount, mapCount, datasetCount, publisherCount

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants