feat: display filtered (wasm, js and all) filtered benchmarks
This commit is contained in:
parent
9d128033ac
commit
92ab34967d
3 changed files with 106 additions and 15 deletions
|
@ -21,9 +21,11 @@ use actix_web::{HttpResponse, Responder};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use tera::Context;
|
||||
|
||||
use crate::api::v1::admin::campaigns::ResultsPage;
|
||||
use crate::api::v1::admin::campaigns::{
|
||||
runners::list_campaign_runner, ListCampaignResp,
|
||||
};
|
||||
use crate::api::v1::bench::SubmissionType;
|
||||
use crate::pages::errors::*;
|
||||
use crate::AppData;
|
||||
use crate::Settings;
|
||||
|
@ -55,6 +57,8 @@ pub fn register_templates(t: &mut tera::Tera) {
|
|||
pub mod routes {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::api::v1::admin::campaigns::ResultsPage;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
pub struct Campaigns {
|
||||
pub home: &'static str,
|
||||
|
@ -64,6 +68,7 @@ pub mod routes {
|
|||
pub delete: &'static str,
|
||||
pub results: &'static str,
|
||||
}
|
||||
|
||||
impl Campaigns {
|
||||
pub const fn new() -> Campaigns {
|
||||
Campaigns {
|
||||
|
@ -91,11 +96,22 @@ pub mod routes {
|
|||
pub fn get_results_route(
|
||||
&self,
|
||||
campaign_id: &str,
|
||||
page: Option<usize>,
|
||||
modifier: Option<ResultsPage>,
|
||||
) -> String {
|
||||
let mut res = self.results.replace("{uuid}", campaign_id);
|
||||
if let Some(page) = page {
|
||||
res = format!("{res}?page={page}");
|
||||
if let Some(modifier) = modifier {
|
||||
let page = modifier.page();
|
||||
if page != 0 {
|
||||
res = format!("{res}?page={page}");
|
||||
}
|
||||
|
||||
if let Some(bench_type) = modifier.bench_type {
|
||||
if page != 0 {
|
||||
res = format!("{res}&bench_type={}", bench_type.to_string());
|
||||
} else {
|
||||
res = format!("{res}?bench_type={}", bench_type.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
res
|
||||
}
|
||||
|
@ -154,7 +170,6 @@ impl From<ListCampaignResp> for TemplateCampaign {
|
|||
impl CtxError for Campaigns {
|
||||
fn with_error(&self, e: &ReadableError) -> String {
|
||||
self.ctx.borrow_mut().insert(ERROR_KEY, e);
|
||||
|
||||
self.render()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,33 +44,88 @@ impl CtxError for CampaignResults {
|
|||
}
|
||||
}
|
||||
|
||||
const RESUTS_LIMIT: usize = 50;
|
||||
const RESUTS_LIMIT: usize = 10;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
||||
pub struct ResultsPagePayload {
|
||||
next_page: Option<String>,
|
||||
submissions: Vec<SurveyResponse>,
|
||||
pub wasm_only: Option<String>,
|
||||
pub js_only: Option<String>,
|
||||
pub all_benches: Option<String>,
|
||||
}
|
||||
|
||||
impl ResultsPagePayload {
|
||||
pub fn new(
|
||||
submissions: Vec<SurveyResponse>,
|
||||
current_page: usize,
|
||||
campaign_id: &Uuid,
|
||||
modifier: ResultsPage,
|
||||
) -> Self {
|
||||
let next_page = if submissions.len() >= RESUTS_LIMIT {
|
||||
let campaign_id_str = campaign_id.to_string();
|
||||
|
||||
let all_benches;
|
||||
let wasm_only;
|
||||
let js_only;
|
||||
match modifier.bench_type {
|
||||
Some(SubmissionType::Js) => {
|
||||
all_benches = Some(
|
||||
crate::PAGES
|
||||
.panel
|
||||
.campaigns
|
||||
.get_results_route(&campaign_id_str, None),
|
||||
);
|
||||
|
||||
wasm_only = Some(crate::PAGES.panel.campaigns.get_results_route(
|
||||
&campaign_id_str,
|
||||
Some(ResultsPage::new(None, Some(SubmissionType::Wasm))),
|
||||
));
|
||||
js_only = None;
|
||||
}
|
||||
Some(SubmissionType::Wasm) => {
|
||||
js_only = Some(crate::PAGES.panel.campaigns.get_results_route(
|
||||
&campaign_id_str,
|
||||
Some(ResultsPage::new(None, Some(SubmissionType::Js))),
|
||||
));
|
||||
all_benches = Some(
|
||||
crate::PAGES
|
||||
.panel
|
||||
.campaigns
|
||||
.get_results_route(&campaign_id_str, None),
|
||||
);
|
||||
wasm_only = None;
|
||||
}
|
||||
None => {
|
||||
all_benches = None;
|
||||
js_only = Some(crate::PAGES.panel.campaigns.get_results_route(
|
||||
&campaign_id_str,
|
||||
Some(ResultsPage::new(None, Some(SubmissionType::Js))),
|
||||
));
|
||||
wasm_only = Some(crate::PAGES.panel.campaigns.get_results_route(
|
||||
&campaign_id_str,
|
||||
Some(ResultsPage::new(None, Some(SubmissionType::Wasm))),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let next_page = if submissions.len() == RESUTS_LIMIT {
|
||||
let m = ResultsPage::new(Some(modifier.page() + 1), modifier.bench_type);
|
||||
|
||||
Some(
|
||||
PAGES
|
||||
.panel
|
||||
.campaigns
|
||||
.get_results_route(&campaign_id.to_string(), Some(current_page + 1)),
|
||||
.get_results_route(&campaign_id_str, Some(m)),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Self {
|
||||
next_page,
|
||||
submissions,
|
||||
js_only,
|
||||
wasm_only,
|
||||
all_benches,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,15 +160,22 @@ pub async fn results(
|
|||
)),
|
||||
Ok(uuid) => {
|
||||
let username = id.identity().unwrap();
|
||||
let query = query.into_inner();
|
||||
let page = query.page();
|
||||
|
||||
let results =
|
||||
runners::get_results(&username, &uuid, &data, page, RESUTS_LIMIT)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
PageError::new(CampaignResults::new(&data.settings, None), e)
|
||||
})?;
|
||||
let payload = ResultsPagePayload::new(results, page, &uuid);
|
||||
let results = runners::get_results(
|
||||
&username,
|
||||
&uuid,
|
||||
&data,
|
||||
page,
|
||||
RESUTS_LIMIT,
|
||||
query.bench_type.clone(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
PageError::new(CampaignResults::new(&data.settings, None), e)
|
||||
})?;
|
||||
let payload = ResultsPagePayload::new(results, &uuid, query);
|
||||
|
||||
let results_page =
|
||||
CampaignResults::new(&data.settings, Some(payload)).render();
|
||||
|
|
|
@ -7,6 +7,20 @@
|
|||
{% block body %}
|
||||
<body class="panel__body">
|
||||
<main class="panel__container">
|
||||
<ul>
|
||||
<h2>Filters</h2>
|
||||
{% if payload.js_only %}
|
||||
<ol><a href="{{ payload.js_only }}">JavaScript polyfil only</a></ol>
|
||||
{% endif %}
|
||||
|
||||
{% if payload.wasm_only %}
|
||||
<ol><a href="{{ payload.wasm_only }}">WASM only</a></ol>
|
||||
{% endif %}
|
||||
|
||||
{% if payload.all_benches %}
|
||||
<ol><a href="{{ payload.all_benches }}">All Benchmarks</a></ol>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
Loading…
Reference in a new issue