Created mining dashboard
This commit is contained in:
parent
f1df9fe243
commit
9f3b4c48ea
3 changed files with 87 additions and 98 deletions
|
|
@ -58,23 +58,54 @@ async def get_mempool_recommended_fees(gerty):
|
|||
r = await client.get(gerty.mempool_endpoint + "/api/v1/fees/recommended")
|
||||
return r.json()
|
||||
|
||||
async def api_get_mining_stat(stat_slug: str, gerty):
|
||||
stat = "";
|
||||
async def get_mining_dashboard(gerty):
|
||||
areas = []
|
||||
if isinstance(gerty.mempool_endpoint, str):
|
||||
async with httpx.AsyncClient() as client:
|
||||
if stat_slug == "mining_current_hash_rate":
|
||||
r = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/1m")
|
||||
data = r.json()
|
||||
stat = {}
|
||||
stat['current'] = data['currentHashrate']
|
||||
stat['1w'] = data['hashrates'][len(data['hashrates']) - 7]['avgHashrate']
|
||||
elif stat_slug == "mining_current_difficulty":
|
||||
r = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/1m")
|
||||
data = r.json()
|
||||
stat = {}
|
||||
stat['current'] = data['currentDifficulty']
|
||||
stat['previous'] = data['difficulty'][len(data['difficulty']) - 2]['difficulty']
|
||||
return stat
|
||||
# current hashrate
|
||||
r = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/1w")
|
||||
data = r.json()
|
||||
hashrateNow = data['currentHashrate']
|
||||
hashrateOneWeekAgo = data['hashrates'][6]['avgHashrate']
|
||||
|
||||
text = []
|
||||
text.append(get_text_item_dict("Current mining hashrate", 12))
|
||||
text.append(get_text_item_dict("{0}hash".format(si_format(hashrateNow, 6, True, " ")), 20))
|
||||
text.append(get_text_item_dict("{0} vs 7 days ago".format(get_percent_difference(hashrateNow, hashrateOneWeekAgo, 3)), 12))
|
||||
areas.append(text)
|
||||
|
||||
r = await client.get(gerty.mempool_endpoint + "/api/v1/difficulty-adjustment")
|
||||
|
||||
# timeAvg
|
||||
text = []
|
||||
time_avg = r.json()['timeAvg'] / 1000
|
||||
hours, remainder = divmod(time_avg, 3600)
|
||||
minutes, seconds = divmod(remainder, 60)
|
||||
time_avg = '{:02} minutes {:02} seconds'.format(int(minutes), int(seconds))
|
||||
text.append(get_text_item_dict("Current block time", 12))
|
||||
text.append(get_text_item_dict(str(time_avg), 20))
|
||||
areas.append(text)
|
||||
|
||||
# difficulty adjustment
|
||||
text = []
|
||||
stat = r.json()['remainingTime']
|
||||
text.append(get_text_item_dict("Time to next difficulty adjustment", 12))
|
||||
text.append(get_text_item_dict(get_time_remaining(stat / 1000, 3), 20))
|
||||
areas.append(text)
|
||||
|
||||
# difficultyChange
|
||||
text = []
|
||||
difficultyChange = round(r.json()['difficultyChange'], 2)
|
||||
text.append(get_text_item_dict("Estimated difficulty change", 12))
|
||||
text.append(get_text_item_dict("{0}{1}%".format("+" if difficultyChange > 0 else "", round(difficultyChange, 2)), 20))
|
||||
areas.append(text)
|
||||
|
||||
r = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/1m")
|
||||
data = r.json()
|
||||
stat = {}
|
||||
stat['current'] = data['currentDifficulty']
|
||||
stat['previous'] = data['difficulty'][len(data['difficulty']) - 2]['difficulty']
|
||||
return areas
|
||||
|
||||
async def api_get_lightning_stats(gerty):
|
||||
stat = {}
|
||||
|
|
@ -88,8 +119,6 @@ async def get_lightning_stats(gerty):
|
|||
data = await api_get_lightning_stats(gerty)
|
||||
areas = []
|
||||
|
||||
logger.debug(data['latest']['channel_count'])
|
||||
|
||||
text = []
|
||||
text.append(get_text_item_dict("Channel Count", 12))
|
||||
text.append(get_text_item_dict(format_number(data['latest']['channel_count']), 20))
|
||||
|
|
@ -122,26 +151,6 @@ async def get_lightning_stats(gerty):
|
|||
|
||||
return areas
|
||||
|
||||
async def get_mining_stat(stat_slug: str, gerty):
|
||||
text = []
|
||||
if stat_slug == "mining_current_hash_rate":
|
||||
stat = await api_get_mining_stat(stat_slug, gerty)
|
||||
logger.debug(stat)
|
||||
current = "{0}hash".format(si_format(stat['current'], 6, True, " "))
|
||||
text.append(get_text_item_dict("Current Mining Hashrate", 20))
|
||||
text.append(get_text_item_dict(current, 40))
|
||||
# compare vs previous time period
|
||||
difference = get_percent_difference(current=stat['current'], previous=stat['1w'])
|
||||
text.append(get_text_item_dict("{0} in last 7 days".format(difference), 12))
|
||||
elif stat_slug == "mining_current_difficulty":
|
||||
stat = await api_get_mining_stat(stat_slug, gerty)
|
||||
text.append(get_text_item_dict("Current Mining Difficulty", 20))
|
||||
text.append(get_text_item_dict(format_number(stat['current']), 40))
|
||||
difference = get_percent_difference(current=stat['current'], previous=stat['previous'])
|
||||
text.append(get_text_item_dict("{0} since last adjustment".format(difference), 12))
|
||||
# text.append(get_text_item_dict("Required threshold for mining proof-of-work", 12))
|
||||
return text
|
||||
|
||||
def get_next_update_time(sleep_time_seconds: int = 0, timezone: str = "Europe/London"):
|
||||
utc_now = pytz.utc.localize(datetime.utcnow())
|
||||
next_refresh_time = utc_now + timedelta(0, sleep_time_seconds)
|
||||
|
|
@ -159,3 +168,32 @@ def gerty_should_sleep(timezone: str = "Europe/London"):
|
|||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def get_date_suffix(dayNumber):
|
||||
if 4 <= dayNumber <= 20 or 24 <= dayNumber <= 30:
|
||||
return "th"
|
||||
else:
|
||||
return ["st", "nd", "rd"][dayNumber % 10 - 1]
|
||||
|
||||
|
||||
def get_time_remaining(seconds, granularity=2):
|
||||
intervals = (
|
||||
# ('weeks', 604800), # 60 * 60 * 24 * 7
|
||||
('days', 86400), # 60 * 60 * 24
|
||||
('hours', 3600), # 60 * 60
|
||||
('minutes', 60),
|
||||
('seconds', 1),
|
||||
)
|
||||
|
||||
result = []
|
||||
|
||||
for name, count in intervals:
|
||||
value = seconds // count
|
||||
if value:
|
||||
seconds -= value * count
|
||||
if value == 1:
|
||||
name = name.rstrip('s')
|
||||
result.append("{} {}".format(round(value), name))
|
||||
return ', '.join(result[:granularity])
|
||||
|
|
|
|||
|
|
@ -201,30 +201,10 @@
|
|||
label="mempool.space recommended fees"
|
||||
></q-toggle>
|
||||
|
||||
|
||||
<q-expansion-item
|
||||
expand-separator
|
||||
icon="money"
|
||||
label="Mining Data"
|
||||
>
|
||||
<q-toggle
|
||||
v-model="toggleStates.mining"
|
||||
label="Toggle all"
|
||||
>
|
||||
<q-tooltip>Toggle all</q-tooltip>
|
||||
</q-toggle>
|
||||
<br>
|
||||
<q-toggle
|
||||
v-model="formDialog.data.display_preferences.mining_current_hash_rate"
|
||||
label="Current mining hashrate"
|
||||
></q-toggle>
|
||||
|
||||
<q-toggle
|
||||
v-model="formDialog.data.display_preferences.mining_current_difficulty"
|
||||
label="Current mining difficulty"
|
||||
></q-toggle>
|
||||
</q-expansion-item>
|
||||
|
||||
<q-toggle
|
||||
v-model="formDialog.data.display_preferences.mining_dashboard"
|
||||
label="Mining Dashboard"
|
||||
></q-toggle>
|
||||
|
||||
<q-toggle
|
||||
v-model="formDialog.data.display_preferences.lightning_dashboard"
|
||||
|
|
@ -497,8 +477,7 @@
|
|||
onchain_dashboard: true,
|
||||
mempool_recommended_fees: true,
|
||||
mempool_tx_count: true,
|
||||
mining_current_hash_rate: true,
|
||||
mining_current_difficulty: true,
|
||||
mining_dashboard: true,
|
||||
lightning_dashboard: true
|
||||
},
|
||||
lnbits_wallets: [],
|
||||
|
|
|
|||
|
|
@ -176,13 +176,13 @@ async def get_screen_data(screen_num: int, screens_list: dict, gerty):
|
|||
elif screen_slug == "fun_exchange_market_rate":
|
||||
areas.append(await get_exchange_rate(gerty))
|
||||
elif screen_slug == "onchain_dashboard":
|
||||
areas.append(await get_onchain_dashboard(gerty))
|
||||
title = "Onchain Data"
|
||||
areas = await get_onchain_dashboard(gerty)
|
||||
elif screen_slug == "mempool_recommended_fees":
|
||||
areas.append(await get_mempool_stat(screen_slug, gerty))
|
||||
elif screen_slug == "mining_current_hash_rate":
|
||||
areas.append(await get_mining_stat(screen_slug, gerty))
|
||||
elif screen_slug == "mining_current_difficulty":
|
||||
areas.append(await get_mining_stat(screen_slug, gerty))
|
||||
elif screen_slug == "mining_dashboard":
|
||||
title = "Mining Data"
|
||||
areas = await get_mining_dashboard(gerty)
|
||||
elif screen_slug == "lightning_dashboard":
|
||||
title = "Lightning Network"
|
||||
areas = await get_lightning_stats(gerty)
|
||||
|
|
@ -381,31 +381,3 @@ async def get_mempool_stat(stat_slug: str, gerty):
|
|||
font_size,
|
||||
750, pos_y))
|
||||
return text
|
||||
|
||||
|
||||
def get_date_suffix(dayNumber):
|
||||
if 4 <= dayNumber <= 20 or 24 <= dayNumber <= 30:
|
||||
return "th"
|
||||
else:
|
||||
return ["st", "nd", "rd"][dayNumber % 10 - 1]
|
||||
|
||||
|
||||
def get_time_remaining(seconds, granularity=2):
|
||||
intervals = (
|
||||
# ('weeks', 604800), # 60 * 60 * 24 * 7
|
||||
('days', 86400), # 60 * 60 * 24
|
||||
('hours', 3600), # 60 * 60
|
||||
('minutes', 60),
|
||||
('seconds', 1),
|
||||
)
|
||||
|
||||
result = []
|
||||
|
||||
for name, count in intervals:
|
||||
value = seconds // count
|
||||
if value:
|
||||
seconds -= value * count
|
||||
if value == 1:
|
||||
name = name.rstrip('s')
|
||||
result.append("{} {}".format(round(value), name))
|
||||
return ', '.join(result[:granularity])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue