kopia lustrzana https://github.com/bugout-dev/moonstream
add reports.
rodzic
0436ab784a
commit
920c8941ef
|
@ -217,11 +217,87 @@ def init_game_bank_queries_handler(args: argparse.Namespace):
|
||||||
FROM
|
FROM
|
||||||
withdoraws_total
|
withdoraws_total
|
||||||
ORDER BY
|
ORDER BY
|
||||||
amount DESC;
|
amount DESC
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def init_tokenomics_queries_handler(args: argparse.Namespace):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Create the tokenomics queries.
|
||||||
|
"""
|
||||||
|
|
||||||
|
client = Moonstream()
|
||||||
|
|
||||||
|
query = """
|
||||||
|
select
|
||||||
|
sum(value),
|
||||||
|
time,
|
||||||
|
count(*) as activity
|
||||||
|
from (
|
||||||
|
select (label_data->'args'->>'value')::decimal as value, to_char(to_timestamp(block_timestamp), :time_format) as time from polygon_labels
|
||||||
|
where label='moonworm-alpha'
|
||||||
|
and address='0x64060aB139Feaae7f06Ca4E63189D86aDEb51691'
|
||||||
|
and label_data->>'name'='Transfer'
|
||||||
|
and block_timestamp >= extract(epoch from now() - interval :time_range)::int
|
||||||
|
) interval_transfers
|
||||||
|
GROUP BY time
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Create
|
||||||
|
client.create_query(
|
||||||
|
token=args.moonstream_token,
|
||||||
|
name="cu-voluem",
|
||||||
|
query=query,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def run_tokenomics_queries_handler(args: argparse.Namespace):
|
||||||
|
|
||||||
|
client = Moonstream()
|
||||||
|
|
||||||
|
# for query in client.list_queries(
|
||||||
|
# token=args.moonstream_token,
|
||||||
|
# ).queries:
|
||||||
|
|
||||||
|
query_name = "cu-volume"
|
||||||
|
params = {}
|
||||||
|
|
||||||
|
# if (
|
||||||
|
# query.name == "cu-bank-withdrawals-total"
|
||||||
|
# or query.name == "cu-bank-withdrawals-events"
|
||||||
|
# ):
|
||||||
|
# blocktimestamp = int(time.time())
|
||||||
|
#
|
||||||
|
params = {"time_format": "YYYY-MM-DD HH24:00:00", "time_range": "24 hours"}
|
||||||
|
|
||||||
|
keep_going = True
|
||||||
|
|
||||||
|
if_modified_since_datetime = datetime.datetime.utcnow()
|
||||||
|
if_modified_since = if_modified_since_datetime.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||||
|
|
||||||
|
data_url = client.exec_query(
|
||||||
|
token=args.token,
|
||||||
|
query_name=query_name,
|
||||||
|
params=params,
|
||||||
|
) # S3 presign_url
|
||||||
|
while keep_going:
|
||||||
|
data_response = requests.get(
|
||||||
|
data_url,
|
||||||
|
headers={"If-Modified-Since": if_modified_since},
|
||||||
|
timeout=10,
|
||||||
|
)
|
||||||
|
# push to s3
|
||||||
|
|
||||||
|
if data_response.status_code == 200:
|
||||||
|
json.dumps(data_response.json())
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# You can put a sleep in here if you want
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
def list_user_queries_handler(args: argparse.Namespace):
|
def list_user_queries_handler(args: argparse.Namespace):
|
||||||
"""
|
"""
|
||||||
List the user's queries.
|
List the user's queries.
|
||||||
|
@ -292,7 +368,7 @@ def generate_game_bank_report(args: argparse.Namespace):
|
||||||
# push to s3
|
# push to s3
|
||||||
|
|
||||||
if data_response.status_code == 200:
|
if data_response.status_code == 200:
|
||||||
json.dump(data_response.json())
|
json.dumps(data_response.json())
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# You can put a sleep in here if you want
|
# You can put a sleep in here if you want
|
||||||
|
@ -313,7 +389,7 @@ def main():
|
||||||
|
|
||||||
cu_reports_subparsers = cu_reports_parser.add_subparsers()
|
cu_reports_subparsers = cu_reports_parser.add_subparsers()
|
||||||
|
|
||||||
cu_reports_subparsers.add_argument(
|
cu_reports_parser.add_argument(
|
||||||
"--moonstream-token",
|
"--moonstream-token",
|
||||||
required=True,
|
required=True,
|
||||||
type=str,
|
type=str,
|
||||||
|
@ -334,11 +410,23 @@ def main():
|
||||||
).set_defaults(func=list_user_queries_handler)
|
).set_defaults(func=list_user_queries_handler)
|
||||||
|
|
||||||
queries_subparsers.add_parser(
|
queries_subparsers.add_parser(
|
||||||
"init",
|
"init-game-bank",
|
||||||
help="Create all predifind query",
|
help="Create all predifind query",
|
||||||
description="Create all predifind query",
|
description="Create all predifind query",
|
||||||
).set_defaults(func=init_game_bank_queries_handler)
|
).set_defaults(func=init_game_bank_queries_handler)
|
||||||
|
|
||||||
|
queries_subparsers.add_parser(
|
||||||
|
"init-tokenonomics",
|
||||||
|
help="Create all predifind query",
|
||||||
|
description="Create all predifind query",
|
||||||
|
).set_defaults(func=init_tokenomics_queries_handler)
|
||||||
|
|
||||||
|
queries_subparsers.add_parser(
|
||||||
|
"run-tokenonomics",
|
||||||
|
help="Create all predifind query",
|
||||||
|
description="Create all predifind query",
|
||||||
|
).set_defaults(func=run_tokenomics_queries_handler)
|
||||||
|
|
||||||
delete_query = queries_subparsers.add_parser(
|
delete_query = queries_subparsers.add_parser(
|
||||||
"delete",
|
"delete",
|
||||||
help="Delete all predifind query",
|
help="Delete all predifind query",
|
||||||
|
@ -357,26 +445,26 @@ def main():
|
||||||
"generate-reports",
|
"generate-reports",
|
||||||
help="Generate cu-bank state reports",
|
help="Generate cu-bank state reports",
|
||||||
)
|
)
|
||||||
cu_bank_parser.add_argument("--addresses", type=str, required=True)
|
# cu_bank_parser.add_argument("--addresses", type=str, required=True)
|
||||||
cu_bank_parser.add_argument(
|
# cu_bank_parser.add_argument(
|
||||||
"--output",
|
# "--output",
|
||||||
required=True,
|
# required=True,
|
||||||
type=str,
|
# type=str,
|
||||||
help="Output file name",
|
# help="Output file name",
|
||||||
)
|
# )
|
||||||
cu_bank_parser.add_argument("--blockchain", type=str, help="Blockchain")
|
# cu_bank_parser.add_argument("--blockchain", type=str, help="Blockchain")
|
||||||
cu_bank_parser.add_argument(
|
# cu_bank_parser.add_argument(
|
||||||
"--limit",
|
# "--limit",
|
||||||
type=int,
|
# type=int,
|
||||||
default=100,
|
# default=100,
|
||||||
help="Limit of the search results",
|
# help="Limit of the search results",
|
||||||
)
|
# )
|
||||||
|
|
||||||
cu_bank_parser.add_argument(
|
# cu_bank_parser.add_argument(
|
||||||
"--",
|
# "--",
|
||||||
type=str,
|
# type=str,
|
||||||
help="Filter by created_at",
|
# help="Filter by created_at",
|
||||||
)
|
# )
|
||||||
|
|
||||||
cu_bank_parser.set_defaults(func=generate_game_bank_report)
|
cu_bank_parser.set_defaults(func=generate_game_bank_report)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
|
@ -64,6 +64,7 @@ setup(
|
||||||
"statistics=mooncrawl.stats_worker.dashboard:main",
|
"statistics=mooncrawl.stats_worker.dashboard:main",
|
||||||
"state-crawler=mooncrawl.state_crawler.cli:main",
|
"state-crawler=mooncrawl.state_crawler.cli:main",
|
||||||
"metadata-crawler=mooncrawl.metadata_crawler.cli:main",
|
"metadata-crawler=mooncrawl.metadata_crawler.cli:main",
|
||||||
|
"custom-crawler=mooncrawl.cu_reports_crawler.cli:main",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Ładowanie…
Reference in New Issue