Skip to content

Commit

Permalink
added delta to toml output
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian committed Jun 6, 2024
1 parent 461ed5b commit 9b69941
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,14 @@ pub fn get_alternative_segmentation(

pub fn generate_toml_output_file(
location: String,
number_skipped_entries: usize,
best_segmentation: ClonedSegmentation,
alternative_segmentation: Option<Vec<ClonedSegmentation>>,
) -> std::io::Result<()> {
generate_toml(location, best_segmentation, alternative_segmentation)
generate_toml(
location,
number_skipped_entries,
best_segmentation,
alternative_segmentation,
)
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fn main() {
println!("Generating toml file: {}", toml_output_location);
match generate_toml_output_file(
toml_output_location,
number_skipped_entries,
best_segmentation,
alternative_segmentations,
) {
Expand Down
16 changes: 14 additions & 2 deletions src/toml_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct NamedSegmentation(String, TomlSegmentation);

#[derive(Serialize)]
struct TomlSegmentation {
delta: usize,
robustness: f32,
segments: Vec<Segment>,
}
Expand All @@ -37,16 +38,25 @@ struct Segmentations {

pub fn generate_toml(
location: String,
delta: usize,
best_segmentation: ClonedSegmentation,
alternative_segmentation: Option<Vec<ClonedSegmentation>>,
) -> std::io::Result<()> {
let mut segmentations = Vec::<NamedSegmentation>::new();
// Adding best segmentation
segmentations.push(read_segmentation(best_segmentation, "best".to_string()));
segmentations.push(read_segmentation(
best_segmentation,
delta,
"best".to_string(),
));
// Adding the alternative segmentations
if let Some(alternatives) = alternative_segmentation {
alternatives.into_iter().enumerate().for_each(|(i, seg)| {
segmentations.push(read_segmentation(seg, format!("alternative_{}", i + 1)))
segmentations.push(read_segmentation(
seg,
delta,
format!("alternative_{}", i + 1),
))
})
}
let all_segmentations = Segmentations { segmentations };
Expand All @@ -59,6 +69,7 @@ pub fn generate_toml(

fn read_segmentation(
segmentation: (f32, Vec<(crate::behaviortree::TbtNode, usize, usize, f32)>),
delta: usize,
name: String,
) -> NamedSegmentation {
let mut segments = Vec::<Segment>::new();
Expand All @@ -78,6 +89,7 @@ fn read_segmentation(
NamedSegmentation(
name,
TomlSegmentation {
delta,
robustness: segmentation.0,
segments,
},
Expand Down

0 comments on commit 9b69941

Please sign in to comment.