time delta added to index.html

add_selenium_testing
moneroexamples 8 years ago
parent 92bee9f517
commit a661b5b312

@ -145,6 +145,8 @@ namespace xmreg {
end_height = end_height - start_height > no_of_last_blocks end_height = end_height - start_height > no_of_last_blocks
? no_of_last_blocks : end_height; ? no_of_last_blocks : end_height;
time_t prev_blk_timestamp {0};
// iterate over last no_of_last_blocks of blocks // iterate over last no_of_last_blocks of blocks
for (uint64_t i = start_height; i <= end_height; ++i) for (uint64_t i = start_height; i <= end_height; ++i)
{ {
@ -170,6 +172,15 @@ namespace xmreg {
context["age_format"] = age.second; context["age_format"] = age.second;
// get time difference [m] between previous and current blocks
string time_delta_str {};
if (prev_blk_timestamp > 0)
{
time_delta_str = fmt::format("{:0.2f}",
(double(blk.timestamp) - double(prev_blk_timestamp))/60.0);
}
// get xmr in the block reward // get xmr in the block reward
array<uint64_t, 2> coinbase_tx = sum_money_in_tx(blk.miner_tx); array<uint64_t, 2> coinbase_tx = sum_money_in_tx(blk.miner_tx);
@ -215,6 +226,7 @@ namespace xmreg {
blocks.push_back(mstch::map { blocks.push_back(mstch::map {
{"height" , to_string(i)}, {"height" , to_string(i)},
{"timestamp" , timestamp_str}, {"timestamp" , timestamp_str},
{"time_delta" , time_delta_str},
{"age" , age.first}, {"age" , age.first},
{"hash" , blk_hash_str}, {"hash" , blk_hash_str},
{"block_reward", fmt::format("{:0.4f}/{:0.4f}", {"block_reward", fmt::format("{:0.4f}/{:0.4f}",
@ -230,13 +242,17 @@ namespace xmreg {
{"blksize" , fmt::format("{:0.2f}", {"blksize" , fmt::format("{:0.2f}",
static_cast<double>(blk_size) / 1024.0)} static_cast<double>(blk_size) / 1024.0)}
}); });
// save current's block timestamp as reference for the next one
prev_blk_timestamp = blk.timestamp;
} // for (uint64_t i = start_height; i <= end_height; ++i) } // for (uint64_t i = start_height; i <= end_height; ++i)
// reverse blocks and remove last (i.e., oldest) // reverse blocks and remove last (i.e., oldest)
// block. This is done so that time delats // block. This is done so that time delats
// are easier to calcualte in the above for loop // are easier to calcualte in the above for loop
std::reverse(blocks.begin(), blocks.end()); std::reverse(blocks.begin(), blocks.end());
//blocks.pop_back(); blocks.pop_back();
// get memory pool rendered template // get memory pool rendered template
string mempool_html = mempool(); string mempool_html = mempool();

@ -27,7 +27,7 @@
<table class="center"> <table class="center">
<tr> <tr>
<td>height</td> <td>height</td>
<td>age {{age_format}}</td> <td>age {{age_format}} (Δm)</td>
<td>block hash</td> <td>block hash</td>
<td>txs</td> <td>txs</td>
<td>fees</td> <td>fees</td>
@ -38,7 +38,7 @@
{{#blocks}} {{#blocks}}
<tr> <tr>
<td><a href="/block/{{height}}">{{height}}</a></td> <td><a href="/block/{{height}}">{{height}}</a></td>
<td>{{age}}</td> <td>{{age}} ({{time_delta}})</td>
<td><a href="/block/{{hash}}">{{hash}}</a></td> <td><a href="/block/{{hash}}">{{hash}}</a></td>
<td>{{notx}}</td> <td>{{notx}}</td>
<td>{{fees}}</td> <td>{{fees}}</td>

Loading…
Cancel
Save