summaryrefslogtreecommitdiff
path: root/graph-checker/src/gui.rs
diff options
context:
space:
mode:
Diffstat (limited to 'graph-checker/src/gui.rs')
-rw-r--r--graph-checker/src/gui.rs83
1 files changed, 83 insertions, 0 deletions
diff --git a/graph-checker/src/gui.rs b/graph-checker/src/gui.rs
new file mode 100644
index 0000000..2a363e2
--- /dev/null
+++ b/graph-checker/src/gui.rs
@@ -0,0 +1,83 @@
+use crate::compute;
+use crate::geng::GengIterator;
+use crate::graph;
+use eframe::egui;
+use std::sync::mpsc;
+use std::time::{Duration, Instant};
+use tokio;
+
+pub fn run_gui(rt: tokio::runtime::Runtime) {
+ let options = eframe::NativeOptions::default();
+ let _ = eframe::run_native(
+ "Graph checker",
+ options,
+ Box::new(|_cc| Ok(Box::new(Application::new(rt)))),
+ );
+}
+
+struct Application {
+ rt: tokio::runtime::Runtime,
+}
+
+impl Application {
+ fn new(rt: tokio::runtime::Runtime) -> Self {
+ Self { rt }
+ }
+}
+
+impl eframe::App for Application {
+ fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
+ let mut c = ComputeWindow::new(&self.rt);
+ egui::Window::new("Spawn tasks").show(ctx, |ui| {
+ c.update(ui);
+ });
+ }
+}
+
+struct ComputeWindow<'a> {
+ rt: &'a tokio::runtime::Runtime,
+ computed: Vec<graph::GraphProfile>,
+ rx: mpsc::Receiver<graph::GraphProfile>,
+ tx: mpsc::Sender<graph::GraphProfile>,
+}
+
+impl<'a> ComputeWindow<'a> {
+ fn new(rt: &'a tokio::runtime::Runtime) -> Self {
+ let (tx, rx) = mpsc::channel();
+ Self {
+ rt,
+ computed: Vec::new(),
+ rx,
+ tx,
+ }
+ }
+
+ fn update(&mut self, ui: &mut egui::Ui) {
+ if ui.button("Посчитать графы").clicked() {
+ let gi = GengIterator::new(7);
+ let _tasks: Vec<_> = gi
+ .map(|g| {
+ // let db = db.clone();
+ let tx = self.tx.clone();
+ self.rt.spawn(async move {
+ tx.send(compute::async_theorems1(g).await).unwrap();
+ })
+ })
+ .collect();
+ }
+
+ if let Ok(p) = self.rx.recv_timeout(Duration::from_millis(10)) {
+ self.computed.push(p);
+ }
+
+ ui.label(format!("Посчитано графов: {}", self.computed.len()));
+
+ // let start = Instant::now();
+ // let res = futures::future::join_all(tasks).await;
+ // let elapsed = start.elapsed();
+ // let time = elapsed.as_nanos();
+ // let res = res.iter().map(|e| e.as_ref().unwrap()).collect::<Vec<_>>();
+ // println!("len = {}", res.len());
+ // println!("Time elapsed: {}s", time as f64 / 1e9);
+ }
+}