Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website: show time since last data #44

Merged
merged 3 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading