| 62 | await client.collect_parquet("data", query, config) |
| 63 | |
| 64 | def analyze_events(): |
| 65 | # read raw logs |
| 66 | logs = polars.read_parquet( |
| 67 | "data/logs.parquet", |
| 68 | ) |
| 69 | |
| 70 | # read transactions |
| 71 | transactions = polars.read_parquet( |
| 72 | "data/transactions.parquet", |
| 73 | ) |
| 74 | |
| 75 | # read decoded logs and join(stack) the rows with raw logs. |
| 76 | # then join transactions using the tx hash column from raw logs table. |
| 77 | data = polars.read_parquet( |
| 78 | "data/decoded_logs.parquet" |
| 79 | ).hstack(logs).join( |
| 80 | other=transactions, |
| 81 | left_on=polars.col("transaction_hash"), |
| 82 | right_on=polars.col("hash"), |
| 83 | ).group_by( |
| 84 | polars.col("from") |
| 85 | ).agg( |
| 86 | polars.col("value").sum().alias("total_value_sent"), |
| 87 | polars.col("gas_used").sum().alias("total_gas_used"), |
| 88 | ).sort( |
| 89 | polars.col("total_value_sent"), |
| 90 | descending=True |
| 91 | ).limit(10) |
| 92 | |
| 93 | polars.Config.set_ascii_tables() |
| 94 | polars.Config.set_tbl_width_chars(100) |
| 95 | polars.Config.set_fmt_str_lengths(50) |
| 96 | |
| 97 | print(data) |
| 98 | |
| 99 | asyncio.run(collect_events()) |
| 100 | analyze_events() |