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 serde::{Deserialize, Serialize};
use tera::Context; use tera::Context;
use crate::api::v1::admin::campaigns::ResultsPage;
use crate::api::v1::admin::campaigns::{ use crate::api::v1::admin::campaigns::{
runners::list_campaign_runner, ListCampaignResp, runners::list_campaign_runner, ListCampaignResp,
}; };
use crate::api::v1::bench::SubmissionType;
use crate::pages::errors::*; use crate::pages::errors::*;
use crate::AppData; use crate::AppData;
use crate::Settings; use crate::Settings;
@ -55,6 +57,8 @@ pub fn register_templates(t: &mut tera::Tera) {
pub mod routes { pub mod routes {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::api::v1::admin::campaigns::ResultsPage;
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct Campaigns { pub struct Campaigns {
pub home: &'static str, pub home: &'static str,
@ -64,6 +68,7 @@ pub mod routes {
pub delete: &'static str, pub delete: &'static str,
pub results: &'static str, pub results: &'static str,
} }
impl Campaigns { impl Campaigns {
pub const fn new() -> Campaigns { pub const fn new() -> Campaigns {
Campaigns { Campaigns {
@ -91,12 +96,23 @@ pub mod routes {
pub fn get_results_route( pub fn get_results_route(
&self, &self,
campaign_id: &str, campaign_id: &str,
page: Option<usize>, modifier: Option<ResultsPage>,
) -> String { ) -> String {
let mut res = self.results.replace("{uuid}", campaign_id); 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}"); 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 res
} }
@ -154,7 +170,6 @@ impl From<ListCampaignResp> for TemplateCampaign {
impl CtxError for Campaigns { impl CtxError for Campaigns {
fn with_error(&self, e: &ReadableError) -> String { fn with_error(&self, e: &ReadableError) -> String {
self.ctx.borrow_mut().insert(ERROR_KEY, e); self.ctx.borrow_mut().insert(ERROR_KEY, e);
self.render() 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)] #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct ResultsPagePayload { pub struct ResultsPagePayload {
next_page: Option<String>, next_page: Option<String>,
submissions: Vec<SurveyResponse>, submissions: Vec<SurveyResponse>,
pub wasm_only: Option<String>,
pub js_only: Option<String>,
pub all_benches: Option<String>,
} }
impl ResultsPagePayload { impl ResultsPagePayload {
pub fn new( pub fn new(
submissions: Vec<SurveyResponse>, submissions: Vec<SurveyResponse>,
current_page: usize,
campaign_id: &Uuid, campaign_id: &Uuid,
modifier: ResultsPage,
) -> Self { ) -> 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( Some(
PAGES PAGES
.panel .panel
.campaigns .campaigns
.get_results_route(&campaign_id.to_string(), Some(current_page + 1)), .get_results_route(&campaign_id_str, Some(m)),
) )
} else { } else {
None None
}; };
Self { Self {
next_page, next_page,
submissions, submissions,
js_only,
wasm_only,
all_benches,
} }
} }
} }
@ -105,15 +160,22 @@ pub async fn results(
)), )),
Ok(uuid) => { Ok(uuid) => {
let username = id.identity().unwrap(); let username = id.identity().unwrap();
let query = query.into_inner();
let page = query.page(); let page = query.page();
let results = let results = runners::get_results(
runners::get_results(&username, &uuid, &data, page, RESUTS_LIMIT) &username,
&uuid,
&data,
page,
RESUTS_LIMIT,
query.bench_type.clone(),
)
.await .await
.map_err(|e| { .map_err(|e| {
PageError::new(CampaignResults::new(&data.settings, None), 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 = let results_page =
CampaignResults::new(&data.settings, Some(payload)).render(); CampaignResults::new(&data.settings, Some(payload)).render();

View file

@ -7,6 +7,20 @@
{% block body %} {% block body %}
<body class="panel__body"> <body class="panel__body">
<main class="panel__container"> <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> <table>
<thead> <thead>
<tr> <tr>