Added servers to check

This commit is contained in:
ben 2022-12-16 12:38:14 +00:00
parent 2403d0adfb
commit 68bcfadd42
6 changed files with 203 additions and 112 deletions

View file

@ -79,101 +79,98 @@ def format_number(number, precision=None):
async def get_mining_dashboard(gerty):
areas = []
if isinstance(gerty.mempool_endpoint, str):
async with httpx.AsyncClient() as client:
# current hashrate
r = await get_mempool_info("hashrate_1w", gerty)
data = r
hashrateNow = data["currentHashrate"]
hashrateOneWeekAgo = data["hashrates"][6]["avgHashrate"]
# current hashrate
r = await get_mempool_info("hashrate_1w", gerty)
data = r
hashrateNow = data["currentHashrate"]
hashrateOneWeekAgo = data["hashrates"][6]["avgHashrate"]
text = []
text.append(
get_text_item_dict(
text="Current mining hashrate", font_size=12, gerty_type=gerty.type
)
text = []
text.append(
get_text_item_dict(
text="Current mining hashrate", font_size=12, gerty_type=gerty.type
)
text.append(
get_text_item_dict(
text="{0}hash".format(si_format(hashrateNow, 6, True, " ")),
font_size=20,
gerty_type=gerty.type,
)
)
text.append(
get_text_item_dict(
text="{0}hash".format(si_format(hashrateNow, 6, True, " ")),
font_size=20,
gerty_type=gerty.type,
)
text.append(
get_text_item_dict(
text="{0} vs 7 days ago".format(
get_percent_difference(hashrateNow, hashrateOneWeekAgo, 3)
),
font_size=12,
gerty_type=gerty.type,
)
)
text.append(
get_text_item_dict(
text="{0} vs 7 days ago".format(
get_percent_difference(hashrateNow, hashrateOneWeekAgo, 3)
),
font_size=12,
gerty_type=gerty.type,
)
areas.append(text)
)
areas.append(text)
r = await get_mempool_info("difficulty_adjustment", gerty)
r = await get_mempool_info("difficulty_adjustment", gerty)
# timeAvg
text = []
progress = "{0}%".format(round(r["progressPercent"], 2))
text.append(
get_text_item_dict(
text="Progress through current epoch",
font_size=12,
gerty_type=gerty.type,
)
# timeAvg
text = []
progress = "{0}%".format(round(r["progressPercent"], 2))
text.append(
get_text_item_dict(
text="Progress through current epoch",
font_size=12,
gerty_type=gerty.type,
)
text.append(
get_text_item_dict(text=progress, font_size=60, gerty_type=gerty.type)
)
areas.append(text)
)
text.append(
get_text_item_dict(text=progress, font_size=60, gerty_type=gerty.type)
)
areas.append(text)
# difficulty adjustment
text = []
stat = r["remainingTime"]
text.append(
get_text_item_dict(
text="Time to next difficulty adjustment",
font_size=12,
gerty_type=gerty.type,
)
# difficulty adjustment
text = []
stat = r["remainingTime"]
text.append(
get_text_item_dict(
text="Time to next difficulty adjustment",
font_size=12,
gerty_type=gerty.type,
)
text.append(
get_text_item_dict(
text=get_time_remaining(stat / 1000, 3),
font_size=12,
gerty_type=gerty.type,
)
)
text.append(
get_text_item_dict(
text=get_time_remaining(stat / 1000, 3),
font_size=12,
gerty_type=gerty.type,
)
areas.append(text)
)
areas.append(text)
# difficultyChange
text = []
difficultyChange = round(r["difficultyChange"], 2)
text.append(
get_text_item_dict(
text="Estimated difficulty change",
font_size=12,
gerty_type=gerty.type,
)
# difficultyChange
text = []
difficultyChange = round(r["difficultyChange"], 2)
text.append(
get_text_item_dict(
text="Estimated difficulty change",
font_size=12,
gerty_type=gerty.type,
)
text.append(
get_text_item_dict(
text="{0}{1}%".format(
"+" if difficultyChange > 0 else "", round(difficultyChange, 2)
),
font_size=60,
gerty_type=gerty.type,
)
)
text.append(
get_text_item_dict(
text="{0}{1}%".format(
"+" if difficultyChange > 0 else "", round(difficultyChange, 2)
),
font_size=60,
gerty_type=gerty.type,
)
areas.append(text)
)
areas.append(text)
r = await get_mempool_info("hashrate_1m", gerty)
data = r
stat = {}
stat["current"] = data["currentDifficulty"]
stat["previous"] = data["difficulty"][len(data["difficulty"]) - 2][
"difficulty"
]
r = await get_mempool_info("hashrate_1m", gerty)
data = r
stat = {}
stat["current"] = data["currentDifficulty"]
stat["previous"] = data["difficulty"][len(data["difficulty"]) - 2]["difficulty"]
return areas
@ -456,6 +453,43 @@ async def get_screen_data(screen_num: int, screens_list: dict, gerty):
)
)
areas.append(text)
elif screen_slug == "url_checker":
for url in json.loads(gerty.urls):
async with httpx.AsyncClient() as client:
text = []
try:
response = await client.get(url)
text.append(
get_text_item_dict(
text=url,
font_size=20,
gerty_type=gerty.type,
)
)
text.append(
get_text_item_dict(
text=str(response.status_code),
font_size=40,
gerty_type=gerty.type,
)
)
except:
text = []
text.append(
get_text_item_dict(
text=url,
font_size=20,
gerty_type=gerty.type,
)
)
text.append(
get_text_item_dict(
text=str("DOWN"),
font_size=40,
gerty_type=gerty.type,
)
)
areas.append(text)
elif screen_slug == "fun_satoshi_quotes":
areas.append(await get_satoshi_quotes(gerty))
elif screen_slug == "fun_exchange_market_rate":
@ -940,8 +974,3 @@ def get_time_remaining(seconds, granularity=2):
name = name.rstrip("s")
result.append("{} {}".format(round(value), name))
return ", ".join(result[:granularity])
async def get_urls_to_watch(gerty):
gerty = await get_gerty(gerty)
return json.loads(gerty.urls)

View file

@ -51,8 +51,9 @@ async def m004_initial(db):
"""
)
async def m005_add_gerty_model_col(db):
"""
support for Gerty model col
"""
await db.execute("ALTER TABLE gerty.gertys ADD COLUMN urls TEXT DEFAULT '';")
await db.execute("ALTER TABLE gerty.gertys ADD COLUMN urls TEXT;")

View file

@ -45,4 +45,4 @@ class Mempool(BaseModel):
mempool_endpoint: str = Query(None)
endpoint: str = Query(None)
data: str = Query(None)
time: int = Query(None)
time: int = Query(None)

View file

@ -12,6 +12,6 @@
>
</p>
<a href="https://shop.lnbits.com/product/gerty-a-bitcoin-assistant"
><img src="/gerty/static/gerty.jpg"
><img src="/gerty/static/gerty.jpg" style="max-width: 100%"
/></a>
</q-card-section>

View file

@ -13,12 +13,14 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
>
<q-card-section class="text-h1 q-pa-none">
<small> <b>{{fun_exchange_market_rate["amount"]}}</b></small>
<small class="text-h4">{{fun_exchange_market_rate["unit"]}}</small>
<small class="text-h4"
>{{fun_exchange_market_rate["unit"].split(" ")[1]}}</small
>
</q-card-section>
</q-card>
<q-card
v-if="fun_satoshi_quotes"
v-if="fun_satoshi_quotes['quote']"
unelevated
class="q-pa-none text-body1 blockquote"
style="background: none !important"
@ -49,7 +51,12 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
class="q-pa-md row items-start q-gutter-md"
v-if="dashboard_onchain || dashboard_mining || lightning_dashboard"
>
<q-card class="q-pa-sm" v-if="dashboard_onchain" unelevated class="q-pa-sm">
<q-card
class="q-pa-sm"
v-if="dashboard_onchain[0]"
unelevated
class="q-pa-sm"
>
<q-card-section>
<div class="text-h6">Onchain</div>
</q-card-section>
@ -81,6 +88,44 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
</p>
</q-card-section>
</q-card>
<q-card class="q-pa-sm" v-if="url_checker" unelevated class="q-pa-sm">
<q-card-section>
<div class="text-h6">Servers to check</div>
</q-card-section>
<q-card-section class="q-pa-none">
<p v-for="(item, t) in url_checker">
<b>{{item[0].value.slice(0, 20)}}...:</b>
<q-chip
v-if="item[1].value < 300"
square
color="green"
text-color="white"
icon="sentiment_satisfied"
>
{{item[1].value}}
</q-chip>
<q-chip
v-else-if="item[1].value >= 300"
square
color="yellow"
text-color="white"
icon="sentiment_dissatisfied"
>
{{item[1].value}}
</q-chip>
<q-chip
v-else
square
color="red"
text-color="white"
icon="sentiment_dissatisfied"
>
{{item[1].value}}
</q-chip>
</p>
</q-card-section>
</q-card>
</div>
{% endraw %} {% endblock %} {% block scripts %}
@ -137,6 +182,10 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
this.gertyname = this.gerty[i].settings.name
}
}
if (this.gerty[i].screen.group == 'url_checker') {
this.url_checker = this.gerty[i].screen.areas
this.gertyname = this.gerty[i].settings.name
}
if (this.gerty[i].screen.group == 'dashboard_onchain') {
this.dashboard_onchain = this.gerty[i].screen.areas
this.gertyname = this.gerty[i].settings.name

View file

@ -192,6 +192,7 @@
val="xs"
label="URL Checker"
></q-checkbox>
<br />
<q-select
v-if="formDialog.data.display_preferences.fun_exchange_market_rate"
filled
@ -220,22 +221,22 @@
</q-select>
<q-select
v-if="formDialog.data.display_preferences.url_checker"
filled
multiple
dense
emit-value
v-model="formDialog.data.urls"
use-input
use-chips
multiple
hide-dropdown-icon
new-value-mode="add-unique"
label="Urls to watch."
>
<q-tooltip>Hit enter to add values</q-tooltip>
</q-select>
v-if="formDialog.data.display_preferences.url_checker"
filled
multiple
dense
emit-value
v-model="formDialog.data.urls"
use-input
use-chips
multiple
hide-dropdown-icon
new-value-mode="add-unique"
label="Urls to watch."
>
<q-tooltip>Hit enter to add values</q-tooltip>
</q-select>
<q-toggle
label="*Advanced"
v-model="toggleStates.advanced"
@ -527,7 +528,6 @@
mempool_recommended_fees: false,
dashboard_mining: false,
lightning_dashboard: false,
url_checker: false,
onchain: false,
onchain_difficulty_epoch_progress: false,
onchain_difficulty_retarget_date: false,
@ -537,9 +537,11 @@
mempool_tx_count: false,
mining_current_hash_rate: false,
mining_current_difficulty: false,
lnbits_wallets_balance: false
lnbits_wallets_balance: false,
url_checker: false
},
lnbits_wallets: [],
urls: [],
mempool_endpoint: 'https://mempool.space',
refresh_time: 300
}
@ -558,6 +560,12 @@
self.formDialog.data.lnbits_wallets = []
}
},
setUrls: function () {
self = this
if (!self.formDialog.data.display_preferences.url_checker) {
self.formDialog.data.urls = []
}
},
setOnchain: function () {
self = this
self.formDialog.data.display_preferences.onchain_difficulty_epoch_progress =
@ -582,6 +590,7 @@
this.formDialog.data = {
utc_offset: 0,
lnbits_wallets: [],
urls: [],
mempool_endpoint: 'https://mempool.space',
refresh_time: 300,
display_preferences: {}
@ -608,7 +617,7 @@
this.formDialog.data.type = gerty.type
this.formDialog.data.utc_offset = gerty.utc_offset
this.formDialog.data.lnbits_wallets = JSON.parse(gerty.lnbits_wallets)
this.formDialog.data.urls = JSON.stringify(gerty.urls)
this.formDialog.data.urls = JSON.parse(gerty.urls)
;(this.formDialog.data.exchange = gerty.exchange),
(this.formDialog.data.mempool_endpoint = gerty.mempool_endpoint),
(this.formDialog.data.refresh_time = gerty.refresh_time),
@ -675,7 +684,8 @@
this.formDialog.data.display_preferences.dashboard ||
this.formDialog.data.display_preferences.dashboard_onchain ||
this.formDialog.data.display_preferences.dashboard_onchain ||
this.formDialog.data.display_preferences.lightning_dashboard
this.formDialog.data.display_preferences.lightning_dashboard ||
this.formDialog.data.display_preferences.url_checker
) {
this.formDialog.data.type = 'Gerty'
}
@ -684,6 +694,7 @@
data.lnbits_wallets = JSON.stringify(
this.formDialog.data.lnbits_wallets
)
data.urls = JSON.stringify(this.formDialog.data.urls)
data.display_preferences = JSON.stringify(
this.formDialog.data.display_preferences
)
@ -748,6 +759,7 @@
this.formDialog.data.display_preferences.fun_satoshi_quotes = false
this.formDialog.data.display_preferences.mempool_recommended_fees = false
this.formDialog.data.display_preferences.onchain = false
this.formDialog.data.display_preferences.url_checker = false
}
}
},