Add general stats command
This commit is contained in:
parent
76efd6d728
commit
5b8feb6368
4 changed files with 101 additions and 6 deletions
|
|
@ -1,5 +1,5 @@
|
|||
pub mod export;
|
||||
pub mod ingest;
|
||||
pub mod path;
|
||||
pub mod redirects;
|
||||
pub mod show;
|
||||
pub mod stats;
|
||||
|
|
|
|||
95
brood/src/commands/stats.rs
Normal file
95
brood/src/commands/stats.rs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
mod redirects;
|
||||
|
||||
use std::io;
|
||||
|
||||
use thousands::Separable;
|
||||
|
||||
use crate::data::Data;
|
||||
|
||||
#[derive(Debug, clap::Parser)]
|
||||
enum Command {
|
||||
Redirects(redirects::Cmd),
|
||||
}
|
||||
|
||||
/// Show interesting stats.
|
||||
#[derive(Debug, clap::Parser)]
|
||||
pub struct Cmd {
|
||||
#[command(subcommand)]
|
||||
command: Option<Command>,
|
||||
}
|
||||
|
||||
impl Cmd {
|
||||
pub fn run(self, data: Data) -> io::Result<()> {
|
||||
if let Some(cmd) = self.command {
|
||||
return match cmd {
|
||||
Command::Redirects(cmd) => cmd.run(data),
|
||||
};
|
||||
}
|
||||
|
||||
println!();
|
||||
|
||||
const W_LABEL: usize = 14;
|
||||
const W_NUM: usize = 11;
|
||||
|
||||
let n_pages = data.pages.len();
|
||||
let n_redirects = data.pages.iter().filter(|p| p.redirect).count();
|
||||
let n_articles = n_pages - n_redirects;
|
||||
|
||||
println!(
|
||||
"{:>W_LABEL$}: {:>W_NUM$}",
|
||||
"Pages",
|
||||
n_pages.separate_with_underscores()
|
||||
);
|
||||
|
||||
println!(
|
||||
"{:>W_LABEL$}: {:>W_NUM$}",
|
||||
"Articles",
|
||||
n_articles.separate_with_underscores()
|
||||
);
|
||||
|
||||
println!(
|
||||
"{:>W_LABEL$}: {:>W_NUM$}",
|
||||
"Redirects",
|
||||
n_redirects.separate_with_underscores()
|
||||
);
|
||||
|
||||
println!();
|
||||
println!(
|
||||
"{:>W_LABEL$}: {:>W_NUM$}",
|
||||
"Links",
|
||||
data.links.len().separate_with_underscores()
|
||||
);
|
||||
|
||||
println!(
|
||||
"{:>W_LABEL$}: {:>W_NUM$}",
|
||||
"in parens",
|
||||
data.links
|
||||
.iter()
|
||||
.filter(|l| l.in_parens())
|
||||
.count()
|
||||
.separate_with_underscores()
|
||||
);
|
||||
|
||||
println!(
|
||||
"{:>W_LABEL$}: {:>W_NUM$}",
|
||||
"in structures",
|
||||
data.links
|
||||
.iter()
|
||||
.filter(|l| l.in_structure())
|
||||
.count()
|
||||
.separate_with_underscores()
|
||||
);
|
||||
|
||||
println!(
|
||||
"{:>W_LABEL$}: {:>W_NUM$}",
|
||||
"pg eligible",
|
||||
data.links
|
||||
.iter()
|
||||
.filter(|l| !l.in_parens() && !l.in_structure())
|
||||
.count()
|
||||
.separate_with_underscores()
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
@ -54,19 +54,19 @@ fn follow_redirect(data: &Data, start: NodeIdx) -> Vec<NodeIdx> {
|
|||
nodes
|
||||
}
|
||||
|
||||
/// Show interesting redirect stats.
|
||||
/// Show redirect stats.
|
||||
#[derive(Debug, clap::Parser)]
|
||||
pub struct Cmd {
|
||||
/// Show more detailed info.
|
||||
#[arg(long, short)]
|
||||
long: bool,
|
||||
}
|
||||
|
||||
impl Cmd {
|
||||
pub fn run(self, data: Data) -> io::Result<()> {
|
||||
println!(">> Resolving redirects");
|
||||
println!(">> Resolve redirects");
|
||||
let redirects = find_redirects(&data);
|
||||
|
||||
println!();
|
||||
println!(
|
||||
"There is a total of {} redirects.",
|
||||
redirects.len().separate_with_underscores()
|
||||
|
|
@ -15,7 +15,7 @@ enum Command {
|
|||
Export(commands::export::Cmd),
|
||||
Show(commands::show::Cmd),
|
||||
Path(commands::path::Cmd),
|
||||
Redirects(commands::redirects::Cmd),
|
||||
Stats(commands::stats::Cmd),
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
|
|
@ -74,6 +74,6 @@ fn main() -> io::Result<()> {
|
|||
Command::Export(cmd) => cmd.run(data),
|
||||
Command::Show(cmd) => cmd.run(data),
|
||||
Command::Path(cmd) => cmd.run(data),
|
||||
Command::Redirects(cmd) => cmd.run(data),
|
||||
Command::Stats(cmd) => cmd.run(data),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue