blockscout / blockscout-rs

Microservices for blockscout indexer
MIT License
146 stars 103 forks source link

stats: aggregate result of line chart by days, weeks, months, years #849

Open sevenzing opened 2 months ago

sevenzing commented 2 months ago

Add new input to stats page (like interval) called "resolution" to return results for a single day, a week, a month, or a year:

image

most likely it will change api, or at least date key in response

Refactor the service in preparation for feature:

Implement resolutions:

bragov4ik commented 2 months ago

Caveat: chart "ActiveAccounts". Adding intervals requires us to calculate/store unique users for each interval. It's quite non-trivial. Also not really clear what to do with cumulative/increasing graphs. Show result at the start/middle/end of the interval, or even an average value.

bragov4ik commented 2 months ago

Almost forgot: graphs with averages are non-trivial as well. To properly compute an average of some interval from averages of subintervals we need to retrieve # of entries for each subinterval.

I.e. we have 100 entries on monday (avg=0.5) and 1 entry on friday (avg=1). Avg for the week should be ~0.5 instead of 0.75

bragov4ik commented 2 months ago

for now will implement it for easier cases, let's decide on "ActiveAccounts" later..

bragov4ik commented 2 months ago

Also not really clear what to do with cumulative/increasing graphs. Show result at the start/middle/end of the interval, or even an average value.

and for this it makes sense to let it be configurable (i.e. also decide later)

bragov4ik commented 2 weeks ago

API design (report-ish)

Request

Add a parameter to query string (enum => string with some set of available values). Variants:

Pros:

Cons:

Response

Variant A

Response API remains the same:


{
    "chart": [
        {
            "date": "2024-07-01",
            "value": "35607"
        },
        {
            "date": "2024-07-02",
            "value": "8832",
            "is_approximate": true
        }
    ]
}

and for resolutions the end(or middle or start) of each interval is returned. I.e. for month it may return the last date of each month. Maybe we can add this info for each chart separately (e.g. in /lines endpoint or as in #913)

Pros:

Variant B

Add date_to or date_from field

{
    "chart": [
        {
            "date": "2024-06-01",
            "date_to": "2024-06-30",
            "value": "35607"
        },
        {
            "date": "2024-07-01",
            "date_to": "2024-07-31",
            "value": "8832",
            "is_approximate": true
        }
    ]
}

Pros:

bragov4ik commented 2 weeks ago

some other rejected variants: