Slowly switch over to raw data input instead of file system access
This commit is contained in:
parent
e6f47328a0
commit
54200678ab
|
@ -1142,21 +1142,6 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.28"
|
||||
|
@ -1164,7 +1149,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1173,17 +1157,6 @@ version = "0.3.28"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.28"
|
||||
|
@ -1205,17 +1178,6 @@ dependencies = [
|
|||
"waker-fn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.33",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.28"
|
||||
|
@ -1234,10 +1196,8 @@ version = "0.3.28"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-macro",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
|
@ -2413,7 +2373,6 @@ dependencies = [
|
|||
"egui",
|
||||
"env_logger",
|
||||
"fast-float",
|
||||
"futures",
|
||||
"log",
|
||||
"palette",
|
||||
"rfd",
|
||||
|
|
|
@ -70,8 +70,15 @@ impl Database {
|
|||
database
|
||||
}
|
||||
|
||||
pub fn from_string(string: &String) -> Self {
|
||||
let database: Self = serde_json::from_str(&string)
|
||||
.unwrap_or_else(|_| panic!("Cannot deserialize file from data"));
|
||||
|
||||
database
|
||||
}
|
||||
|
||||
pub fn from_config(config: &config::Config) -> Self {
|
||||
Database::from_file(&format!("./{}/{}", &config.data_dir, &config.main_json))
|
||||
Database::from_file(&format!("{}/{}", &config.data_dir, &config.main_json))
|
||||
}
|
||||
|
||||
pub fn bean_names(&self) -> Vec<String> {
|
||||
|
|
|
@ -32,6 +32,7 @@ pub fn database_plot_entry(brew: &Brew, config: &Config, database: &Database) ->
|
|||
if !&flow_profile.is_empty() {
|
||||
let brew_title = brew.date_time_with_bean(&database);
|
||||
|
||||
// TODO: CHANGE to raw. Maybe include some Option<ZipArchive...> in Config?!
|
||||
let flow_profile =
|
||||
FlowProfile::from_file(&format!("{}/{}", &config.data_dir, &flow_profile), None)
|
||||
.preprocess_json();
|
||||
|
|
62
src/ui.rs
62
src/ui.rs
|
@ -4,6 +4,7 @@ use eframe::egui;
|
|||
|
||||
use egui::{plot::{Legend, Line, Plot}, Align, Layout, ProgressBar, Modifiers};
|
||||
use rfd::{FileHandle, AsyncFileDialog};
|
||||
use zip::ZipArchive;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
|
@ -13,7 +14,7 @@ use crate::{
|
|||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
thread::{self, JoinHandle},
|
||||
thread::{self, JoinHandle}, io::{Read, Cursor}, default,
|
||||
};
|
||||
use std::{
|
||||
env,
|
||||
|
@ -39,7 +40,8 @@ pub struct Ui {
|
|||
|
||||
loading_progress: Arc<Mutex<LoadingProgress>>,
|
||||
loading_data: Arc<Mutex<Option<LoadingData>>>,
|
||||
loading_file: Arc<Mutex<Option<Vec<u8>>>>,
|
||||
config_file: Arc<Mutex<Option<Vec<u8>>>>,
|
||||
zip_file: Arc<Mutex<Option<ZipArchive<Cursor<Vec<u8>>>>>>,
|
||||
data_transfered: bool,
|
||||
|
||||
config: Config,
|
||||
|
@ -316,7 +318,7 @@ impl eframe::App for Ui {
|
|||
|ui| {
|
||||
let file_loaded: bool;
|
||||
{
|
||||
file_loaded = self.loading_file.lock().unwrap().is_some();
|
||||
file_loaded = self.config_file.lock().unwrap().is_some();
|
||||
}
|
||||
if file_loaded {
|
||||
let loading_finished: bool;
|
||||
|
@ -328,7 +330,8 @@ impl eframe::App for Ui {
|
|||
self.modal = true;
|
||||
self.show_loading_screen = true;
|
||||
|
||||
let loading_file_arc = self.loading_file.clone();
|
||||
let config_file_arc = self.config_file.clone();
|
||||
let zip_file_arc = self.zip_file.clone();
|
||||
let loading_data_arc = self.loading_data.clone();
|
||||
let loading_progress_arc = self.loading_progress.clone();
|
||||
let ctx_clone = ctx.clone();
|
||||
|
@ -338,11 +341,17 @@ impl eframe::App for Ui {
|
|||
|
||||
let mut loading_data = LoadingData::default();
|
||||
|
||||
let loading_file_lock = loading_file_arc.lock().unwrap();
|
||||
loading_data.config = Config::from_raw(loading_file_lock.as_ref().expect("No file loaded"));
|
||||
let config_file_lock = config_file_arc.lock().unwrap();
|
||||
let mut zip_file_lock = zip_file_arc.lock().unwrap();
|
||||
|
||||
loading_data.database =
|
||||
Database::from_config(&loading_data.config);
|
||||
loading_data.config = Config::from_raw(config_file_lock.as_ref().expect("No config file loaded"));
|
||||
|
||||
let main_filename = format!("{}/{}", &loading_data.config.data_dir, &loading_data.config.main_json);
|
||||
let mut zip_file = zip_file_lock.as_mut().expect("No data zip file loaded");
|
||||
let mut main_file = zip_file.by_name(&main_filename).expect("Can't get main file {main_filename}");
|
||||
let mut main_file_string = String::new();
|
||||
main_file.read_to_string(&mut main_file_string).expect("Can't read main file {main_file} to string");
|
||||
loading_data.database = Database::from_string(&main_file_string);
|
||||
|
||||
let mut checkboxes = HashMap::new();
|
||||
|
||||
|
@ -426,10 +435,11 @@ impl eframe::App for Ui {
|
|||
ui.label("Select the config file (.toml) to start");
|
||||
|
||||
if ui.button("Load file").clicked() {
|
||||
let loading_file_arc = self.loading_file.clone();
|
||||
let config_file_arc = self.config_file.clone();
|
||||
let zip_file_arc = self.zip_file.clone();
|
||||
|
||||
let file_dialog = async move {
|
||||
let file = AsyncFileDialog::new()
|
||||
let config_file = AsyncFileDialog::new()
|
||||
.add_filter("toml", &["toml"])
|
||||
.set_directory(
|
||||
match &env::current_dir() {
|
||||
|
@ -437,12 +447,38 @@ impl eframe::App for Ui {
|
|||
Err(_) => None,
|
||||
}.unwrap_or_default()
|
||||
)
|
||||
.set_title("Config file [.toml]")
|
||||
.set_file_name("config.toml")
|
||||
.pick_file().await;
|
||||
|
||||
let data = file.unwrap().read().await;
|
||||
let config_data = config_file.unwrap().read().await;
|
||||
|
||||
let mut loading_file_lock = loading_file_arc.lock().unwrap();
|
||||
*loading_file_lock = Some(data);
|
||||
let zip_file = AsyncFileDialog::new()
|
||||
.add_filter("zip", &["zip"])
|
||||
.set_directory(
|
||||
match &env::current_dir() {
|
||||
Ok(path) => path.to_str(),
|
||||
Err(_) => None,
|
||||
}.unwrap_or_default()
|
||||
)
|
||||
.set_title("Data archive [.zip]")
|
||||
.set_file_name("beanconqueror.zip")
|
||||
.pick_file().await;
|
||||
|
||||
let zip_data = zip_file.unwrap().read().await;
|
||||
|
||||
let mut config_file_lock = config_file_arc.lock().unwrap();
|
||||
*config_file_lock = Some(config_data);
|
||||
|
||||
if let Ok(zip) = zip::ZipArchive::new(Cursor::new(zip_data)) {
|
||||
println!("Files inside zip:");
|
||||
for name in zip.file_names() {
|
||||
println!("Name: {name}");
|
||||
}
|
||||
|
||||
let mut zip_file_lock = zip_file_arc.lock().unwrap();
|
||||
*zip_file_lock = Some(zip);
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
|
Loading…
Reference in New Issue