mapswipe/website-old

Update stats on homepage

Opened this issue · 4 comments

Make the overview stats on the homepage H2 update automatically, similar to the data page.

Is this not going to be slow to load?

Yeah, imagine it will have the same stutter as the data page. Any ideas for improving speed? Or maybe could change design to be more like the data page, rather than inline.

I can think of a few options:

  • do it by hand: go in the source every now and then, and update the numbers
  • do it on deploy: add some code in the gulp deployment function to pull the data from the backend, calculate some stats, and copy the results in the output page. Now it's "semi-hardcoded", and loading of these numbers will be instant (as in, same as the normal page). In theory, it should be more or less the same code that you already have, you just call it at a different time, being that everything is javascript.
  • once you have the above, you can simply set github to run the deployment code once a day or so, and it will keep updating numbers for you.
  • once you have that, why not do it for the data page as well? ;)

I opened a duplicate issue, not realizing this one already existed, where I asked:

More than 30,000 volunteers engaged.
With over 1,000,000 sq km swiped.
Across 29 countries.

Can we replace the static numbers currently used with an API call for current number(s)?
Noting that the sq km total doesn't accurately include the new project types.

@laurentS commented there:
I think purely dynamic might be slow/expensive unless we can cache the results somewhere.

We actually have some of these stats (area mapped) on this page https://mapswipe.org/en/data.html which are crunched on each page load. The geojson file weighs over 1MB now, which is a lot just to produce one number. I'd lean towards setting up a github actions job that runs weekly or daily to update that number, either directly in the page(s) or in a small stats file that we can then fetch on each page load. And we can add the other 2 numbers in there at the same time.

I'm not sure what the best option would be to get the number of volunteers, as I'm not even sure how we defined this number in the first place: number of accounts on firebase? number of active users in the past X months?

As for the countries mapped, I think we could extract that from the same geojson file as the area, unless we have a better source.