feat: display filtered (wasm, js and all) filtered benchmarks

This commit is contained in:
Aravinth Manivannan 2023-02-02 00:30:15 +05:30
parent 9d128033ac
commit 92ab34967d
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
3 changed files with 106 additions and 15 deletions

View file

@ -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,12 +96,23 @@ 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 {
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()
}
}

View file

@ -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)
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, page, &uuid);
let payload = ResultsPagePayload::new(results, &uuid, query);
let results_page =
CampaignResults::new(&data.settings, Some(payload)).render();

View file

@ -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>