diff --git a/src/page.h b/src/page.h index 66ec4ca..7b6e054 100644 --- a/src/page.h +++ b/src/page.h @@ -522,6 +522,8 @@ public: // previous blk timestamp, initalised to lowest possible value double prev_blk_timestamp {std::numeric_limits::lowest()}; + vector blk_sizes; + // iterate over last no_of_last_blocks of blocks for (uint64_t i = start_height; i <= end_height; ++i) { @@ -537,11 +539,17 @@ public: // get block's hash crypto::hash blk_hash = core_storage->get_block_id_by_height(i); + // get block size in kB + double blk_size = static_cast(core_storage->get_db().get_block_size(i))/1024.0; + + string blk_size_str = fmt::format("{:0.2f}", blk_size); + + blk_sizes.push_back(blk_size); + // remove "<" and ">" from the hash string string blk_hash_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", blk_hash)); // get block age - pair age = get_age(server_timestamp, blk.timestamp); context["age_format"] = age.second; @@ -585,6 +593,7 @@ public: txd_map.insert({"age" , age.first}); txd_map.insert({"is_ringct" , (tx.version > 1)}); txd_map.insert({"rct_type" , tx.rct_signatures.type}); + txd_map.insert({"blk_size" , blk_size_str}); // do not show block info for other than @@ -595,6 +604,7 @@ public: txd_map["height"] = string(""); txd_map["age"] = string(""); txd_map["time_delta"] = string(""); + txd_map["blk_size"] = string(""); } txs.push_back(txd_map); @@ -607,18 +617,16 @@ public: } // for (uint64_t i = start_height; i <= end_height; ++i) + // calculate median size of the blocks shown + double blk_size_median = xmreg::calc_median(blk_sizes.begin(), blk_sizes.end()); + + context["blk_size_median"] = fmt::format("{:0.2f}", blk_size_median); + // reverse txs and remove last (i.e., oldest) // tx. This is done so that time delats // are easier to calcualte in the above for loop std::reverse(txs.begin(), txs.end()); - // if we look at the genesis time, we should not remove - // the last block, i.e. genesis one. - if (!(start_height < 2)) - { - //txs.pop_back(); - } - // get memory pool rendered template string mempool_html = mempool(); diff --git a/src/templates/index2.html b/src/templates/index2.html index a741b10..2c36b6d 100644 --- a/src/templates/index2.html +++ b/src/templates/index2.html @@ -23,30 +23,36 @@ {{{mempool_info}}} {{#is_page_zero}} -

Transactions in the last 25 blocks

+

Transactions in the last 25 blocks

{{/is_page_zero}} {{^is_page_zero}} -

Transactions in older blocks

+

Transactions in older blocks

{{/is_page_zero}} +

(Median size of these blocks: {{blk_size_median}} kB)

+ + +
+ - + {{#txs}} + diff --git a/src/tools.cpp b/src/tools.cpp index ebda401..d37adfe 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -1332,5 +1332,6 @@ get_human_readable_timestamp(uint64_t ts) } + } diff --git a/src/tools.h b/src/tools.h index 75566b7..a8d499b 100644 --- a/src/tools.h +++ b/src/tools.h @@ -30,6 +30,8 @@ #include #include #include +#include +#include /** * Some helper functions used in the example. @@ -302,6 +304,20 @@ make_printable(const string& in_s); string get_human_readable_timestamp(uint64_t ts); +// Get the median of an unordered set of numbers of arbitrary +// type without modifying the underlying dataset. +// taken from http://stackoverflow.com/a/19695285 +template +typename std::iterator_traits::value_type +calc_median(It it_begin, It it_end) +{ + using T = typename std::iterator_traits::value_type; + std::vector data(it_begin, it_end); + std::nth_element(data.begin(), data.begin() + data.size() / 2, data.end()); + return data[data.size() / 2]; +} + + } #endif //XMREG01_TOOLS_H
height age {{age_format}}size [kB] tx hash fees outputs in/out rct/type mixinsize [kB]tx size [kB]
{{height}} {{age}}{{blk_size}} {{hash}} {{tx_fee_short}} {{sum_outputs_short}}