Mercurial > lbo > hg > analyrics
view src/template_types.rs @ 77:fd0237049be0
Show paths instead of tags & apply rust fixes
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Mon, 31 Jul 2023 09:31:37 +0200 |
parents | 51ea67f319e3 |
children |
line wrap: on
line source
use crate::logsdb::RecentSessionsRow; use rocket::serde::Serialize; use std::collections::BTreeSet; #[derive(Serialize)] #[serde(crate = "rocket::serde")] pub struct RecentSessionsTableRow { start: String, duration: String, count: i64, refer: Option<String>, origin_country: Option<String>, origin_city: Option<String>, ua: String, alltags: String, paths: String, } fn make_unique_from_csstring<S: AsRef<str>>(s: S) -> String { BTreeSet::from_iter(s.as_ref().split(", ")) .into_iter() .collect::<Vec<&str>>() .join(", ") } impl RecentSessionsTableRow { pub fn from_row<F: time::formatting::Formattable>( r: RecentSessionsRow, off: time::UtcOffset, timeformat: &F, ) -> RecentSessionsTableRow { RecentSessionsTableRow { start: time::OffsetDateTime::from_unix_timestamp(r.start) .unwrap_or(time::OffsetDateTime::UNIX_EPOCH) .to_offset(off) .format(&timeformat) .unwrap_or(String::new()), duration: format!("{:.0}", time::Duration::seconds(r.duration)), count: r.count, refer: r.refer, origin_country: r.origin_country, origin_city: r.origin_city, ua: r.ua, alltags: make_unique_from_csstring(r.alltags), paths: make_unique_from_csstring(r.paths), } } }