From 33008e6b32d5b02f050adb738010242b2a262ac6 Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Sat, 2 Aug 2025 21:15:50 +0200 Subject: [PATCH 1/4] only one place to 'calculate' the name --- src/game.rs | 10 +++--- src/model/client.rs | 6 ++++ src/model/highscore.rs | 74 +++++++++++++++++------------------------- 3 files changed, 41 insertions(+), 49 deletions(-) diff --git a/src/game.rs b/src/game.rs index e49e327..531bea7 100644 --- a/src/game.rs +++ b/src/game.rs @@ -45,13 +45,13 @@ async fn index(State(backend): State>, cookies: CookieJar) -> Respo span.font-headline.rank.text-muted { (rank.rank)"." } - @if rank.uuid == client.uuid { (PreEscaped("")) } - (rank.name) - @if rank.uuid == client.uuid { (PreEscaped("")) } + @if rank.client == client { (PreEscaped("")) } + (rank.client.get_display_name()) + @if rank.client == client{ (PreEscaped("")) } } span.font-headline.cam { - (rank.amount)(PreEscaped(" "))"๐Ÿ“ธ" - } + (rank.amount)(PreEscaped(" "))"๐Ÿ“ธ" + } } } } diff --git a/src/model/client.rs b/src/model/client.rs index e434a84..f0c4ed2 100644 --- a/src/model/client.rs +++ b/src/model/client.rs @@ -9,6 +9,12 @@ pub struct Client { pub name: Option, } +impl PartialEq for Client { + fn eq(&self, other: &Self) -> bool { + self.uuid == other.uuid + } +} + impl Client { pub(crate) fn get_display_name(&self) -> String { match &self.name { diff --git a/src/model/highscore.rs b/src/model/highscore.rs index 0d595fd..a726686 100644 --- a/src/model/highscore.rs +++ b/src/model/highscore.rs @@ -1,56 +1,42 @@ -use crate::{random_names::get_name_by_uuid, Backend}; - -struct RankDb { - pub(crate) rank: i64, - pub(crate) name: Option, - pub(crate) uuid: String, - pub(crate) amount: i64, -} +use crate::{model::client::Client, Backend}; pub(crate) struct Rank { pub(crate) rank: i64, - pub(crate) name: String, - pub(crate) uuid: String, + pub(crate) client: Client, pub(crate) amount: i64, } -impl From for Rank { - fn from(value: RankDb) -> Self { - let name = match value.name { - Some(name) => name, - None => get_name_by_uuid(&value.uuid).to_string(), - }; - - Self { - rank: value.rank, - name, - uuid: value.uuid, - amount: value.amount, - } - } -} - impl Backend { pub(crate) async fn highscore(&self) -> Vec { match self { - Backend::Sqlite(db) => sqlx::query_as!( - RankDb, - "SELECT - RANK() OVER (ORDER BY COUNT(s.client_uuid) DESC) as rank, - c.name, - c.uuid, - COUNT(s.client_uuid) as amount - FROM client c - LEFT JOIN sightings s ON c.uuid = s.client_uuid - GROUP BY c.uuid, c.name - ORDER BY amount DESC" - ) - .fetch_all(db) - .await - .unwrap_or_default() - .into_iter() - .map(|r| r.into()) - .collect(), + Backend::Sqlite(db) => { + let rows = sqlx::query!( + "SELECT + RANK() OVER (ORDER BY COUNT(s.client_uuid) DESC) as rank, + c.name, + c.uuid, + COUNT(s.client_uuid) as amount + FROM client c + LEFT JOIN sightings s ON c.uuid = s.client_uuid + GROUP BY c.uuid, c.name + ORDER BY amount DESC" + ) + .fetch_all(db) + .await + .unwrap_or_default(); + + rows.into_iter() + .map(|row| Rank { + rank: row.rank, + client: Client { + uuid: row.uuid, + name: row.name, + }, + amount: row.amount, + }) + .map(|r| r.into()) + .collect() + } } } } From 4b62d5989bd15f90bec987dbc1ad890ff447e4fc Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Sat, 2 Aug 2025 21:22:31 +0200 Subject: [PATCH 2/4] progress bar --- src/game.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/game.rs b/src/game.rs index 531bea7..9317fe9 100644 --- a/src/game.rs +++ b/src/game.rs @@ -35,7 +35,9 @@ async fn index(State(backend): State>, cookies: CookieJar) -> Respo } } - p { "You have found " (sightings.len()) "/" (amount_total_cameras) " cameras." } + p { "You have found " (sightings.len()) "/" (amount_total_cameras) " cameras." + progress value=(sightings.len()) max=(amount_total_cameras); + } p { h2 { "Highscore" } ul.iterated { From b7340433104bef4dbffb8845d00788b11f43845a Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Sat, 2 Aug 2025 21:24:12 +0200 Subject: [PATCH 3/4] maud formatting --- src/game.rs | 34 +++++++++++++++------------ src/index.rs | 10 +++----- src/page.rs | 66 +++++++++++++++++++++++++--------------------------- 3 files changed, 54 insertions(+), 56 deletions(-) diff --git a/src/game.rs b/src/game.rs index 9317fe9..7fae183 100644 --- a/src/game.rs +++ b/src/game.rs @@ -29,14 +29,22 @@ async fn index(State(backend): State>, cookies: CookieJar) -> Respo } form { - fieldset role="group" { - input name="name" placeholder=(format!("Rename {}", client.get_display_name())) aria-label="Name"; - input type="submit" value="Save"; - } + fieldset role="group" { + input + name="name" + placeholder=(format!("Rename {}", client.get_display_name())) + aria-label="Name"; + input type="submit" value="Save"; + } } - p { "You have found " (sightings.len()) "/" (amount_total_cameras) " cameras." - progress value=(sightings.len()) max=(amount_total_cameras); + p { + "You have found " + (sightings.len()) + "/" + (amount_total_cameras) + " cameras." + progress value=(sightings.len()) max=(amount_total_cameras); } p { h2 { "Highscore" } @@ -44,16 +52,12 @@ async fn index(State(backend): State>, cookies: CookieJar) -> Respo @for rank in highscore { li.card { span { - span.font-headline.rank.text-muted { - (rank.rank)"." - } - @if rank.client == client { (PreEscaped("")) } - (rank.client.get_display_name()) - @if rank.client == client{ (PreEscaped("")) } - } - span.font-headline.cam { - (rank.amount)(PreEscaped(" "))"๐Ÿ“ธ" + span.font-headline.rank.text-muted { (rank.rank) "." } + @if rank.client == client { (PreEscaped("")) } + (rank.client.get_display_name()) + @if rank.client == client { (PreEscaped("")) } } + span.font-headline.cam { (rank.amount) (PreEscaped(" ")) "๐Ÿ“ธ" } } } } diff --git a/src/index.rs b/src/index.rs index 5af50de..274041d 100644 --- a/src/index.rs +++ b/src/index.rs @@ -3,11 +3,9 @@ use maud::{html, Markup}; pub(super) async fn index() -> Markup { new(html! { - h1 { - "Digital Shadows" - } + h1 { "Digital Shadows" } hgroup { - h2 { + h2 { "Who owns your " mark { "data" } "?" @@ -22,9 +20,7 @@ pub(super) async fn index() -> Markup { blockquote { "Digital Shadows confronts visitors with their digital self โ€“ copied, measured, analyzed. An experiment on data power, visibility, and control in the digital age." footer { - cite { - "โ€” Renรฉ Mayrhofer" - } + cite { "โ€” Renรฉ Mayrhofer" } } } p { diff --git a/src/page.rs b/src/page.rs index 7b776a1..c73454b 100644 --- a/src/page.rs +++ b/src/page.rs @@ -10,52 +10,50 @@ pub fn new(content: Markup) -> Markup { meta name="viewport" content="width=device-width, initial-scale=1.0"; link rel="stylesheet" href="/static/pico.min.css"; link rel="stylesheet" href="/static/style.css"; - title { - "Digital Shadows" - } + title { "Digital Shadows" } } body { header.container { - nav { - ul { - li { a href="/" { strong { "Digital Shadows" } } } + nav { + ul { + li { + a href="/" { + strong { "Digital Shadows" } + } } - ul { - li { - a href="/"{ - span role="img" aria-label="home" { - "๐Ÿ " - } - } + } + ul { + li { + a href="/" { + span role="img" aria-label="home" { "๐Ÿ " } } - li { - a href="/game" { - span role="img" aria-label="camera" { - "๐Ÿ“ธ" - } - } + } + li { + a href="/game" { + span role="img" aria-label="camera" { "๐Ÿ“ธ" } } - li { span id="theme_switcher" {} } + } + li { + span id="theme_switcher" {} } } } + } - main.container { - section { - (content) - } - } + main.container { + section { (content) } + } - footer.container { - small { - "Footer " - mark { "to be completed" } - a href="#" { "with links" } - " โ€ข " - a target="_blank" href="https://www.digidow.eu/impressum/" { "Impressum" } - } + footer.container { + small { + "Footer " + mark { "to be completed" } + a href="#" { "with links" } + " โ€ข " + a target="_blank" href="https://www.digidow.eu/impressum/" { "Impressum" } } - script src="/static/theme.js" {} + } + script src="/static/theme.js" {} } } } From 9919ae93c21395043f7f0eac6e54668a70cad146 Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Sat, 2 Aug 2025 21:27:33 +0200 Subject: [PATCH 4/4] todo :-( --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a13026 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# TODOs +- [ ] limit names to 25(?) chars