A slightly more complicated example

In this example, we will show you how to aggregate time series data. We will continue building on the first example.

import bubbletea

url = "https://gateway.thegraph.com/api/[API KEY]/subgraphs/id/0x0d69090672c1e5a94e9aedfbc59558d18a78e1d3-0"
query = """
{
    deposits(
        where:{timestamp_gt:1609459200, timestamp_lt:1610236800}
        orderBy: timestamp
        orderDirection: asc
        bypassPagination: true
    ) {
        amount
        timestamp
        reserve {
            symbol
            decimals
        }
    }
}
"""

data = bubbletea.beta_load_subgraph(url, query)
data = data["deposits"]
data = data[data["reserve.symbol"] == "AAVE"] 
data["amount"] = data["amount"] / math.pow(10, 18)

data_hourly = bubbletea.beta_aggregate_timeseries(  
    data,
    time_column="timestamp",
    interval=bubbletea.TimeseriesInterval.HOURLY,
    columns=[
        bubbletea.ColumnConfig(
            name="amount",
            aggregate_method=bubbletea.AggregateMethod.SUM,
            na_fill_value=0.0
        )
    ],
)

bubbletea.beta_plot_bar(
    title = "Hourly AAVE Deposits",
    df = data_hourly,
    x = {"title": "Time", "field": "timestamp"},
    ys = [{"title": "Amount", "field": "amount"}],
)

beta_aggregate_timeseries function allows you to aggregate time series data by different time intervals. In this case, we are aggregating by hours.

data_hourly = bubbletea.beta_aggregate_timeseries(  
    data,
    time_column="timestamp",
    interval=bubbletea.TimeseriesInterval.HOURLY,
    columns=[
        bubbletea.ColumnConfig(
            name="amount",
            aggregate_method=bubbletea.AggregateMethod.SUM,
            na_fill_value=0.0
        )
    ],
)

Last updated

Was this helpful?