Compare commits

..

No commits in common. "65eb941eb45c515b7fc3732013c7d017b6591f14" and "db0f1c5be86402cf89ed27096ff462064b70770b" have entirely different histories.

9 changed files with 54 additions and 97 deletions

60
Cargo.lock generated
View File

@ -95,7 +95,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
dependencies = [
"cfg-if",
"getrandom 0.2.10",
"once_cell",
"version_check",
]
@ -959,13 +958,13 @@ dependencies = [
[[package]]
name = "cssparser"
version = "0.29.6"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93d03419cb5950ccfd3daf3ff1c7a36ace64609a1a8746d493df1ca0afde0fa"
checksum = "754b69d351cdc2d8ee09ae203db831e005560fc6030da058f86ad60c92a9cb0a"
dependencies = [
"cssparser-macros",
"dtoa-short",
"itoa",
"itoa 0.4.8",
"matches",
"phf 0.8.0",
"proc-macro2",
@ -1100,16 +1099,6 @@ dependencies = [
"dtoa",
]
[[package]]
name = "duplicate"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de78e66ac9061e030587b2a2e75cc88f22304913c907b11307bca737141230cb"
dependencies = [
"heck 0.4.1",
"proc-macro-error",
]
[[package]]
name = "ego-tree"
version = "0.6.2"
@ -1713,6 +1702,12 @@ dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.6"
@ -2728,16 +2723,15 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scraper"
version = "0.16.0"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59e25654b5e9fd557a67dbaab5a5d36b8c448d0561beb4c041b6dbb902eddfa6"
checksum = "5684396b456f3eb69ceeb34d1b5cb1a2f6acf7ca4452131efa3ba0ee2c2d0a70"
dependencies = [
"ahash 0.8.3",
"cssparser",
"ego-tree",
"getopts",
"html5ever",
"once_cell",
"matches",
"selectors",
"smallvec",
"tendril",
@ -2934,20 +2928,22 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
[[package]]
name = "selectors"
version = "0.24.0"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c37578180969d00692904465fb7f6b3d50b9a2b952b87c23d0e2e5cb5013416"
checksum = "df320f1889ac4ba6bc0cdc9c9af7af4bd64bb927bccdf32d81140dc1f9be12fe"
dependencies = [
"bitflags",
"cssparser",
"derive_more",
"fxhash",
"log",
"matches",
"phf 0.8.0",
"phf_codegen 0.8.0",
"precomputed-hash",
"servo_arc",
"smallvec",
"thin-slice",
]
[[package]]
@ -2997,7 +2993,7 @@ version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
dependencies = [
"itoa",
"itoa 1.0.6",
"ryu",
"serde",
]
@ -3020,16 +3016,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
dependencies = [
"form_urlencoded",
"itoa",
"itoa 1.0.6",
"ryu",
"serde",
]
[[package]]
name = "servo_arc"
version = "0.2.0"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52aa42f8fdf0fed91e5ce7f23d8138441002fa31dca008acf47e6fd4721f741"
checksum = "d98238b800e0d1576d8b6e3de32827c2d74bee68bb97748dcf5071fb53965432"
dependencies = [
"nodrop",
"stable_deref_trait",
@ -3214,7 +3210,7 @@ dependencies = [
"hkdf 0.12.3",
"hmac 0.12.1",
"indexmap",
"itoa",
"itoa 1.0.6",
"libc",
"log",
"md-5",
@ -3474,6 +3470,12 @@ version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d"
[[package]]
name = "thin-slice"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c"
[[package]]
name = "thiserror"
version = "1.0.40"
@ -3507,13 +3509,12 @@ dependencies = [
[[package]]
name = "tildes-parser"
version = "0.1.0"
source = "git+https://git.bauke.xyz/tildes-community/tildes-parser.git?rev=6f0d4d394d533a331b0c9cf19fe80d60f0865ca7#6f0d4d394d533a331b0c9cf19fe80d60f0865ca7"
source = "git+https://git.bauke.xyz/tildes-community/tildes-parser.git?rev=08bf7ed#08bf7ed29e10ba6012afcd57cea263e9f0a707e9"
dependencies = [
"duplicate",
"color-eyre",
"lazy_static",
"regex",
"scraper",
"thiserror",
]
[[package]]
@ -3528,7 +3529,6 @@ dependencies = [
"dotenvy",
"grass",
"plotters",
"scraper",
"sea-orm",
"sea-orm-migration",
"surf",
@ -3569,7 +3569,7 @@ version = "0.3.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd"
dependencies = [
"itoa",
"itoa 1.0.6",
"serde",
"time-core",
"time-macros 0.2.9",

View File

@ -18,7 +18,6 @@ chrono = "0.4.22"
color-eyre = "0.6.2"
dotenvy = "0.15.5"
grass = "0.11.2"
scraper = "0.16.0"
sea-orm-migration = "0.11.3"
tracing = "0.1.36"
@ -42,7 +41,7 @@ version = "2.3.2"
[dependencies.tildes-parser]
git = "https://git.bauke.xyz/tildes-community/tildes-parser.git"
rev = "6f0d4d394d533a331b0c9cf19fe80d60f0865ca7"
rev = "08bf7ed"
[dependencies.tracing-subscriber]
features = ["env-filter"]

View File

@ -29,9 +29,12 @@ impl UserCountChart {
group_name: &str,
render_point_circles: bool,
truncate: bool,
output_dir: &str,
) -> Result<PathBuf> {
let parent = parent.join(format!("{}/user-count", output_dir));
let parent = if truncate {
parent.join("charts/user-count")
} else {
parent.join("charts-untruncated/user-count")
};
create_dir_all(&parent).await?;
let (mut datapoints, mut min_count, mut max_count) = (vec![], i64::MAX, 0);

View File

@ -115,31 +115,9 @@ pub async fn run() -> Result<()> {
groups: GroupDataModel::get_n_most_recent(&db, 31, &group.name)
.await?,
};
chart
.render(&output, &group.name, true, true, "charts")
.await?;
chart
.render(&output, &group.name, true, false, "charts-untruncated")
.await?;
{
let total_chart = UserCountChart {
groups: GroupDataModel::get_all(&db, &group.name).await?,
};
total_chart
.render(&output, &group.name, false, true, "charts-total")
.await?;
total_chart
.render(
&output,
&group.name,
false,
false,
"charts-total-untruncated",
)
.await?;
}
chart.render(&output, &group.name, true, true).await?;
chart.render(&output, &group.name, true, false).await?;
GroupTemplate::new(group.description.clone(), &group.name)
.await
@ -158,12 +136,16 @@ pub async fn run() -> Result<()> {
write_assets(&output).await?;
if let Some(group) = user_count_group {
for dir in ["charts", "charts-untruncated"] {
let from_path =
output.join(&format!("{}/user-count/{}.svg", dir, &group.name));
let to_path = output.join(format!("{}/main-user-count.svg", dir));
copy(from_path, to_path).await?;
}
let path =
output.join(&format!("charts/user-count/{}.svg", &group.name));
copy(path, output.join("charts/main-user-count.svg")).await?;
let path = output.join(&format!(
"charts-untruncated/user-count/{}.svg",
&group.name
));
copy(path, output.join("charts-untruncated/main-user-count.svg"))
.await?;
}
}
},

View File

@ -42,20 +42,6 @@ impl GroupDataModel {
Ok(group)
}
/// Get all the saved group datas from a given group name.
pub async fn get_all(
db: &DatabaseConnection,
name: &str,
) -> Result<Vec<Self>> {
Ok(
GroupDataEntity::find()
.order_by_asc(GroupDataColumn::SnapshotId)
.filter(GroupDataColumn::Name.eq(name))
.all(db)
.await?,
)
}
/// Get the N most recently saved group datas from a given group name.
pub async fn get_n_most_recent(
db: &DatabaseConnection,

View File

@ -65,7 +65,3 @@ details {
.underline {
text-decoration: underline;
}
.small {
font-size: 1rem;
}

View File

@ -44,11 +44,7 @@
<td>
<a href="/{{ group.name }}">{{ group.name }}</a>
</td>
<td>
{{ group.subscribers }}&nbsp;<span class="small"
title="Percentage of subscribers compared to the highest-subscribed group."
>({{ group.subscribers|percentage(user_count) }})</span>
</td>
<td>{{ group.subscribers }}</td>
<td>
{% if let Some(description) = group.description %}
{{ description }}

View File

@ -40,7 +40,7 @@ pub struct HomeTemplate {
pub today: NaiveDate,
/// The user count from the group with the most subscribers.
pub user_count: i64,
pub user_count: String,
}
impl HomeTemplate {
@ -59,7 +59,9 @@ impl HomeTemplate {
groups,
page_title: "Tildes Statistics".to_string(),
today: today(),
user_count: user_count.unwrap_or(1),
user_count: user_count
.map(|n| n.to_string())
.unwrap_or_else(|| "unknown".to_string()),
}
}
@ -126,10 +128,3 @@ impl GroupTemplate {
Ok(())
}
}
mod filters {
pub fn percentage(a: &i64, b: &i64) -> askama::Result<String> {
let percentage = (*a as f64 / *b as f64) * 100_f64;
Ok(format!("{:.2}%", percentage))
}
}

View File

@ -9,9 +9,9 @@ use {
eyre::{eyre, WrapErr},
Result,
},
scraper::Html,
sea_orm::{ConnectOptions, Database, DatabaseConnection},
surf::{Client, Config},
tildes_parser::Html,
};
/// Creates the SeaQL [`DatabaseConnection`].