changed score calculation and added sorting and 'new' tag
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, State},
|
extract::{Path, Query, State},
|
||||||
response::{Html, IntoResponse},
|
response::{Html, IntoResponse},
|
||||||
};
|
};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
@@ -10,6 +10,12 @@ use tera::Context;
|
|||||||
|
|
||||||
use crate::{AppState, TEMPLATES};
|
use crate::{AppState, TEMPLATES};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct SortParams {
|
||||||
|
pub sort: Option<String>,
|
||||||
|
pub order: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Report {
|
pub struct Report {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
@@ -25,12 +31,17 @@ pub struct Report {
|
|||||||
pub struct ReportRow {
|
pub struct ReportRow {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub score: u64,
|
pub score: u64,
|
||||||
|
pub single_score: u64,
|
||||||
|
pub multi_score: u64,
|
||||||
pub cores: u32,
|
pub cores: u32,
|
||||||
pub ram: String,
|
pub ram: String,
|
||||||
|
pub ram_raw: f32,
|
||||||
pub os: String,
|
pub os: String,
|
||||||
pub hostname: String,
|
pub hostname: String,
|
||||||
pub time_ago: String,
|
pub time_ago: String,
|
||||||
|
pub timestamp: String,
|
||||||
pub signature: String,
|
pub signature: String,
|
||||||
|
pub is_new: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@@ -63,6 +74,16 @@ fn format_time_ago(timestamp: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_recent(timestamp: &str) -> bool {
|
||||||
|
DateTime::parse_from_rfc3339(timestamp)
|
||||||
|
.map(|ts| {
|
||||||
|
let now = Utc::now();
|
||||||
|
let diff = now.signed_duration_since(ts.with_timezone(&Utc));
|
||||||
|
diff.num_hours() < 24 && diff.num_seconds() >= 0
|
||||||
|
})
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_total_ram(ram_str: &str) -> String {
|
fn parse_total_ram(ram_str: &str) -> String {
|
||||||
let total_part = ram_str.split('/').last().unwrap_or("").trim();
|
let total_part = ram_str.split('/').last().unwrap_or("").trim();
|
||||||
let digits: String = total_part.chars().filter(|c| c.is_ascii_digit()).collect();
|
let digits: String = total_part.chars().filter(|c| c.is_ascii_digit()).collect();
|
||||||
@@ -73,8 +94,15 @@ fn parse_total_ram(ram_str: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_total_ram_raw(ram_str: &str) -> f32 {
|
||||||
|
let total_part = ram_str.split('/').last().unwrap_or("").trim();
|
||||||
|
let digits: String = total_part.chars().filter(|c| c.is_ascii_digit()).collect();
|
||||||
|
digits.parse::<f32>().unwrap_or(0.0) / 1024.0
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn home_handler(
|
pub async fn home_handler(
|
||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
|
Query(params): Query<SortParams>,
|
||||||
) -> Result<impl IntoResponse, (StatusCode, String)> {
|
) -> Result<impl IntoResponse, (StatusCode, String)> {
|
||||||
let response = reqwest::get("https://alatreon.org/slimes?limit=1000")
|
let response = reqwest::get("https://alatreon.org/slimes?limit=1000")
|
||||||
.await
|
.await
|
||||||
@@ -87,11 +115,13 @@ pub async fn home_handler(
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let reports: Vec<ReportRow> = raw_reports
|
let mut reports: Vec<ReportRow> = raw_reports
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| ReportRow {
|
.map(|s| ReportRow {
|
||||||
id: s.id,
|
id: s.id,
|
||||||
score: s.benchmark.multi_thread.score,
|
score: (s.benchmark.multi_thread.score + s.benchmark.single_thread.score) / 2,
|
||||||
|
single_score: s.benchmark.single_thread.score,
|
||||||
|
multi_score: s.benchmark.multi_thread.score,
|
||||||
cores: s.benchmark.logical_cores,
|
cores: s.benchmark.logical_cores,
|
||||||
ram: s
|
ram: s
|
||||||
.slimes
|
.slimes
|
||||||
@@ -99,6 +129,12 @@ pub async fn home_handler(
|
|||||||
.and_then(|v| v.first())
|
.and_then(|v| v.first())
|
||||||
.map(|r| parse_total_ram(r))
|
.map(|r| parse_total_ram(r))
|
||||||
.unwrap_or_else(|| "-".into()),
|
.unwrap_or_else(|| "-".into()),
|
||||||
|
ram_raw: s
|
||||||
|
.slimes
|
||||||
|
.get("RAM")
|
||||||
|
.and_then(|v| v.first())
|
||||||
|
.map(|r| parse_total_ram_raw(r))
|
||||||
|
.unwrap_or_else(|| 0.0),
|
||||||
os: s
|
os: s
|
||||||
.slimes
|
.slimes
|
||||||
.get("OS")
|
.get("OS")
|
||||||
@@ -111,14 +147,37 @@ pub async fn home_handler(
|
|||||||
.and_then(|v| v.first())
|
.and_then(|v| v.first())
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_else(|| "-".into()),
|
.unwrap_or_else(|| "-".into()),
|
||||||
time_ago: format_time_ago(&s.timestamp),
|
|
||||||
signature: s.signature,
|
signature: s.signature,
|
||||||
|
timestamp: s.timestamp.clone(),
|
||||||
|
time_ago: format_time_ago(&s.timestamp),
|
||||||
|
is_new: is_recent(&s.timestamp),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let sort_field = params.sort.unwrap_or_else(|| "score".to_string());
|
||||||
|
let order = params.order.unwrap_or_else(|| "desc".to_string());
|
||||||
|
|
||||||
|
reports.sort_by(|a, b| {
|
||||||
|
let cmp = match sort_field.as_str() {
|
||||||
|
"single" => a.single_score.cmp(&b.single_score),
|
||||||
|
"multi" => a.multi_score.cmp(&b.multi_score),
|
||||||
|
"ram" => a
|
||||||
|
.ram_raw
|
||||||
|
.partial_cmp(&b.ram_raw)
|
||||||
|
.unwrap_or(std::cmp::Ordering::Equal),
|
||||||
|
"threads" => a.cores.cmp(&b.cores),
|
||||||
|
"time" => a.timestamp.cmp(&b.timestamp),
|
||||||
|
_ => a.score.cmp(&b.score),
|
||||||
|
};
|
||||||
|
|
||||||
|
if order == "asc" { cmp } else { cmp.reverse() }
|
||||||
|
});
|
||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.insert("reports", &reports);
|
context.insert("reports", &reports);
|
||||||
context.insert("title", &state.app_name);
|
context.insert("title", &state.app_name);
|
||||||
|
context.insert("current_sort", &sort_field);
|
||||||
|
context.insert("current_order", &order);
|
||||||
|
|
||||||
match TEMPLATES.render("index.html", &context) {
|
match TEMPLATES.render("index.html", &context) {
|
||||||
Ok(html) => Ok(Html(html)),
|
Ok(html) => Ok(Html(html)),
|
||||||
@@ -143,6 +202,10 @@ pub async fn report_details_handler(
|
|||||||
context.insert("report", &report);
|
context.insert("report", &report);
|
||||||
context.insert("title", &format!("Report #{} | {}", id, state.app_name));
|
context.insert("title", &format!("Report #{} | {}", id, state.app_name));
|
||||||
context.insert("time_ago", &format_time_ago(&report.timestamp));
|
context.insert("time_ago", &format_time_ago(&report.timestamp));
|
||||||
|
context.insert(
|
||||||
|
"score",
|
||||||
|
&((report.benchmark.multi_thread.score + report.benchmark.single_thread.score) / 2),
|
||||||
|
);
|
||||||
|
|
||||||
match TEMPLATES.render("details.html", &context) {
|
match TEMPLATES.render("details.html", &context) {
|
||||||
Ok(html) => Ok(Html(html)),
|
Ok(html) => Ok(Html(html)),
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.init();
|
.init();
|
||||||
|
|
||||||
let shared_state = Arc::new(AppState {
|
let shared_state = Arc::new(AppState {
|
||||||
app_name: "Quick rust website template".to_string(),
|
app_name: "Slimes Leaderboards".to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ body {
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 1200px;
|
max-width: 1400px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
@@ -83,21 +83,6 @@ tr:hover {
|
|||||||
background-color: var(--hover-color);
|
background-color: var(--hover-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.score-cell {
|
|
||||||
color: var(--primary-color);
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|
||||||
.signature-cell {
|
|
||||||
color: var(--text-muted);
|
|
||||||
font-style: italic;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
max-width: 200px;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
@@ -44,8 +44,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="score-container">
|
<div class="score-container">
|
||||||
<div class="score-value">{{ report.benchmark.multi_thread.score }}</div>
|
<div class="score-value">{{ score }}</div>
|
||||||
<div class="score-label">Multi-Thread Score</div>
|
<div class="score-label">CPU Score</div>
|
||||||
|
<div class="score-note">(mt+st)/2</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@
|
|||||||
background: var(--bg-card);
|
background: var(--bg-card);
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 2.5rem;
|
padding: 2.5rem;
|
||||||
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
|
/* box-shadow: 0 4px 6px rgba(0,0,0,0.05); */
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +166,12 @@
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
.score-label {
|
.score-label {
|
||||||
|
font-size: 1rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: var(--text-muted);
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
}
|
||||||
|
.score-note {
|
||||||
font-size: 0.7rem;
|
font-size: 0.7rem;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
|
|||||||
@@ -1,11 +1,41 @@
|
|||||||
{% extends "_layout.html" %}
|
{% extends "_layout.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="header-section">
|
||||||
<h2>Benchmark Reports</h2>
|
<h2>Benchmark Reports</h2>
|
||||||
|
|
||||||
|
<div class="table-controls">
|
||||||
|
<form id="sortForm" method="get" action="/">
|
||||||
|
<div class="control-group">
|
||||||
|
<label for="sort">Sort by:</label>
|
||||||
|
<select name="sort" onchange="this.form.submit()">
|
||||||
|
<option value="score" {% if current_sort == "score" %}selected{% endif %}>Score</option>
|
||||||
|
<option value="single" {% if current_sort == "single" %}selected{% endif %}>Single Thread</option>
|
||||||
|
<option value="multi" {% if current_sort == "multi" %}selected{% endif %}>Multi Thread</option>
|
||||||
|
<option value="ram" {% if current_sort == "ram" %}selected{% endif %}>RAM Amount</option>
|
||||||
|
<option value="threads" {% if current_sort == "threads" %}selected{% endif %}>Thread Count</option>
|
||||||
|
<option value="time" {% if current_sort == "time" %}selected{% endif %}>Time Ago</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<input type="hidden" name="order" value="{{ current_order }}">
|
||||||
|
<button type="button" class="order-toggle" onclick="toggleOrder()">
|
||||||
|
{% if current_order == "desc" %}
|
||||||
|
Descending ↓
|
||||||
|
{% else %}
|
||||||
|
Ascending ↑
|
||||||
|
{% endif %}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>MT Score</th>
|
<th>CPU Score</th>
|
||||||
<th>Threads</th>
|
<th>Threads</th>
|
||||||
<th>RAM</th>
|
<th>RAM</th>
|
||||||
<th>OS</th>
|
<th>OS</th>
|
||||||
@@ -24,13 +54,26 @@
|
|||||||
<td data-label="RAM">{{ report.ram }}</td>
|
<td data-label="RAM">{{ report.ram }}</td>
|
||||||
<td data-label="OS">{{ report.os | truncate(length=30) }}</td>
|
<td data-label="OS">{{ report.os | truncate(length=30) }}</td>
|
||||||
<td data-label="Hostname">{{ report.hostname }}</td>
|
<td data-label="Hostname">{{ report.hostname }}</td>
|
||||||
<td data-label="Time">{{ report.time_ago }}</td>
|
<td data-label="Time">{{ report.time_ago }}
|
||||||
|
{% if report.is_new %}
|
||||||
|
<span class="new-badge">NEW</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
<td data-label="Note" class="signature-cell">{{ report.signature }}</td>
|
<td data-label="Note" class="signature-cell">{{ report.signature }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function toggleOrder() {
|
||||||
|
const form = document.getElementById('sortForm');
|
||||||
|
const orderInput = form.querySelector('input[name="order"]');
|
||||||
|
orderInput.value = orderInput.value === 'desc' ? 'asc' : 'desc';
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.clickable-row {
|
.clickable-row {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -45,5 +88,100 @@
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.score-cell {
|
||||||
|
color: var(--primary-color);
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.signature-cell {
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-style: italic;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
max-width: 400px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new-badge {
|
||||||
|
font-size: 0.6rem;
|
||||||
|
padding: 3px;
|
||||||
|
color: var(--primary-text);
|
||||||
|
border: 1px solid var(--primary-color);
|
||||||
|
background: var(--primary-soft);
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-section {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 25px;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-section h2 { margin: 0; }
|
||||||
|
|
||||||
|
.table-controls form {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
align-items: center;
|
||||||
|
background: var(--bg-card);
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
padding: 0.4rem 0.8rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
background: white;
|
||||||
|
color: var(--text-dark);
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-toggle {
|
||||||
|
background: var(--primary-soft);
|
||||||
|
border: 1px solid var(--primary-border);
|
||||||
|
color: var(--primary-text);
|
||||||
|
padding: 0.4rem 0.8rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-toggle:hover {
|
||||||
|
background: var(--primary-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sub-scores {
|
||||||
|
font-size: 0.65rem;
|
||||||
|
font-weight: normal;
|
||||||
|
opacity: 0.7;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 640px) {
|
||||||
|
.table-controls form {
|
||||||
|
/* flex-direction: column; */
|
||||||
|
gap: 0.6rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user