Commit 22288392 by dongshufeng

put common function in ds-common

parent dce60e55
......@@ -16,5 +16,6 @@ num-complex = "0.4"
ndarray = "0.15"
nalgebra = "0.33"
ds-common = { path = "../ds-common" }
eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" }
\ No newline at end of file
......@@ -5,9 +5,10 @@ use std::collections::HashMap;
use arrow_schema::{DataType, Field, Schema};
use ndarray::Array2;
use ds_common::dyn_topo::{read_dev_topo, read_dyn_topo};
use mems::model::{get_wasm_result, PluginInput, PluginOutput};
use crate::read::{read_dev_ohm, read_dev_topo, read_dyn_topo, read_tn_input};
use crate::read::{read_dev_ohm, read_tn_input};
mod read;
mod nlp;
......
......@@ -7,78 +7,6 @@ use eig_domain::DataUnit;
use mems::model::dev::MeasPhase;
const MAT_SIZE: usize = 2 * 54;
pub(crate) fn read_dyn_topo(records: &mut StringRecordsIter<&[u8]>)
-> Result<Vec<Vec<u64>>, String> {
let mut dyn_topo = Vec::new();
// 按行读取csv
let mut row = 0;
loop {
match records.next() {
Some(Ok(record)) => {
let mut col = 0;
dyn_topo.push(vec![0u64; 2]);
for str in record.iter() {
if let Ok(id) = str.parse() {
dyn_topo[row][col] = id;
} else {
return Err(format!("Wrong dynamic topology input, row {row} col {col}"));
}
col += 1;
if col == 2 {
break;
}
}
if col != 2 {
return Err(format!("Wrong dynamic topology input, expected col 2, actual {col}"));
}
}
Some(Err(e)) => {
return Err(format!("Wrong dynamic topology input, err: {:?}", e));
}
None => {
break;
}
}
row += 1;
}
Ok(dyn_topo)
}
pub(crate) fn read_dev_topo(records: &mut StringRecordsIter<&[u8]>)
-> Result<Vec<Vec<u64>>, String> {
let mut dev_topo = Vec::new();
// 按行读取csv
let mut row = 0;
loop {
match records.next() {
Some(Ok(record)) => {
let mut col = 0;
dev_topo.push(vec![0u64; 4]);
for str in record.iter() {
if let Ok(id) = str.parse() {
dev_topo[row][col] = id;
} else {
return Err(format!("Wrong device topology, row {row} col {col}"));
}
col += 1;
if col == 4 {
break;
}
}
if col != 4 {
return Err(format!("Wrong device topology input, expected col 4, actual {col}"));
}
}
Some(Err(e)) => {
return Err(format!("Wrong device topology input, err: {:?}", e));
}
None => {
break;
}
}
row += 1;
}
Ok(dev_topo)
}
pub(crate) fn read_dev_ohm(records: &mut StringRecordsIter<&[u8]>)
-> Result<HashMap<u64, Vec<Array2<f64>>>, String> {
......
......@@ -6,4 +6,5 @@ edition = "2021"
[dependencies]
log = "0.4"
serde_json = "1.0"
csv = "1.3.0"
\ No newline at end of file
csv = "1.3.0"
mems = { path = "../../../mems" }
\ No newline at end of file
use csv::StringRecordsIter;
pub fn read_dyn_topo(records: &mut StringRecordsIter<&[u8]>)
-> Result<Vec<Vec<u64>>, String> {
let mut dyn_topo = Vec::new();
// 按行读取csv
let mut row = 0;
loop {
match records.next() {
Some(Ok(record)) => {
let mut col = 0;
dyn_topo.push(vec![0u64; 2]);
for str in record.iter() {
if let Ok(id) = str.parse() {
dyn_topo[row][col] = id;
} else {
return Err(format!("Wrong dynamic topology input, row {row} col {col}"));
}
col += 1;
if col == 2 {
break;
}
}
if col != 2 {
return Err(format!("Wrong dynamic topology input, expected col 2, actual {col}"));
}
}
Some(Err(e)) => {
return Err(format!("Wrong dynamic topology input, err: {:?}", e));
}
None => {
break;
}
}
row += 1;
}
Ok(dyn_topo)
}
pub fn read_dev_topo(records: &mut StringRecordsIter<&[u8]>)
-> Result<Vec<Vec<u64>>, String> {
let mut dev_topo = Vec::new();
// 按行读取csv
let mut row = 0;
loop {
match records.next() {
Some(Ok(record)) => {
let mut col = 0;
dev_topo.push(vec![0u64; 4]);
for str in record.iter() {
if let Ok(id) = str.parse() {
dev_topo[row][col] = id;
} else {
return Err(format!("Wrong device topology, row {row} col {col}"));
}
col += 1;
if col == 4 {
break;
}
}
if col != 4 {
return Err(format!("Wrong device topology input, expected col 4, actual {col}"));
}
}
Some(Err(e)) => {
return Err(format!("Wrong device topology input, err: {:?}", e));
}
None => {
break;
}
}
row += 1;
}
Ok(dev_topo)
}
use csv::StringRecordsIter;
pub mod dyn_topo;
pub mod static_topo;
const STATIC_TOPO_DF_NAME: &str = "static_topo";
const TERMINAL_DF_NAME: &str = "terminal_cn_dev";
const POINT_DF_NAME: &str = "point_terminal_phase";
pub const DYN_TOPO_DF_NAME: &str = "dyn_topo";
pub const DEV_TOPO_DF_NAME: &str = "dev_topo";
pub fn read_dyn_topo(records: &mut StringRecordsIter<&[u8]>)
-> Result<Vec<Vec<u64>>, String> {
let mut dyn_topo = Vec::new();
// 按行读取csv
let mut row = 0;
loop {
match records.next() {
Some(Ok(record)) => {
let mut col = 0;
dyn_topo.push(vec![0u64; 2]);
for str in record.iter() {
if let Ok(id) = str.parse() {
dyn_topo[row][col] = id;
} else {
return Err(format!("Wrong dynamic topology input, row {row} col {col}"));
}
col += 1;
if col == 2 {
break;
}
}
if col != 2 {
return Err(format!("Wrong dynamic topology input, expected col 2, actual {col}"));
}
}
Some(Err(e)) => {
return Err(format!("Wrong dynamic topology input, err: {:?}", e));
}
None => {
break;
}
}
row += 1;
}
Ok(dyn_topo)
}
pub fn read_dev_topo(records: &mut StringRecordsIter<&[u8]>)
-> Result<Vec<Vec<u64>>, String> {
let mut dev_topo = Vec::new();
// 按行读取csv
let mut row = 0;
loop {
match records.next() {
Some(Ok(record)) => {
let mut col = 0;
dev_topo.push(vec![0u64; 4]);
for str in record.iter() {
if let Ok(id) = str.parse() {
dev_topo[row][col] = id;
} else {
return Err(format!("Wrong device topology, row {row} col {col}"));
}
col += 1;
if col == 4 {
break;
}
}
if col != 4 {
return Err(format!("Wrong device topology input, expected col 4, actual {col}"));
}
}
Some(Err(e)) => {
return Err(format!("Wrong device topology input, err: {:?}", e));
}
None => {
break;
}
}
row += 1;
}
Ok(dev_topo)
}
pub const DEV_CONDUCTOR_DF_NAME: &str = "dev_ohm";
pub const TN_INPUT_DF_NAME: &str = "tn_input";
......@@ -2,7 +2,7 @@ use std::collections::HashMap;
use csv::StringRecordsIter;
use mems::model::dev::PsRsrType;
pub(crate) fn read_points(records: &mut StringRecordsIter<&[u8]>) -> Result<Vec<Vec<u64>>, String> {
pub fn read_points(records: &mut StringRecordsIter<&[u8]>) -> Result<Vec<Vec<u64>>, String> {
let mut points = Vec::new();
// 按行读取csv
let mut row = 0;
......@@ -38,7 +38,7 @@ pub(crate) fn read_points(records: &mut StringRecordsIter<&[u8]>) -> Result<Vec<
Ok(points)
}
pub(crate) fn read_terminals(records: &mut StringRecordsIter<&[u8]>) -> Result<Vec<Vec<u64>>, String> {
pub fn read_terminals(records: &mut StringRecordsIter<&[u8]>) -> Result<Vec<Vec<u64>>, String> {
let mut terminals: Vec<Vec<u64>> = Vec::new();
// 按行读取csv
let mut row = 0;
......@@ -74,8 +74,8 @@ pub(crate) fn read_terminals(records: &mut StringRecordsIter<&[u8]>) -> Result<V
Ok(terminals)
}
pub(crate) fn read_edges(records: &mut StringRecordsIter<&[u8]>)
-> Result<(Vec<Vec<u64>>, HashMap<u64, bool>), String> {
pub fn read_edges(records: &mut StringRecordsIter<&[u8]>)
-> Result<(Vec<Vec<u64>>, HashMap<u64, bool>), String> {
let mut edges = Vec::new();
let mut normal_open = HashMap::new();
let mut row = 0;
......
......@@ -8,8 +8,9 @@ crate-type = ["cdylib"]
[dependencies]
log = "0.4"
csv = "1.3.0"
serde_cbor = "0.11"
arrow-schema = { version = "52.1", features = ["serde"] }
eig-domain = { path = "../../../eig-domain" }
mems = { path = "../../../mems" }
csv = "1.3.0"
\ No newline at end of file
ds-common = { path = "../ds-common" }
\ No newline at end of file
......@@ -4,14 +4,8 @@ use arrow_schema::{DataType, Field, Schema};
use eig_domain::DataUnit;
use mems::model::{get_df_from_in_plugin, get_meas_from_plugin_input, get_wasm_result, ModelType, PluginInput, PluginOutput};
use crate::read::{read_edges, read_points, read_terminals};
mod read;
use ds_common::static_topo::{read_edges, read_points, read_terminals};
const STATIC_TOPO_DF_NAME: &str = "static_topo";
const TERMINAL_DF_NAME: &str = "terminal_cn_dev";
const POINT_DF_NAME: &str = "point_terminal_phase";
const DYN_TOPO_DF_NAME: &str = "dyn_topo";
const DEV_TOPO_DF_NAME: &str = "dev_topo";
#[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 {
......
use arrow_schema::{DataType, Field, Schema};
use ds_common::{DEV_TOPO_DF_NAME, DYN_TOPO_DF_NAME, read_dev_topo, read_dyn_topo};
use ds_common::{DEV_TOPO_DF_NAME, DYN_TOPO_DF_NAME};
use mems::model::{get_meas_from_plugin_input, get_wasm_result, PluginInput, PluginOutput};
#[no_mangle]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论