kopia lustrzana https://github.com/bugout-dev/moonstream
Added ownership_transitions derived dataset
rodzic
a2ea96b35e
commit
45d7d32ad5
|
@ -18,6 +18,7 @@ from .derive import (
|
|||
transfer_statistics_by_address,
|
||||
quantile_generating,
|
||||
mint_holding_times,
|
||||
ownership_transitions,
|
||||
transfer_holding_times,
|
||||
transfers_mints_connection_table,
|
||||
)
|
||||
|
@ -32,11 +33,12 @@ derive_functions = {
|
|||
"current_owners": current_owners,
|
||||
"current_market_values": current_market_values,
|
||||
"current_values_distribution": current_values_distribution,
|
||||
"transfer_statistics_by_address": transfer_statistics_by_address,
|
||||
"quantile_generating": quantile_generating,
|
||||
"transfers_mints_connection_table": transfers_mints_connection_table,
|
||||
"mint_holding_times": mint_holding_times,
|
||||
"ownership_transitions": ownership_transitions,
|
||||
"quantile_generating": quantile_generating,
|
||||
"transfer_holding_times": transfer_holding_times,
|
||||
"transfers_mints_connection_table": transfers_mints_connection_table,
|
||||
"transfer_statistics_by_address": transfer_statistics_by_address,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ For example:
|
|||
- Current value of each token
|
||||
"""
|
||||
import logging
|
||||
from typing import List, Tuple
|
||||
import sqlite3
|
||||
|
||||
|
||||
|
@ -109,6 +108,7 @@ def current_owners(conn: sqlite3.Connection) -> None:
|
|||
logger.error(e)
|
||||
|
||||
|
||||
|
||||
def current_market_values(conn: sqlite3.Connection) -> None:
|
||||
"""
|
||||
Requires a connection to a dataset in which the raw data (esp. transfers) has already been
|
||||
|
@ -456,3 +456,39 @@ def transfer_holding_times(conn: sqlite3.Connection):
|
|||
conn.rollback()
|
||||
logger.error("Could not create derived dataset: transfer_holding_times")
|
||||
logger.error(e)
|
||||
|
||||
def ownership_transitions(conn: sqlite3.Connection) -> None:
|
||||
"""
|
||||
Derives a table called ownership_transitions which counts the number of transitions in ownership
|
||||
from address A to address B for each pair of addresses (A, B) for which there was at least
|
||||
one transfer from A to B.
|
||||
|
||||
Requires the following tables:
|
||||
- transfers
|
||||
- current_owners
|
||||
"""
|
||||
table_name = "ownership_transitions"
|
||||
drop_ownership_transitions = f"DROP TABLE IF EXISTS {table_name};"
|
||||
# TODO(zomglings): Adding transaction_value below causes integer overflow. Might be worth trying MEAN instead of SUM for value transferred.
|
||||
create_ownership_transitions = f"""
|
||||
CREATE TABLE {table_name} AS
|
||||
WITH transitions(from_address, to_address, transition) AS (
|
||||
SELECT current_owners.owner as from_address, current_owners.owner as to_address, 1 as transition FROM current_owners
|
||||
UNION ALL
|
||||
SELECT transfers.from_address as from_address, transfers.to_address as to_address, 1 as transition FROM transfers
|
||||
)
|
||||
SELECT
|
||||
transitions.from_address,
|
||||
transitions.to_address,
|
||||
sum(transitions.transition) as num_transitions
|
||||
FROM transitions GROUP BY transitions.from_address, transitions.to_address;
|
||||
"""
|
||||
cur = conn.cursor()
|
||||
try:
|
||||
cur.execute(drop_ownership_transitions)
|
||||
cur.execute(create_ownership_transitions)
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
conn.rollback()
|
||||
logger.error(f"Could not create derived dataset: {table_name}")
|
||||
logger.error(e)
|
||||
|
|
Ładowanie…
Reference in New Issue