Skip to content

Commit

Permalink
Website: show time since last data (#44)
Browse files Browse the repository at this point in the history
* website: time since fix

* website: time since in new line

* pre-render time since
  • Loading branch information
metachris authored Jun 15, 2024
1 parent 6f584de commit dd20e00
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 38 deletions.
2 changes: 2 additions & 0 deletions services/website/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"text/template"
"time"

"github.com/dustin/go-humanize"
"github.com/flashbots/relayscan/database"
)

Expand Down Expand Up @@ -63,6 +64,7 @@ var funcMap = template.FuncMap{
"relayTable": relayTable,
"builderTable": builderTable,
"builderProfitTable": builderProfitTable,
"humanTime": humanize.Time,
}

func ParseIndexTemplate() (*template.Template, error) {
Expand Down
84 changes: 46 additions & 38 deletions services/website/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
<div class="content">
<div style="text-align: center; margin-bottom:60px;">
<h1 style="margin-bottom:10px;">MEV-Boost Analytics</h1>
<!-- <h2 style="margin-bottom:10px;">24h Stats</h2> -->

<p style="color: #6d6d6d; margin-top:0;">
<small>Updated {{ .LastDataTimeString }} UTC / Slot {{ .LastUpdateSlot }} / <span id="updated_ago">7 minutes ago</span></small><br>
<p style="color: #6d6d6d; margin-top:0; line-height: 1.4em;">
<small>
Updated {{ .LastDataTimeString }} UTC / Slot {{ .LastUpdateSlot }}<br>
<span id="updated_ago">({{ .LastDataTime | humanTime }})</span>
</small>
</p>
<p id="view-type">
<a href="/overview?t={{ $time }}" id="a-view-type-overview" {{ if eq $view "overview" }}class="active" {{ end }}>Overview</a>
Expand Down Expand Up @@ -170,6 +172,47 @@ <h1 style="margin-bottom:10px;">MEV-Boost Analytics</h1>

<script src="https://unpkg.com/@popperjs/core@2"></script>
<script>
function timeSince(date) {
var seconds = Math.floor(new Date() - date) / 1000;
var interval = seconds / 31536000;
if (interval > 1) {
return Math.floor(interval) + " years";
}
interval = seconds / 2592000;
if (interval > 1) {
return Math.floor(interval) + " months";
}
interval = seconds / 86400;
if (interval > 1) {
return Math.floor(interval) + " days";
}
interval = seconds / 3600;
if (interval > 1) {
return Math.floor(interval) + " hours";
}
interval = seconds / 60;
if (interval > 1) {
n = Math.floor(interval)
if (n == 1) {
return n + " minute";
} else {
return n + " minutes";
}
}

sec = Math.floor(seconds)
if (isNaN(sec)) {
return "";
}
return sec + " seconds";
}

var referenceTime = new Date("{{ .LastDataTime }}");
var timeAgo = timeSince(referenceTime);
if (timeAgo != "") {
document.getElementById("updated_ago").innerText = "(" + timeAgo + " ago)";
}

const showEvents = ['mouseenter', 'focus'];
const hideEvents = ['mouseleave', 'blur'];

Expand Down Expand Up @@ -258,41 +301,6 @@ <h1 style="margin-bottom:10px;">MEV-Boost Analytics</h1>
// fix for table sorting (it's already sorted, and this click makes the sortable plugin think it has done it)
document.getElementById("th-builderprofit-profittotal").click()
}

function timeSince(date) {
var seconds = Math.floor(new Date() - date) / 1000;
var interval = seconds / 31536000;
if (interval > 1) {
return Math.floor(interval) + " years";
}
interval = seconds / 2592000;
if (interval > 1) {
return Math.floor(interval) + " months";
}
interval = seconds / 86400;
if (interval > 1) {
return Math.floor(interval) + " days";
}
interval = seconds / 3600;
if (interval > 1) {
return Math.floor(interval) + " hours";
}
interval = seconds / 60;
if (interval > 1) {
n = Math.floor(interval)
if (n == 1) {
return n + " minute";
} else {
return n + " minutes";
}
}
return Math.floor(seconds) + " seconds";
}
window.onload = function (e) {
var referenceTime = new Date("{{ .LastDataTime }}");
var timeAgo = timeSince(referenceTime);
document.getElementById("updated_ago").innerText = timeAgo + " ago";
}
</script>

<div style="display: none;">
Expand Down

0 comments on commit dd20e00

Please sign in to comment.