use anyhow::Context; use sqlx::{migrate::MigrateDatabase, Row}; #[tokio::main] async fn main() -> anyhow::Result<()> { let database_url = std::env::args() .nth(1) .context("You should provide path to the database")? .parse::()?; if !sqlx::Sqlite::database_exists(&database_url).await? { return Err(anyhow::Error::msg(format!( "Database {database_url} not found" ))); } let db = sqlx::SqlitePool::connect(&database_url).await?; let g0 = sqlx::query("SELECT size FROM graphs LIMIT 1") .fetch_one(&db) .await?; let vert_num = g0.get::("size") as usize; println!("Size of graphs: {vert_num}"); let mut res = vec![vec![0; vert_num + 1]; vert_num + 1]; let graphs = sqlx::query("SELECT ind_dom, forced_geod FROM graphs") .fetch_all(&db) .await?; let mut cnt = 0; for row in graphs.into_iter() { let ind_dom = row.get::("ind_dom") as usize; let forced_geod = row.get::("forced_geod") as usize; res[ind_dom][forced_geod] += 1; cnt += 1; } println!("Number of rows: {cnt}"); let mut table = Vec::new(); table.push("\\begin{table}[H]\n".to_string()); table.push(" \\centering\n".to_string()); table.push(format!( " \\caption{{Результаты вычислений для графов с {} вершинами}}\n", vert_num )); table.push(" \\begin{tabular}{".to_string()); for _ in 0..=vert_num + 1 { table.push("|c".to_string()); } table.push("|}\n".to_string()); table.push(" \\hline\n".to_string()); table.push(" $i(G)$ \\textbackslash{} $fg(G)$ ".to_string()); for i in 0..=vert_num { table.push(format!("& {i} ")); } table.push("\\\\ \\hline\n".to_string()); for i in 0..=vert_num { table.push(" ".to_string()); table.push(format!("{i} ")); for j in 0..=vert_num { table.push(format!("& {} ", res[i][j])); } table.push(" \\\\ \\hline\n".to_string()); } table.push(" \\end{tabular}\n".to_string()); table.push("\\end{table}\n".to_string()); println!("{}", table.join("")); db.close().await; Ok(()) }