diff --git a/Cargo.lock b/Cargo.lock index 4db4274..dcefbce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,10 +3,19 @@ version = 3 [[package]] -name = "autocfg" -version = "1.0.1" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base-x" @@ -26,6 +35,12 @@ version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + [[package]] name = "cfg-if" version = "0.1.10" @@ -38,6 +53,31 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-integer", + "num-traits", + "time 0.1.45", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "console_error_panic_hook" version = "0.1.6" @@ -61,10 +101,60 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" dependencies = [ "percent-encoding", - "time", + "time 0.2.26", "version_check 0.9.3", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "cxx" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dbg" version = "1.0.4" @@ -209,7 +299,7 @@ dependencies = [ "cfg-if 1.0.0", "js-sys", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi 0.10.0+wasi-snapshot-preview1", "wasm-bindgen", ] @@ -255,6 +345,36 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "iana-time-zone" +version = "0.1.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "indexmap" version = "1.6.2" @@ -265,6 +385,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "itoa" version = "0.4.7" @@ -288,9 +417,28 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.92" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "link-cplusplus" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" +dependencies = [ + "cc", +] + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] [[package]] name = "log" @@ -307,6 +455,56 @@ version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "percent-encoding" version = "2.1.0" @@ -424,6 +622,15 @@ dependencies = [ "rand_core", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + [[package]] name = "rustc_version" version = "0.2.3" @@ -445,6 +652,18 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "scratch" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" + [[package]] name = "seed" version = "0.8.0" @@ -529,6 +748,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + [[package]] name = "standback" version = "0.2.17" @@ -598,6 +823,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.38" @@ -618,6 +852,17 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + [[package]] name = "time" version = "0.2.26" @@ -660,10 +905,13 @@ dependencies = [ name = "tracerviewer" version = "0.1.0" dependencies = [ + "chrono", + "humantime", "seed", "serde", "thiserror", "wasm-bindgen-test", + "wasm-timer", ] [[package]] @@ -716,9 +964,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" @@ -812,6 +1060,21 @@ dependencies = [ "quote", ] +[[package]] +name = "wasm-timer" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" +dependencies = [ + "futures", + "js-sys", + "parking_lot", + "pin-utils", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "web-sys" version = "0.3.50" @@ -838,6 +1101,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 421ac20..0bc127e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,12 @@ crate-type = ["cdylib"] wasm-bindgen-test = "0.3.18" [dependencies] +chrono = "0.4.23" +humantime = "2.1.0" seed = "0.8.0" serde = "1.0.152" thiserror = "1.0.38" +wasm-timer = "0.2.5" [profile.release] lto = true diff --git a/index.css b/index.css new file mode 100644 index 0000000..2815869 --- /dev/null +++ b/index.css @@ -0,0 +1,23 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", + "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", + monospace; +} + +html, body, #root { + background-color: #000; + color: #fff; + height: 100%; +} + +.fresh { + color: #4f4; +} diff --git a/index.html b/index.html index 6a97472..0b426df 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,8 @@ + + diff --git a/src/lib.rs b/src/lib.rs index c1725b5..ed186e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,10 +3,14 @@ // but some rules are too "annoying" or are not applicable for your case.) #![allow(clippy::wildcard_imports)] -use std::sync::Arc; +use std::{sync::Arc, time::Duration}; +use chrono::{DateTime, Local, NaiveDateTime, TimeZone}; use seed::{prelude::*, *}; use thiserror::Error; +use wasm_timer::{SystemTime, UNIX_EPOCH}; + +const ROOT_URL: &'static str = "/www/tracer/"; #[derive(Clone, Error, Debug)] pub enum AppError { @@ -22,7 +26,6 @@ pub enum AppError { fn init(_: Url, orders: &mut impl Orders) -> Model { let timer_handle = orders.stream_with_handle(streams::interval(1000, || Msg::OnCheck)); Model { - counter: 0, timer_handle, data: None, error: None, @@ -35,7 +38,6 @@ fn init(_: Url, orders: &mut impl Orders) -> Model { // `Model` describes our app state. struct Model { - counter: i32, timer_handle: StreamHandle, data: Option, error: Option, @@ -49,7 +51,6 @@ struct Model { #[derive(Clone)] // `Msg` describes the different events you can modify state with. enum Msg { - Increment, OnCheck, OnError(AppError), Received(Data), @@ -58,14 +59,20 @@ enum Msg { // `update` describes how to handle each `Msg`. fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders) { match msg { - Msg::Increment => model.counter += 1, Msg::OnError(e) => model.error = Some(e), Msg::OnCheck => { orders.skip(); // No need to rerender orders.perform_cmd(async { - let response = fetch("/www/tracer/data.json") - .await - .expect("HTTP request failed"); + let response = fetch(format!( + "{}/data.json?t={}", + ROOT_URL, + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs() + )) + .await + .expect("HTTP request failed"); match response .check_status() // ensure we've got 2xx status @@ -100,8 +107,6 @@ struct Data { scene: Scene, image_metadata: Vec, } - -// TODO(wathiede): implement the skips and then the renderer could use json as an input file type. #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Scene { @@ -123,10 +128,80 @@ pub enum ImageType { // ------ ------ // View // ------ ------ +fn view_metadata_table(data: &Data) -> Node { + fn row(name: &str, value: T) -> Node + where + T: std::fmt::Debug, + { + let mut v = format!("{:?}", value); + if &v == "None" { + v = "❌".to_string(); + } + tr![td![name], td![v]] + } + //❌ + //✔️ + let d = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .saturating_sub(Duration::from_secs(data.timestamp as u64)); + let fresh = d.as_secs() < 60; + // Round to the second + let d = Duration::from_secs(d.as_secs()); + + let dt = NaiveDateTime::from_timestamp_opt(data.timestamp, 0).unwrap(); + let dt = Local.from_local_datetime(&dt).unwrap(); + div![ + div!["Rendered @ ", dt.format("%Y-%m-%d %H:%M:%S").to_string()], + div![ + C![IF!(fresh => "fresh")], + humantime::format_duration(d).to_string(), + " ago" + ], + table![ + C!["table", "is-striped", "is-narrow"], + tbody![ + tr![th!["Name"], th!["Value"]], + row("subsamples", data.scene.subsamples), + row("adaptive_subsampling", data.scene.adaptive_subsampling), + row("num_threads", data.scene.num_threads), + row("width", data.scene.width), + row("height", data.scene.height), + row("global_illumination", data.scene.global_illumination), + ], + ] + ] +} + +fn view_image(im: &ImageMetadata) -> Node { + let url = format!("{ROOT_URL}/{}", im.image); + div![ + a![attrs! {At::Href => url}, p![&im.name]], + a![attrs! {At::Href => url}, img![attrs! { At::Src => url}]] + ] +} + +fn view_data(data: &Data) -> Node { + div![ + C!["columns"], + div![C!["column", "is-narrow"], view_metadata_table(data),], + div![ + C!["column"], + data.image_metadata.iter().map(|im| view_image(im)) + ] + ] +} // `view` describes what to display. fn view(model: &Model) -> Node { - div!["Data", pre![format!("{:#?}", model.data)],] + div![ + match &model.data { + Some(data) => view_data(data), + None => h1!["Loading...."], + }, + "Data", + pre![format!("{:#?}", model.data)], + ] } // ------ ------