From 5d5398e265d59d8dcd0de76deabdf145e2d581e5 Mon Sep 17 00:00:00 2001 From: GroovieGermanikus Date: Tue, 17 Oct 2023 18:47:55 +0200 Subject: [PATCH] use log scale --- log_scale.py | 21 +++++++++++++++++++++ recent_blocks_database.py | 22 +++++++++++++++++++--- templates/_blockslist.html | 14 ++++++-------- 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 log_scale.py diff --git a/log_scale.py b/log_scale.py new file mode 100644 index 0000000..bc91135 --- /dev/null +++ b/log_scale.py @@ -0,0 +1,21 @@ +import math + +# https://www.geeksforgeeks.org/python-intensity-transformation-operations-on-images/ + +max = 1.0 +c = max/(math.log(1.0 + max)) + + +# def log_scale(x): +# y = c * math.log(1.0 + x, base) +# return y + + +def invlog_scale(x): + m=10 + return (pow(2,x * m)-1)/(pow(2,m)-1) + +if __name__=="__main__": + print("c=", c) + x = invlog_scale(.98) + print("x=", x) diff --git a/recent_blocks_database.py b/recent_blocks_database.py index c20b6b4..66ed449 100644 --- a/recent_blocks_database.py +++ b/recent_blocks_database.py @@ -2,7 +2,12 @@ import math from typing import Union, Any import pg8000.native +import log_scale +# x: 0..1 +# out: "80%" +def format_width(x): + return format(100.0 * x, "#.1f") + '%' def calc_bars(row): successful_transactions = row['successful_transactions'] @@ -11,9 +16,20 @@ def calc_bars(row): total = processed_transactions + banking_stage_errors if total > 0: row['hide_bar'] = False - row['bar_success'] = format(100.0 * successful_transactions / total, '#.1f') + '%' - row['bar_txerror'] = format(100.0 * (processed_transactions - successful_transactions) / total, '#.1f') + '%' - row['bar_bankingerror'] = format(100.0 * banking_stage_errors / total, '#.1f') + '%' + a = successful_transactions / total + b = processed_transactions / total + c = (processed_transactions + banking_stage_errors) / total # effectively 1.0 + + print("a=", a, "b=", b, "c=", c) + la = log_scale.invlog_scale(a) + lb = log_scale.invlog_scale(b) + lc = log_scale.invlog_scale(c) + print("la=", la, "lb=", lb, "lc=", lc) + + row['bar_success'] = format_width(la) + row['bar_txerror'] = format_width(lb - la) + row['bar_bankingerror'] = format_width(lc - lb) + print(row['bar_success'], row['bar_txerror'], row['bar_bankingerror']) else: row['hide_bar'] = True diff --git a/templates/_blockslist.html b/templates/_blockslist.html index 0143114..86ed8c9 100644 --- a/templates/_blockslist.html +++ b/templates/_blockslist.html @@ -2,7 +2,7 @@ Slot # - Block content + Block content (log scale) Tx errors/total @@ -11,17 +11,15 @@ {{ block.slot }} -
+
{% if not block.hide_bar %}
-
-
-
-
-
- {{ block.bar_success }} / {{ block.bar_txerror }} / {{ block.bar_bankingerror }} +
{{ block.bar_success }}
+
{{ block.bar_txerror }}
+
{{ block.bar_bankingerror }}
+ {% else %}