From 1e82d52df4195122c479192a51ff7aab0d022b91 Mon Sep 17 00:00:00 2001 From: FlareFlo Date: Wed, 3 Jul 2024 17:37:25 +0200 Subject: [PATCH 1/3] Added: Export every missile csv at once --- Cargo.lock | 63 ++++++++++++++++++++--------- js/missile_ballistics.js | 35 +++++++++++++++- src/missile_ballistics.rs | 26 ++++++++++++ static/html/missile_ballistics.html | 1 + 4 files changed, 105 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9aca65a..7e53fef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,6 +43,15 @@ dependencies = [ "libc", ] +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +dependencies = [ + "derive_arbitrary", +] + [[package]] name = "attribute-derive" version = "0.6.1" @@ -409,6 +418,17 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "derive_arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +dependencies = [ + "proc-macro2 1.0.86", + "quote 1.0.36", + "syn 2.0.68", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -430,6 +450,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2 1.0.86", + "quote 1.0.36", + "syn 2.0.68", +] + [[package]] name = "dlib" version = "0.5.2" @@ -1842,9 +1873,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.7.8" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" dependencies = [ "serde", "serde_spanned", @@ -1863,15 +1894,14 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.22.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", - "winnow", ] [[package]] @@ -2304,15 +2334,6 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" -[[package]] -name = "winnow" -version = "0.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" -dependencies = [ - "memchr", -] - [[package]] name = "winreg" version = "0.10.1" @@ -2340,12 +2361,12 @@ checksum = "16905f154f353035a05927b3829fe7eec34d06468fa2a4c6b6669c3dfcacc1d4" [[package]] name = "wt_ballistics_calc" version = "0.1.0" -source = "git+https://github.com/FlareFlo/wt_ballistics_calc#e9a549ff80adf4163246f5c4b7088fa9a83afe2e" +source = "git+https://github.com/FlareFlo/wt_ballistics_calc#db0c99e33b8a4d8d981eac6b59b1c0674c479a12" dependencies = [ "pad", "serde", "serde_json", - "toml 0.7.8", + "toml 0.8.14", "wt_datamine_extractor", "zip", ] @@ -2458,11 +2479,15 @@ dependencies = [ [[package]] name = "zip" -version = "0.6.6" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +checksum = "775a2b471036342aa69bc5a602bc889cb0a06cda00477d0c69566757d5553d39" dependencies = [ - "byteorder", + "arbitrary", "crc32fast", "crossbeam-utils", + "displaydoc", + "indexmap", + "memchr", + "thiserror", ] diff --git a/js/missile_ballistics.js b/js/missile_ballistics.js index 0743238..5da2b37 100644 --- a/js/missile_ballistics.js +++ b/js/missile_ballistics.js @@ -1,4 +1,4 @@ -import init, {export_zip, main_js, plot, run_compare} from "../pkg"; +import init, {export_zip, main_js, plot, run_compare, export_all_to_zip} from "../pkg"; import {input_manager, set_value_enter, sleep} from "./util"; async function main() { @@ -72,6 +72,39 @@ async function main() { }); + document.getElementById("export_all_zip").addEventListener("click", () => { + const downloadBlob = function(data, fileName, mimeType) { + var blob, url; + blob = new Blob([data], { + type: mimeType + }); + url = window.URL.createObjectURL(blob); + downloadURL(url, fileName); + setTimeout(function() { + return window.URL.revokeObjectURL(url); + }, 1000); + }; + + const downloadURL = function(data, fileName) { + var a; + a = document.createElement('a'); + a.href = data; + a.download = fileName; + document.body.appendChild(a); + a.style = 'display: none'; + a.click(); + a.remove(); + }; + + const bytes = new Uint8Array(); + const zip = export_all_to_zip( + parseInt(document.getElementById("altitude").value), + parseInt(document.getElementById("velocity").value) + ); + downloadBlob(zip, "missile_sim.zip", "application/zip"); + + }); + let canvas_scale = 1; let canvas_translate = (0, 0); let canvas = document.getElementById("ballistics"); diff --git a/src/missile_ballistics.rs b/src/missile_ballistics.rs index 6edc452..9b7bce5 100644 --- a/src/missile_ballistics.rs +++ b/src/missile_ballistics.rs @@ -8,6 +8,7 @@ use wt_ballistics_calc_lib::runner::{generate, LaunchResults}; use std::str::FromStr; use std::sync::Mutex; +use js_sys::Math::min; use wt_datamine_extractor_lib::missile::missile::Missile; const WIDTH: u32 = 3840; @@ -245,3 +246,28 @@ pub fn export_zip(plot_png: &[u8]) -> Vec { let file = res.as_csv(Some(plot_png), missile); file.unwrap() } + +#[wasm_bindgen] +pub fn export_all_to_zip(altitude: u32, start_velocity: f64) -> Vec { + let mut zip = None; + for missile in MISSILES.iter() { + let results = generate( + missile, + LaunchParameter { + use_gravity: false, + start_velocity, + distance_to_target: 0.0, + target_speed: 0.0, + altitude, + }, + TIMESTEP, + false, + ); + if zip.is_none() { + zip = Some(results.start_csv(None, missile.clone())); + } else { + results.write_into_zip(None, missile.clone(), zip.as_mut().unwrap()).unwrap(); + } + } + LaunchResults::finish_zip(zip.unwrap()).unwrap() +} diff --git a/static/html/missile_ballistics.html b/static/html/missile_ballistics.html index 0a7e775..44ca3dc 100644 --- a/static/html/missile_ballistics.html +++ b/static/html/missile_ballistics.html @@ -51,6 +51,7 @@

+