Skip to content

Commit 4b21e47

Browse files
Kiwad, Rajeshwaripavannarayana
andauthored
Task/tsp 1178 replotting and resizing plots (#49)
* Update list values if list is enabled * Format list values * Fix clippy errors * Formatted rust * Truncate list to list count Also fix clippy errors * TSP-1178- resizing of plots when window size changes * Add list length check Refactor * Aperture vs aperature * Decimation of step values implementation * Interpolations for Lin, Log and list * Step LIN and LOG done * Update evaluated list with new count * Sweep LIN and LOG done * Check list values for min/max * Evaluate list values based on start/stop value as limit * Evaluate using limit vs direct evaluation * step and sweep list done * minor changes in plotdata.x and cargo fmt * generateplotdata updates * step list plot change * unused packages removed * including angular build package * package.json update * steps to points change --------- Co-authored-by: pavannarayana <[email protected]>
1 parent 7827f54 commit 4b21e47

File tree

16 files changed

+1176
-212
lines changed

16 files changed

+1176
-212
lines changed

kic-script-gen/src/back_end/client_server.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl AppState {
6666
// let new_wf: Script_Path = Script_Path::default();
6767
// let pat = serde_json::to_string(&new_wf).unwrap();
6868
// println!("{pat}");
69-
println!("Updating work folder from JSON: {}", json_value);
69+
println!("Updating work folder from JSON: {json_value}");
7070
let mut work_folder_guard = self.work_folder.lock().await;
7171
if let Ok(value) = serde_json::from_str::<ScriptPath>(json_value) {
7272
let filename: String = format!("{}.tsp", value.session.clone());
@@ -82,15 +82,15 @@ impl AppState {
8282
return;
8383
}
8484
*work_folder_guard = Some(path_file.to_string_lossy().to_string());
85-
println!("Work folder updated to: {:?}", work_folder_guard);
85+
println!("Work folder updated to: {work_folder_guard:?}");
8686
} else {
8787
println!(
8888
"Work folder does not exist: {:?}",
8989
path_file.to_string_lossy().to_string()
9090
);
9191
}
9292
} else {
93-
println!("Failed to parse work folder from JSON: {}", json_value);
93+
println!("Failed to parse work folder from JSON: {json_value}");
9494
}
9595
}
9696
}
@@ -128,7 +128,7 @@ async fn ws_index(
128128
let mut data_model = app_state.data_model.lock().await;
129129
let response =
130130
data_model.process_data_from_client(ipc_data.json_value);
131-
println!("processed data from client {}", response);
131+
println!("processed data from client {response}");
132132
// Send generate script signal
133133
if let Err(e) = gen_script_tx.send(()) {
134134
eprintln!("Failed to send signal: {e}");
@@ -302,11 +302,11 @@ pub async fn start(mut script_model: ScriptModel) -> anyhow::Result<()> {
302302
} else if trimmed_line.contains("systems") {
303303
let mut data_model = app_state.data_model.lock().await;
304304
let response = data_model.process_system_config(trimmed_line);
305-
println!("{}", response);
305+
println!("{response}");
306306
// Send generate script signal
307307
if !response.contains("error") {
308308
if let Err(e) = app_state.gen_script_tx.send(()) {
309-
eprintln!("Failed to send signal: {}", e);
309+
eprintln!("Failed to send signal: {e}");
310310
}
311311
}
312312
let mut session = app_state.session.lock().await;
@@ -334,7 +334,7 @@ pub async fn start(mut script_model: ScriptModel) -> anyhow::Result<()> {
334334
{
335335
let response = data_model
336336
.process_data_from_saved_config(sweep_model_str);
337-
println!("processed data from saved config {}", response);
337+
println!("processed data from saved config {response}");
338338
let mut session = app_state.session.lock().await;
339339
if let Some(session) = session.as_mut() {
340340
session.text(response).await.unwrap();
@@ -347,12 +347,12 @@ pub async fn start(mut script_model: ScriptModel) -> anyhow::Result<()> {
347347
}
348348
}
349349
Err(e) => {
350-
eprintln!("Failed to parse json_value as JSON: {}", e);
350+
eprintln!("Failed to parse json_value as JSON: {e}");
351351
}
352352
}
353353
}
354354
Err(e) => {
355-
eprintln!("Failed to deserialize IpcData from stdin: {}", e);
355+
eprintln!("Failed to deserialize IpcData from stdin: {e}");
356356
}
357357
}
358358
}

kic-script-gen/src/back_end/data_model.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ impl DataModel {
9393
pub fn process_data_from_saved_config(&mut self, data: String) -> String {
9494
match serde_json::from_str::<SweepModel>(&data) {
9595
Ok(mut sweep_model) => {
96-
println!(
97-
"Successfully deserialized saved JSON in server: {:?}",
98-
sweep_model
99-
);
96+
println!("Successfully deserialized saved JSON in server: {sweep_model:?}");
10097
sweep_model.sweep_config.evaluate();
10198

10299
self.sweep_model = sweep_model.clone();
@@ -107,7 +104,7 @@ impl DataModel {
107104
)
108105
}
109106
Err(e) => {
110-
println!("Failed to deserialize saved JSON: {}", e);
107+
println!("Failed to deserialize saved JSON: {e}");
111108
self.serialize_empty_response("error", "Failed to process saved sweep model")
112109
}
113110
}

script-gen-manager/src/model/chan_data/start_stop_channel.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::num;
2+
13
use serde::{Deserialize, Serialize};
24

35
use super::default_channel::CommonChanAttributes;
@@ -45,7 +47,7 @@ impl StartStopChannel {
4547
self.set_list(steps_or_points);
4648
}
4749

48-
pub fn set_list(&mut self, steps_or_points: i32) {
50+
fn set_list(&mut self, steps_or_points: i32) {
4951
let num_points = steps_or_points;
5052
self.list = Vec::with_capacity(num_points.try_into().unwrap());
5153

@@ -59,12 +61,55 @@ impl StartStopChannel {
5961
}
6062
}
6163

62-
pub fn evaluate(&mut self) {
64+
pub fn evaluate(&mut self, list_size: usize) {
6365
self.common_chan_attributes.evaluate();
6466
self.determine_start_value();
6567
self.determine_stop_value();
6668
self.common_chan_attributes
6769
.update_region_constraints(self.start.value, self.stop.value);
70+
71+
//List evaluation
72+
73+
self.update_list(list_size);
74+
}
75+
76+
fn update_list(&mut self, list_size: usize) {
77+
//get the right unit for the list value
78+
let unit = if self.common_chan_attributes.source_range.unit == BaseMetadata::UNIT_AMPERES {
79+
Some(BaseMetadata::UNIT_AMPERES.to_string())
80+
} else {
81+
Some(BaseMetadata::UNIT_VOLTS.to_string())
82+
};
83+
84+
//The case where the list size is more than the requested size
85+
if self.list.len() > list_size {
86+
let pf = ParameterFloat::new(&format!("list_{}", 0), 0.0, unit.clone()); //Unused in this case
87+
self.list.resize(list_size, pf); //Simply truncate the list
88+
}
89+
if self.list.len() < list_size {
90+
//The case where the list size is less than the requested size
91+
let num_points = list_size - self.list.len();
92+
for i in 0..num_points {
93+
let pf = ParameterFloat::new(
94+
&format!("list_{}", self.list.len() + i),
95+
0.0,
96+
unit.clone(),
97+
);
98+
self.list.push(pf); //Fill the list with default values
99+
}
100+
}
101+
102+
for (_, pf) in self.list.iter_mut().enumerate() {
103+
if let Some(start_unit) = &pf.unit {
104+
if start_unit == &self.common_chan_attributes.source_range.unit {
105+
pf.value = self.common_chan_attributes.source_range.limit(pf.value);
106+
} else {
107+
//default to 0.0 if source function has been changed
108+
pf.value = self.common_chan_attributes.source_range.limit(0.0);
109+
pf.unit = Some(self.common_chan_attributes.source_range.unit.clone());
110+
}
111+
}
112+
}
68113
}
69114

70115
fn determine_start_value(&mut self) {
@@ -81,7 +126,7 @@ impl StartStopChannel {
81126
}
82127
} else {
83128
//TODO: handle error condition
84-
println!("bias.unit is None");
129+
println!("start.unit is None");
85130
}
86131

87132
if self.style.value == BaseMetadata::STYLE_LOG.to_string() {

script-gen-manager/src/model/sweep_data/sweep_config.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ pub struct SweepConfig {
3535
// base_metadata: BaseMetadata,
3636
}
3737

38+
impl Default for SweepConfig {
39+
fn default() -> Self {
40+
Self::new()
41+
}
42+
}
43+
3844
impl SweepConfig {
3945
pub fn new() -> Self {
4046
SweepConfig {
@@ -366,10 +372,14 @@ impl SweepConfig {
366372
bias_channel.evaluate();
367373
}
368374
for step_channel in &mut self.step_channels {
369-
step_channel.start_stop_channel.evaluate();
375+
step_channel
376+
.start_stop_channel
377+
.evaluate(self.step_global_parameters.step_points.value as usize);
370378
}
371379
for sweep_channel in &mut self.sweep_channels {
372-
sweep_channel.start_stop_channel.evaluate();
380+
sweep_channel
381+
.start_stop_channel
382+
.evaluate(self.sweep_global_parameters.sweep_points.value as usize);
373383
}
374384
}
375385

@@ -422,7 +432,6 @@ impl SweepConfig {
422432
self.device_list.iter_mut().for_each(|device| {
423433
if device._id == chan_id {
424434
device.in_use = false;
425-
return;
426435
}
427436
});
428437
}

script-gen-manager/src/script_component/sweep.rs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::{any::Any, collections::HashMap};
22

33
use crate::{
44
instr_metadata::base_metadata::BaseMetadata,
5-
model::{chan_data::channel_range::ChannelRange, sweep_data::sweep_config::SweepConfig},
5+
model::{
6+
chan_data::channel_range::ChannelRange,
7+
sweep_data::{parameters::ParameterFloat, sweep_config::SweepConfig},
8+
},
69
};
710

811
use super::function::FunctionModel;
@@ -79,7 +82,7 @@ impl SweepModel {
7982
fn define_bias_channels(&mut self, sweep_config: &SweepConfig) {
8083
let mut index = 1;
8184
for bias_channel in sweep_config.bias_channels.iter() {
82-
let instr_name = format!("bias{}", index);
85+
let instr_name = format!("bias{index}");
8386
self.attributes.bias_names.push(instr_name.clone());
8487

8588
self.val_replacement_map.insert(
@@ -177,7 +180,7 @@ impl SweepModel {
177180
fn define_step_channels(&mut self, sweep_config: &SweepConfig) {
178181
let mut index = 1;
179182
for step_channel in sweep_config.step_channels.iter() {
180-
let instr_name = format!("step{}", index);
183+
let instr_name = format!("step{index}");
181184
self.attributes.step_names.push(instr_name.clone());
182185

183186
self.val_replacement_map.insert(
@@ -300,10 +303,17 @@ impl SweepModel {
300303
self.format(step_channel.start_stop_channel.stop.value),
301304
);
302305

306+
self.process_list(
307+
sweep_config.step_global_parameters.list_step,
308+
&step_channel.start_stop_channel.list,
309+
instr_name,
310+
sweep_config.step_global_parameters.step_points.value as usize,
311+
);
312+
303313
index += 1;
304314
}
305315

306-
let step_count = if self.attributes.step_names.len() > 0 {
316+
let step_count = if !self.attributes.step_names.is_empty() {
307317
sweep_config
308318
.step_global_parameters
309319
.step_points
@@ -313,7 +323,7 @@ impl SweepModel {
313323
String::from("1")
314324
};
315325

316-
let step_to_sweep_delay = if self.attributes.step_names.len() > 0 {
326+
let step_to_sweep_delay = if !self.attributes.step_names.is_empty() {
317327
self.format(
318328
sweep_config
319329
.step_global_parameters
@@ -337,10 +347,36 @@ impl SweepModel {
337347
}
338348
}
339349

350+
fn process_list(
351+
&mut self,
352+
is_list: bool,
353+
list: &Vec<ParameterFloat>,
354+
instr_name: String,
355+
len: usize, // Default length for list values
356+
) {
357+
//Default value for list is nil
358+
let mut list_values = "nil".to_string();
359+
360+
if is_list {
361+
let mut new_list = list
362+
.iter()
363+
.map(|item| item.value.to_string())
364+
.collect::<Vec<_>>();
365+
if !new_list.is_empty() && new_list.len() > len {
366+
new_list.truncate(len);
367+
}
368+
369+
//Fill in list values
370+
list_values = format!("{{ {} }}", new_list.join(", "));
371+
}
372+
self.val_replacement_map
373+
.insert(instr_name.clone() + ":LIST", list_values);
374+
}
375+
340376
fn define_sweep_channels(&mut self, sweep_config: &SweepConfig) {
341377
let mut index = 1;
342378
for sweep_channel in sweep_config.sweep_channels.iter() {
343-
let instr_name = format!("sweep{}", index);
379+
let instr_name = format!("sweep{index}");
344380
self.attributes.sweep_names.push(instr_name.clone());
345381

346382
self.val_replacement_map.insert(
@@ -463,6 +499,13 @@ impl SweepModel {
463499
self.format(sweep_channel.start_stop_channel.stop.value),
464500
);
465501

502+
self.process_list(
503+
sweep_config.sweep_global_parameters.list_sweep,
504+
&sweep_channel.start_stop_channel.list,
505+
instr_name,
506+
sweep_config.sweep_global_parameters.sweep_points.value as usize,
507+
);
508+
466509
index += 1;
467510
}
468511

0 commit comments

Comments
 (0)