Added fee by fee level statistics

This commit is contained in:
Jochen Hoenicke 2017-08-14 10:29:45 +02:00
parent 2fb5173ed9
commit 5aab06f563
7 changed files with 202 additions and 50 deletions

128
altertable-fee.sql Normal file
View File

@ -0,0 +1,128 @@
BEGIN TRANSACTION;
ALTER TABLE mempool RENAME to oldmempool;
CREATE TABLE mempool (
time INTEGER NOT NULL,
cnt0 INTEGER,
cnt1 INTEGER,
cnt2 INTEGER,
cnt3 INTEGER,
cnt4 INTEGER,
cnt5 INTEGER,
cnt6 INTEGER,
cnt7 INTEGER,
cnt8 INTEGER,
cnt9 INTEGER,
cnt10 INTEGER,
cnt11 INTEGER,
cnt12 INTEGER,
cnt13 INTEGER,
cnt14 INTEGER,
cnt15 INTEGER,
cnt16 INTEGER,
cnt17 INTEGER,
cnt18 INTEGER,
cnt19 INTEGER,
cnt20 INTEGER,
cnt21 INTEGER,
cnt22 INTEGER,
cnt23 INTEGER,
cnt24 INTEGER,
cnt25 INTEGER,
cnt26 INTEGER,
cnt27 INTEGER,
cnt28 INTEGER,
cnt29 INTEGER,
cnt30 INTEGER,
cnt31 INTEGER,
cnt32 INTEGER,
cnt33 INTEGER,
cnt34 INTEGER,
cnt35 INTEGER,
size0 INTEGER,
size1 INTEGER,
size2 INTEGER,
size3 INTEGER,
size4 INTEGER,
size5 INTEGER,
size6 INTEGER,
size7 INTEGER,
size8 INTEGER,
size9 INTEGER,
size10 INTEGER,
size11 INTEGER,
size12 INTEGER,
size13 INTEGER,
size14 INTEGER,
size15 INTEGER,
size16 INTEGER,
size17 INTEGER,
size18 INTEGER,
size19 INTEGER,
size20 INTEGER,
size21 INTEGER,
size22 INTEGER,
size23 INTEGER,
size24 INTEGER,
size25 INTEGER,
size26 INTEGER,
size27 INTEGER,
size28 INTEGER,
size29 INTEGER,
size30 INTEGER,
size31 INTEGER,
size32 INTEGER,
size33 INTEGER,
size34 INTEGER,
size35 INTEGER,
fee0 INTEGER,
fee1 INTEGER,
fee2 INTEGER,
fee3 INTEGER,
fee4 INTEGER,
fee5 INTEGER,
fee6 INTEGER,
fee7 INTEGER,
fee8 INTEGER,
fee9 INTEGER,
fee10 INTEGER,
fee11 INTEGER,
fee12 INTEGER,
fee13 INTEGER,
fee14 INTEGER,
fee15 INTEGER,
fee16 INTEGER,
fee17 INTEGER,
fee18 INTEGER,
fee19 INTEGER,
fee20 INTEGER,
fee21 INTEGER,
fee22 INTEGER,
fee23 INTEGER,
fee24 INTEGER,
fee25 INTEGER,
fee26 INTEGER,
fee27 INTEGER,
fee28 INTEGER,
fee29 INTEGER,
fee30 INTEGER,
fee31 INTEGER,
fee32 INTEGER,
fee33 INTEGER,
fee34 INTEGER,
fee35 INTEGER
);
INSERT INTO mempool (time,
cnt0, cnt1, cnt2, cnt3, cnt4, cnt5, cnt6, cnt7, cnt8, cnt9,
cnt10, cnt11, cnt12, cnt13, cnt14, cnt15, cnt16, cnt17, cnt18, cnt19,
cnt20, cnt21, cnt22, cnt23, cnt24, cnt25,
cnt26, cnt27, cnt28, cnt29, cnt30, cnt31, cnt32, cnt33, cnt34, cnt35,
size0, size1, size2, size3, size4, size5, size6, size7, size8, size9,
size10, size11, size12, size13, size14, size15, size16, size17, size18, size19,
size20, size21, size22, size23, size24, size25,
size26, size27, size28, size29, size30, size31, size32, size33, size34, size35,
fee0)
SELECT * from oldmempool;
DROP TABLE oldmempool;
COMMIT;

View File

@ -72,5 +72,40 @@ CREATE TABLE mempool (
size33 INTEGER,
size34 INTEGER,
size35 INTEGER,
fee INTEGER
fee0 INTEGER,
fee1 INTEGER,
fee2 INTEGER,
fee3 INTEGER,
fee4 INTEGER,
fee5 INTEGER,
fee6 INTEGER,
fee7 INTEGER,
fee8 INTEGER,
fee9 INTEGER,
fee10 INTEGER,
fee11 INTEGER,
fee12 INTEGER,
fee13 INTEGER,
fee14 INTEGER,
fee15 INTEGER,
fee16 INTEGER,
fee17 INTEGER,
fee18 INTEGER,
fee19 INTEGER,
fee20 INTEGER,
fee21 INTEGER,
fee22 INTEGER,
fee23 INTEGER,
fee24 INTEGER,
fee25 INTEGER,
fee26 INTEGER,
fee27 INTEGER,
fee28 INTEGER,
fee29 INTEGER,
fee30 INTEGER,
fee31 INTEGER,
fee32 INTEGER,
fee33 INTEGER,
fee34 INTEGER,
fee35 INTEGER
);

View File

@ -7,36 +7,38 @@ my $MEMPOOLDB="mempool.s3db";
my @feelimit=(0.0001,5,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,220,240,260,280,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000);
my @total=();
my @count=();
my $totalfee = 0;
my @fees=();
my $time = time();
for ($i = 0; $i< @feelimit; $i++) {
$total[$i] = 0;
$count[$i] = 0;
$fees[$i] = 0;
}
while(<>) {
/"size": (\d+)/ and $size = $1;
/"fee": (\d*\.\d+)/ and $fee = int($1*1e8 + .5);
if (/},/) {
$totalfee += $fee;
$feeperbyte = $fee / $size;
for ($i = 0; $i< @feelimit; $i++) {
if ($feeperbyte >= $feelimit[$i]) {
$total[$i] += $size;
$count[$i]++;
$fees[$i] += $fee;
}
}
}
}
if ($count[0]) {
my $cnt = join(",", @count);
my $size = join(",", @total);
my $size = join(",", @total);
my $fee = join(",", @fees);
open(LOG, ">>$MEMPOOLLOG");
print LOG "[$time,[$cnt],[$size],$totalfee],\n";
print LOG "[$time,[$cnt],[$size],[$fee]],\n";
close(LOG);
open(SQL, "|$SQLITE $MEMPOOLDB");
print SQL ".timeout 20000\n";
$line = "INSERT INTO mempool VALUES($time,$cnt,$size,$totalfee);\n";
$line = "INSERT INTO mempool VALUES($time,$cnt,$size,$fee);\n";
print SQL $line;
close SQL;
}

View File

@ -7,8 +7,8 @@ my @vals = map { $_ || 0 } (split ",", $_, -1);
my $time = shift @vals;
my $cnt = join(",", splice(@vals, 0, 36));
my $size = join(",", splice(@vals, 0, 36));
my $totalfee = shift @vals;
$_ = "[$time,[$cnt],[$size],$totalfee],\n"'
my $fee = join(",", splice(@vals, 0, 36));
$_ = "[$time,[$cnt],[$size],[$fee]],\n"'
.mode csv
.headers off
select * from mempool order by time;

View File

@ -52,12 +52,13 @@ try {
$ctr--;
continue;
}
for ($i = 0; $i < 73; $i++) {
for ($i = 0; $i < 3*36+1; $i++) {
if (!isset($row[1+$i])) { $row[1+$i] = 0; };
}
echo $comma.'['.$row[0].',['.
join(',', array_slice($row, 1, 36)).'],['.
join(',', array_slice($row, 37, 36)).'],'.$row[73].']';
join(',', array_slice($row, 37, 36)).'],['.
join(',', array_slice($row, 73, 36)).']]';
$comma = ",\n";
$ctr = $increment;
}

View File

@ -9,7 +9,7 @@
<script type="text/javascript" src="../flot/jquery.flot.resize.min.js"></script>
<script type="text/javascript" src="../flot/jquery.flot.selection.min.js"></script>
<script type="text/javascript" src="../flot/jquery.flot.navigate.min.js"></script>
<script type="text/javascript" src="mempool.js?v=1.9"></script>
<script type="text/javascript" src="mempool.js?v=1.11"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="Content-Language" content="en"/>
@ -23,6 +23,7 @@
<b>Johoe's Mempool Statistics</b> &ndash; Period:
</div>
<div id="chartContainer1" style="width: 100%; height: 600px; margin-top: 15px;"></div>
<div id="chartContainer3" style="width: 100%; height: 600px; margin-top: 15px;"></div>
<div id="chartContainer2" style="width: 100%; height: 600px; margin-top: 15px;"></div>
<div id="tooltip"></div>
<script type="text/javascript">

View File

@ -18,30 +18,26 @@
var charts;
var ranges = [ 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000 ];
var show = [ 0, 2, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,22,23,24, 25, 26,27 ];
var show = [ 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,22,23,24, 25, 26,27 ];
var reloader;
var reloadInterval = 0;
var reloading;
var colors = [ "#349dac", "#7e5e82", "#84b200", "#a0d0cd",
var colors = [ "#349dac", "#a21010", "#7e5e82", "#84b200", "#a0d0cd",
"#c7b52e", "#6cbbea", "#514f4c", "#4e7fbb", "#9f63a0",
"#f69445", "#349dac", "#c7b52e", "#514f4c", "#c14540",
"#7e2e82", "#54b200", "#1e7fbb", "#f67405", "#60e0cd",
"#e12000", "#123456", "#fe3dba", "#349d00", "#bd00ed",
"#001080"];
var units = [ "tx", "kB", "BTC" ];
var precisions = [ 0, 0, 3];
var feelevel = 0;
var showFee = false;
var data = [];
function legendClick(idx) {
if (idx == show.length) {
showFee = !showFee;
} else {
feelevel = idx;
}
for (var i = 0; i < 2; i++) {
feelevel = idx;
for (var i = 0; i < 3; i++) {
var data = charts[i].getData();
data = updateData(data, i);
charts[i].getOptions().yaxes[1].show = showFee;
charts[i].setData(data);
charts[i].setupGrid();
charts[i].draw();
@ -51,7 +47,8 @@ function legendClick(idx) {
function tooltip(dataidx, event, pos, item) {
var plot = charts[dataidx];
var theData = data[dataidx];
var unit = dataidx == 0 ? "tx" : "kB";
var unit = units[dataidx];
var prec = precisions[dataidx];
var series = theData[0];
var xIndex = 0;
if (item) {
@ -78,9 +75,8 @@ function tooltip(dataidx, event, pos, item) {
sum = sum + theData[i][xIndex][1];
var value = ranges[show[i]];
str = str + "<tr><td>" + (value == 0 ? "total" : value + "+") +
":</td><td>" + Math.round(sum).toFixed(0).replace(/(\d)(?=(\d{3})+$)/g, '$1,') + "&nbsp;"+unit+"</td></tr>";
":</td><td>" + sum.toFixed(prec).replace(/(\d)(?=(\d{3})+$)/g, '$1,') + "&nbsp;"+unit+"</td></tr>";
}
str = str + "<tr><td>total fee:</td><td>" + theData[show.length][xIndex][1].toFixed(4) + "&nbsp;BTC</td></tr>";
str = str + "</table>";
var tip = $("#tooltip");
@ -176,8 +172,6 @@ function updateData(plotdata, dataidx) {
plotdata[j].lines.show = j >= feelevel;
plotdata[j].stack = j >= feelevel ? 1 : false;
}
plotdata[show.length].data = showFee ? theData[show.length] : [];
plotdata[show.length].lines.show = showFee;
return plotdata;
}
@ -204,19 +198,6 @@ function convertData(raw, dataidx, unit) {
[theData[j][theData[j].length-1][0], 0]]
});
}
converted.push({
label: "total fee",
idx: show.length,
yaxis: 2,
color: "#000",
stack: false,
lines: {
show: false,
fill: false,
steps: false
},
data: theData[show.length],
});
return converted;
}
@ -234,7 +215,6 @@ function showChart(raw, dataidx, container, filename, title, unit) {
},
selection: { mode: "x" },
xaxis: { mode: "time", timezone: "browser" },
yaxes: [ {}, { show: false, position: "right", min: 0}],
legend: { position: "nw", sorted: "reverse",
labelFormatter: function(label, series) {
return '<a href="#"'+
@ -261,7 +241,8 @@ function showChart(raw, dataidx, container, filename, title, unit) {
function showMempool(rawdata) {
var chart1 = showChart(rawdata, 0, "chartContainer1", "mempool", "Unconfirmed Transaction Count (Mempool)", 1)
var chart2 = showChart(rawdata, 1, "chartContainer2", "mempoolkb", "Mempool Size in kB", 1000.0)
charts = [chart1, chart2];
var chart3 = showChart(rawdata, 2, "chartContainer3", "mempoolfee", "Pending Transaction Fee in BTC", 100000000.0)
charts = [chart1, chart2, chart3];
reloadInterval = 60000;
reloader = update;
if (reloadInterval > 0) {
@ -272,9 +253,11 @@ function showMempool(rawdata) {
function zoomData(rawdata) {
storeData(rawdata, 0, 1);
storeData(rawdata, 1, 1000.0);
charts[0].setData(updateData(charts[0].getData(), 0));
charts[1].setData(updateData(charts[1].getData(), 1));
for (var i = 0; i < 2; i++) {
storeData(rawdata, 2, 100000000.0);
for (var i = 0; i < 3; i++) {
charts[i].setData(updateData(charts[i].getData(), i));
}
for (var i = 0; i < 3; i++) {
var chart = charts[i];
chart.setupGrid();
chart.draw();
@ -287,9 +270,11 @@ function loadData(rawdata) {
} else {
storeData(rawdata, 0, 1);
storeData(rawdata, 1, 1000.0);
charts[0].setData(updateData(charts[0].getData(), 0));
charts[1].setData(updateData(charts[1].getData(), 1));
for (var i = 0; i < 2; i++) {
storeData(rawdata, 2, 100000000.0);
for (var i = 0; i < 3; i++) {
charts[i].setData(updateData(charts[i].getData(), i));
}
for (var i = 0; i < 3; i++) {
var chart = charts[i];
var opts = chart.getXAxes()[0].options
opts.min = null;
@ -337,9 +322,9 @@ function update() {
loadRange(charts[0].getAxes().xaxis.max+1000, Date.now()+600000, function(rawdata) {
addData(rawdata, 0, 1);
addData(rawdata, 1, 1000.0);
charts[0].setData(updateData(charts[0].getData(), 0));
charts[1].setData(updateData(charts[1].getData(), 1));
for (var i = 0; i < 2; i++) {
addData(rawdata, 2, 100000000.0);
for (var i = 0; i < 3; i++) {
charts[i].setData(updateData(charts[i].getData(), i));
charts[i].setupGrid();
charts[i].draw();
}