Commit 489703d8 by dongshufeng

refactor(all): add iesplan example

parent 04eb97d7
......@@ -144,15 +144,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "boolinator"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -310,15 +301,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "cpufeatures"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0"
dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -370,16 +352,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "csv"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -433,16 +405,6 @@ dependencies = [
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]]
name = "displaydoc"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -759,16 +721,6 @@ dependencies = [
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -1234,12 +1186,10 @@ version = "0.1.0"
dependencies = [
"byteorder",
"bytes",
"chrono",
"cron",
"csv",
"eig-domain",
"getrandom",
"gloo-file 0.3.0",
"gloo-timers 0.3.0",
"gloo-utils 0.2.0",
"js-sys",
"log",
......@@ -1248,7 +1198,6 @@ dependencies = [
"serde-wasm-bindgen 0.6.5",
"serde_cbor",
"serde_json",
"sha2",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
......@@ -1323,9 +1272,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.160"
version = "0.2.161"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0b21006cd1874ae9e650973c565615676dc4a274c965bb0a73796dac838ce4f"
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
[[package]]
name = "linux-raw-sys"
......@@ -1666,9 +1615,9 @@ checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2"
[[package]]
name = "portable-atomic-util"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcdd8420072e66d54a407b3316991fe946ce3ab1083a7f575b2463866624704d"
checksum = "90a7d5beecc52a491b54d6dd05c7a45ba1801666a5baad9fdbfc6fef8d2d206c"
dependencies = [
"portable-atomic",
]
......@@ -1994,9 +1943,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.128"
version = "1.0.129"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
checksum = "6dbcf9b78a125ee667ae19388837dd12294b858d101fdd393cb9d5501ef09eb2"
dependencies = [
"itoa",
"memchr",
......@@ -2017,17 +1966,6 @@ dependencies = [
]
[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -2483,7 +2421,7 @@ dependencies = [
[[package]]
name = "yew-bulma"
version = "0.1.0"
source = "git+https://github.com/shufengdong/yew-bulma.git#26d4bab9e21144613448e0562c26ca09ce556cee"
source = "git+https://github.com/shufengdong/yew-bulma.git#2bd9d5ddc5c77c9797e427f488b3baa329abde66"
dependencies = [
"bytes",
"chrono",
......
use std::fmt;
use std::marker::PhantomData;
use csv::StringRecord;
use protobuf::{EnumFull, EnumOrUnknown};
use serde::{Deserialize, Serialize};
......@@ -332,3 +332,109 @@ fn deserialize_enum_or_unknown<'de, E: EnumFull, D: serde::Deserializer<'de>>(
d.deserialize_any(DeserializeEnumVisitor(PhantomData))
}
pub fn csv_str(record: &StringRecord, col: usize) -> Option<&str> {
Some(record.get(col)?.trim())
}
pub fn csv_string(record: &StringRecord, col: usize) -> Option<String> {
Some(record.get(col)?.trim().to_string())
}
pub fn csv_usize(record: &StringRecord, col: usize) -> Option<usize> {
let s = record.get(col)?.to_string();
let r = s.parse().ok()?;
Some(r)
}
pub fn csv_u8(record: &StringRecord, col: usize) -> Option<u8> {
let s = record.get(col)?.trim();
let r = if s.starts_with("0x") {
u8::from_str_radix(s.trim_start_matches("0x"), 16).ok()?
} else {
s.parse().ok()?
};
Some(r)
}
pub fn csv_u16(record: &StringRecord, col: usize) -> Option<u16> {
let s = record.get(col)?.trim();
let r = if s.starts_with("0x") {
u16::from_str_radix(s.trim_start_matches("0x"), 16).ok()?
} else {
s.parse().ok()?
};
Some(r)
}
pub fn csv_u32(record: &StringRecord, col: usize) -> Option<u32> {
let s = record.get(col)?.trim();
let r = if s.starts_with("0x") {
u32::from_str_radix(s.trim_start_matches("0x"), 16).ok()?
} else {
s.parse().ok()?
};
Some(r)
}
pub fn csv_u64(record: &StringRecord, col: usize) -> Option<u64> {
let s = record.get(col)?.trim();
let r = if s.starts_with("0x") {
u64::from_str_radix(s.trim_start_matches("0x"), 16).ok()?
} else {
s.parse().ok()?
};
Some(r)
}
pub fn csv_i8(record: &StringRecord, col: usize) -> Option<i8> {
let s = record.get(col)?.trim();
let r = if s.starts_with("0x") {
i8::from_str_radix(s.trim_start_matches("0x"), 16).ok()?
} else {
s.parse().ok()?
};
Some(r)
}
pub fn csv_i16(record: &StringRecord, col: usize) -> Option<i16> {
let s = record.get(col)?.trim();
let r = if s.starts_with("0x") {
i16::from_str_radix(s.trim_start_matches("0x"), 16).ok()?
} else {
s.parse().ok()?
};
Some(r)
}
pub fn csv_i32(record: &StringRecord, col: usize) -> Option<i32> {
let s = record.get(col)?.trim();
let r = if s.starts_with("0x") {
i32::from_str_radix(s.trim_start_matches("0x"), 16).ok()?
} else {
s.parse().ok()?
};
Some(r)
}
pub fn csv_i64(record: &StringRecord, col: usize) -> Option<i64> {
let s = record.get(col)?.trim();
let r = if s.starts_with("0x") {
i64::from_str_radix(s.trim_start_matches("0x"), 16).ok()?
} else {
s.parse().ok()?
};
Some(r)
}
pub fn csv_f64(record: &StringRecord, col: usize) -> Option<f64> {
let s = record.get(col)?.trim();
let r = s.parse().ok()?;
Some(r)
}
pub fn csv_f32(record: &StringRecord, col: usize) -> Option<f32> {
let s = record.get(col)?.trim();
let r = s.parse().ok()?;
Some(r)
}
\ No newline at end of file
......@@ -22,12 +22,9 @@ yew = { version = "0.21", features = ["csr"] }
yew-agent = "0.2"
gloo-utils = "0.2"
gloo-file = "0.3"
gloo-timers = "0.3"
sha2 = { version = "0.10", default-features = false }
getrandom = { version = "0.2", features = ["js"] }
chrono = { version = "0.4", features = ["wasmbind"] }
protobuf = { version = "3.7", features = ["with-bytes"] }
cron = "0.12"
csv = "1.3"
yew-bulma = { git = "https://github.com/shufengdong/yew-bulma.git" }
eig-domain = { path = "../../../eig-domain" }
# web-sys and js-sys
......@@ -35,3 +32,19 @@ js-sys = "0.3"
[dependencies.web-sys]
version = "0.3"
features = ["FormData", "File"]
[profile.release]
# Tell `rustc` to optimize for small code size.
# 二进制文件会包含更少的代码
panic = 'abort'
# 对所有代码库进行优化(优化更好,构建更慢)
codegen-units = 1
# 优化大小(更加激进)
opt-level = 0
# 优化大小
# opt-level = 's'
# 对整个程序进行链接时优化(link time optimization)
lto = true
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
\ No newline at end of file
1
\ No newline at end of file
0,car1,500
100001,name1,Checkbox
100002,name2,Checkbox
100003,name3,Checkbox
100004,name4,Checkbox
100005,name5,Checkbox
......@@ -2,6 +2,7 @@ use wasm_bindgen::prelude::*;
use web_sys::Element;
use crate::startpage::StartPage;
use yew_bulma::layout::tiles::Tiles;
use eig_domain::{csv_string, csv_u64, csv_usize};
use eig_domain::excel::get_first_sheet_merged_cells;
pub mod startpage;
mod paracard;
......@@ -26,13 +27,31 @@ pub enum ParaType {
pub struct Parameters {
id: usize,
name: String,
height: usize,
labels: Vec<String>,
points: Vec<u64>,
para_types: Vec<ParaType>,
}
pub fn create_parameters(csv_bytes: &[u8]) -> Option<Parameters> {
None
pub fn create_parameters(content: &[u8]) -> Parameters {
let mut rdr = csv::ReaderBuilder::new()
.has_headers(false)
.from_reader(content);
let mut records = rdr.records();
let record = records.next().unwrap().unwrap();
let id = csv_usize(&record, 0).unwrap();
let name = csv_string(&record, 1).unwrap();
let height = csv_usize(&record, 2).unwrap();
let mut labels = Vec::new();
let mut points = Vec::new();
let mut para_types = Vec::new();
for record in records {
let row = record.unwrap();
points.push(csv_u64(&row, 0).unwrap());
labels.push(csv_string(&row, 1).unwrap());
para_types.push(ParaType::Checkbox);
}
Parameters { id, name, height, labels, points, para_types }
}
pub fn build_tiles(xlsx_bytes: Vec<u8>) -> Option<Tiles> {
......
......@@ -30,8 +30,9 @@ impl Component for ParaCard {
let input_html = (0..paras.points.len()).map(|i| {
self.create_input(ctx, i)
}).collect::<Html>();
let height = format!("height:{}px", paras.height);
html! {
<Card>
<Card height={height}>
<CardHeader>
<p class="card-header-title">
{paras.name.clone()}
......
......@@ -4,13 +4,16 @@ use yew::prelude::*;
use yew_bulma::layout::tiles::Tiles;
use yew_bulma::*;
use crate::build_tiles;
use crate::{build_tiles, create_parameters, Parameters};
use crate::paracard::ParaCard;
pub enum Msg {
start,
}
pub struct StartPage {
tiles: Tiles,
general_para: Parameters,
}
impl Component for StartPage {
......@@ -19,7 +22,8 @@ impl Component for StartPage {
fn create(_: &Context<Self>) -> Self {
let tiles = build_tiles(include_bytes!("../layout.xlsx").to_vec()).unwrap();
Self { tiles }
let general_para = create_parameters(include_bytes!("../general.csv"));
Self { tiles, general_para }
}
fn update(&mut self, _: &Context<Self>, msg: Self::Message) -> bool {
......@@ -39,6 +43,9 @@ impl Component for StartPage {
};
nodes.insert(i, v);
}
nodes.insert(self.general_para.id, html! {
<ParaCard paras={self.general_para.clone()} />
});
self.tiles.create_html(nodes)
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论