Commit ac235958 by wzc-a

Merge remote-tracking branch 'origin/master'

parents 00f08b23 be47b600
...@@ -6,6 +6,7 @@ use arrow_schema::{DataType, Field, Schema}; ...@@ -6,6 +6,7 @@ use arrow_schema::{DataType, Field, Schema};
use ndarray::Array2; use ndarray::Array2;
use ds_common::dyn_topo::{read_dev_topo, read_dyn_topo}; use ds_common::dyn_topo::{read_dev_topo, read_dyn_topo};
use ds_common::{DEV_CONDUCTOR_DF_NAME, DEV_TOPO_DF_NAME, DS_PF_NLP_CONS, DS_PF_NLP_OBJ, DYN_TOPO_DF_NAME, TN_INPUT_DF_NAME};
use ds_common::tn_input::read_tn_input; use ds_common::tn_input::read_tn_input;
use mems::model::{get_wasm_result, PluginInput, PluginOutput}; use mems::model::{get_wasm_result, PluginInput, PluginOutput};
...@@ -14,11 +15,6 @@ use crate::read::read_dev_ohm; ...@@ -14,11 +15,6 @@ use crate::read::read_dev_ohm;
mod read; mod read;
mod nlp; mod nlp;
const DYN_TOPO_DF_NAME: &str = "dyn_topo";
const DEV_TOPO_DF_NAME: &str = "dev_topo";
const DEV_CONDUCTOR_DF_NAME: &str = "dev_ohm";
const TN_INPUT_DF_NAME: &str = "tn_input";
#[no_mangle] #[no_mangle]
pub unsafe fn run(ptr: i32, len: u32) -> u64 { pub unsafe fn run(ptr: i32, len: u32) -> u64 {
// 从内存中获取字符串 // 从内存中获取字符串
...@@ -93,16 +89,25 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -93,16 +89,25 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
}; };
get_wasm_result(output) get_wasm_result(output)
} else { } else {
let mut csv_str = String::from("cn,tn\n"); let mut obj_csv_str = String::from("cn,tn\n");
// build schema
let obj_schema = Schema::new(vec![
Field::new("cn", DataType::UInt64, false),
Field::new("tn", DataType::UInt64, false),
]);
let mut cons_csv_str = String::from("cn,tn\n");
// build schema // build schema
let schema = Schema::new(vec![ let cons_schema = Schema::new(vec![
Field::new("cn", DataType::UInt64, false), Field::new("cn", DataType::UInt64, false),
Field::new("tn", DataType::UInt64, false), Field::new("tn", DataType::UInt64, false),
]); ]);
let csv_bytes = vec![("".to_string(), csv_str.into_bytes())]; let csv_bytes = vec![
(DS_PF_NLP_OBJ.to_string(), obj_csv_str.into_bytes()),
(DS_PF_NLP_CONS.to_string(), cons_csv_str.into_bytes()),
];
let output = PluginOutput { let output = PluginOutput {
error_msg: None, error_msg: None,
schema: Some(vec![schema]), schema: Some(vec![obj_schema, cons_schema]),
csv_bytes, csv_bytes,
}; };
get_wasm_result(output) get_wasm_result(output)
......
...@@ -2,11 +2,18 @@ pub mod dyn_topo; ...@@ -2,11 +2,18 @@ pub mod dyn_topo;
pub mod static_topo; pub mod static_topo;
pub mod tn_input; pub mod tn_input;
// static topo
pub const STATIC_TOPO_DF_NAME: &str = "static_topo"; pub const STATIC_TOPO_DF_NAME: &str = "static_topo";
pub const TERMINAL_DF_NAME: &str = "terminal_cn_dev"; pub const TERMINAL_DF_NAME: &str = "terminal_cn_dev";
pub const POINT_DF_NAME: &str = "point_terminal_phase"; pub const POINT_DF_NAME: &str = "point_terminal_phase";
// dynamic topo
pub const DYN_TOPO_DF_NAME: &str = "dyn_topo"; pub const DYN_TOPO_DF_NAME: &str = "dyn_topo";
pub const DEV_TOPO_DF_NAME: &str = "dev_topo"; pub const DEV_TOPO_DF_NAME: &str = "dev_topo";
// impedance matrix
pub const DEV_CONDUCTOR_DF_NAME: &str = "dev_ohm"; pub const DEV_CONDUCTOR_DF_NAME: &str = "dev_ohm";
// pf input
pub const SHUNT_MEAS_DF_NAME: &str = "shunt_meas"; pub const SHUNT_MEAS_DF_NAME: &str = "shunt_meas";
pub const TN_INPUT_DF_NAME: &str = "tn_input"; pub const TN_INPUT_DF_NAME: &str = "tn_input";
// pf nlp
pub const DS_PF_NLP_OBJ: &str = "3phase_pf_obj";
pub const DS_PF_NLP_CONS: &str = "3phase_pf_cons";
\ No newline at end of file
...@@ -238,6 +238,20 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 { ...@@ -238,6 +238,20 @@ pub unsafe fn run(ptr: i32, len: u32) -> u64 {
Field::new("unit", DataType::Utf8, false), Field::new("unit", DataType::Utf8, false),
Field::new("value", DataType::Float64, false), Field::new("value", DataType::Float64, false),
]); ]);
// create file
let mut base = PathBuf::from("/");
base.push("pf_input.csv");
let mut file = fs::OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(&base)
.expect("Could not create file");
if let Err(e) = file.write_all(csv_str.as_bytes()) {
log::warn!("!!Failed to write file, err: {:?}", e);
} else {
let _ = file.sync_all();
}
let csv_bytes = vec![(TN_INPUT_DF_NAME.to_string(), csv_str.into_bytes())]; let csv_bytes = vec![(TN_INPUT_DF_NAME.to_string(), csv_str.into_bytes())];
let output = PluginOutput { let output = PluginOutput {
error_msg: None, error_msg: None,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论