diff options
Diffstat (limited to 'tables/src/main.rs')
| -rw-r--r-- | tables/src/main.rs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tables/src/main.rs b/tables/src/main.rs new file mode 100644 index 0000000..3af0171 --- /dev/null +++ b/tables/src/main.rs @@ -0,0 +1,69 @@ +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::<String>()?; + + 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::<i32, &str>("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::<i32, &str>("ind_dom") as usize; + let forced_geod = row.get::<i32, &str>("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("")); + + Ok(()) +} |