2024-11-07 21:40:26 +00:00
|
|
|
def parse_int(args):
|
|
|
|
try:
|
|
|
|
return int( args )
|
|
|
|
except ValueError:
|
|
|
|
print(f"{args} cannot be cast to int")
|
|
|
|
raise
|
|
|
|
|
|
|
|
def mangrove_by_country_latest():
|
|
|
|
return """
|
|
|
|
select * from models_final.final__protected_mangroves_summary_stats_by_country_agg
|
|
|
|
where year = '2020'
|
|
|
|
order by cumulative_pixels_diff desc
|
|
|
|
"""
|
|
|
|
|
2024-11-15 14:35:42 +00:00
|
|
|
def mangrove_country_timeseries(args):
|
|
|
|
country_name = args["country_with_parent"]
|
|
|
|
return f"""
|
|
|
|
select year, total_n_pixels from models_final.final__protected_mangroves_summary_stats_by_country_agg
|
|
|
|
where country_with_parent = '{country_name}'
|
|
|
|
order by year
|
|
|
|
"""
|
|
|
|
|
2024-11-07 21:40:26 +00:00
|
|
|
def bitcoin_business_growth_timeseries(args):
|
|
|
|
days_ago = parse_int(args["days_ago"])
|
|
|
|
country_name = args["country_name"]
|
|
|
|
return f"""
|
|
|
|
select * from models_final.final__bitcoin_business_growth_by_country
|
|
|
|
where days_ago <= {days_ago} and country_name = '{country_name}'
|
|
|
|
order by date
|
|
|
|
"""
|
|
|
|
|
|
|
|
def bitcoin_business_growth_percent_diff_days_ago(args):
|
|
|
|
days_ago = parse_int(args["days_ago"])
|
|
|
|
return f"""
|
|
|
|
with
|
|
|
|
filtered_data as (
|
|
|
|
select country_name, date, days_ago, cumulative_value
|
|
|
|
from models_final.final__bitcoin_business_growth_by_country
|
|
|
|
where days_ago <= {days_ago}
|
|
|
|
order by country_name, days_ago desc
|
|
|
|
),
|
|
|
|
first_and_last_values as (
|
|
|
|
select
|
|
|
|
country_name,
|
|
|
|
date,
|
|
|
|
days_ago,
|
|
|
|
cumulative_value,
|
|
|
|
first_value(cumulative_value) over (
|
|
|
|
partition by country_name order by days_ago desc
|
|
|
|
) as first_value,
|
|
|
|
first_value(date) over (
|
|
|
|
partition by country_name order by days_ago desc
|
|
|
|
) as first_date,
|
|
|
|
first_value(cumulative_value) over (
|
|
|
|
partition by country_name order by days_ago
|
|
|
|
) as last_value,
|
|
|
|
first_value(date) over (
|
|
|
|
partition by country_name order by days_ago
|
|
|
|
) as last_date
|
|
|
|
from filtered_data
|
|
|
|
),
|
|
|
|
diff as (
|
|
|
|
select
|
|
|
|
country_name,
|
|
|
|
date,
|
|
|
|
first_date,
|
|
|
|
last_date,
|
|
|
|
days_ago,
|
|
|
|
cumulative_value,
|
|
|
|
first_value,
|
|
|
|
last_value,
|
|
|
|
last_value - first_value as difference,
|
|
|
|
round(
|
2025-01-10 12:22:53 +00:00
|
|
|
100 * models_final.safe_divide((last_value - first_value), first_value), 2
|
2024-11-07 21:40:26 +00:00
|
|
|
) as percent_difference
|
|
|
|
from first_and_last_values
|
|
|
|
)
|
|
|
|
select *
|
|
|
|
from diff
|
|
|
|
where days_ago = 1
|
|
|
|
order by difference desc
|
|
|
|
"""
|
2024-12-27 19:22:42 +00:00
|
|
|
|
|
|
|
def miner_rewards(args):
|
|
|
|
days_ago = parse_int(args["days_ago"])
|
|
|
|
return f"""
|
|
|
|
with
|
|
|
|
filtered_data as (
|
|
|
|
select * from models_final.final__miner_rewards order by date desc limit {days_ago}
|
|
|
|
)
|
|
|
|
select *
|
|
|
|
from filtered_data
|
|
|
|
order by date asc
|
|
|
|
|
|
|
|
"""
|
2025-01-11 15:10:53 +00:00
|
|
|
|
|
|
|
def feerate_percentiles(args):
|
|
|
|
days_ago = parse_int(args["days_ago"])
|
|
|
|
return f"""
|
|
|
|
with
|
|
|
|
filtered_data as (
|
|
|
|
select * from models_final.final__feerate_percentiles order by date desc limit {days_ago}
|
|
|
|
)
|
|
|
|
select *
|
|
|
|
from filtered_data
|
|
|
|
order by date asc
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
def bitcoin_price_timeseries(args):
|
|
|
|
days_ago = parse_int(args["days_ago"])
|
|
|
|
return f"""
|
|
|
|
with
|
|
|
|
filtered_data as (
|
|
|
|
select * from models_final.final__bitcoin_price order by date desc limit {days_ago}
|
|
|
|
)
|
|
|
|
select *
|
|
|
|
from filtered_data
|
|
|
|
order by date asc
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
def bitcoin_hashrate(args):
|
|
|
|
days_ago = parse_int(args["days_ago"])
|
|
|
|
return f"""
|
|
|
|
with
|
|
|
|
filtered_data as (
|
|
|
|
select * from models_final.final__hashrate order by date desc limit {days_ago}
|
|
|
|
)
|
|
|
|
select *
|
|
|
|
from filtered_data
|
|
|
|
order by date asc
|
|
|
|
|
|
|
|
"""
|