@@ -9,8 +9,8 @@ use crate::cli::hdf5::Hdf5Schema;
99use crate :: cli:: time:: TimeFormat ;
1010use crate :: cli:: { CommonImportArgs , ImportHdf5Args } ;
1111use crate :: cmd:: import:: hdf5:: detect_hdf5_schema:: {
12- basename, build_time_channel_rows , enum_types_for, hdf5_to_sift_data_type,
13- is_time_dataset_name , parent_path ,
12+ basename, enum_types_for, hdf5_to_sift_data_type, is_time_dataset_name , parent_path ,
13+ weave_time_channel_rows ,
1414} ;
1515use crate :: cmd:: import:: hdf5:: import:: build_hdf5_config;
1616use crate :: cmd:: import:: utils:: group_path_to_channel_name;
@@ -392,37 +392,46 @@ fn make_data_config(
392392 }
393393}
394394
395+ fn make_channel ( name : & str ) -> sift_rs:: common:: r#type:: v1:: ChannelConfig {
396+ sift_rs:: common:: r#type:: v1:: ChannelConfig {
397+ name : name. into ( ) ,
398+ data_type : ChannelDataType :: Double as i32 ,
399+ ..Default :: default ( )
400+ }
401+ }
402+
395403#[ test]
396- fn build_time_channel_rows_one_d_dedups_shared_time_dataset ( ) {
397- let configs = vec ! [
404+ fn weave_one_d_shared_time_appears_once_before_channels ( ) {
405+ let data = vec ! [
398406 make_data_config( "/group_a/time" , "/group_a/voltage" , 0 , None ) ,
399407 make_data_config( "/group_a/time" , "/group_a/current" , 0 , None ) ,
400408 make_data_config( "/group_b/timestamp" , "/group_b/value" , 0 , None ) ,
401409 ] ;
402- let rows = build_time_channel_rows ( & configs) ;
403- assert_eq ! ( rows. len( ) , 2 ) ;
404- assert_eq ! ( rows[ 0 ] . name, "group_a.time" ) ;
405- assert_eq ! ( rows[ 0 ] . description, "[time]" ) ;
406- assert_eq ! ( rows[ 0 ] . data_type, ChannelDataType :: Int64 as i32 ) ;
407- assert_eq ! ( rows[ 1 ] . name, "group_b.timestamp" ) ;
408- assert_eq ! ( rows[ 1 ] . description, "[time]" ) ;
409- }
410-
411- #[ test]
412- fn build_time_channel_rows_two_d_includes_time_index ( ) {
413- let configs = vec ! [
414- make_data_config( "/sensor_0" , "/sensor_0" , 0 , None ) ,
415- make_data_config( "/sensor_1" , "/sensor_1" , 0 , None ) ,
410+ let channels = vec ! [
411+ make_channel( "group_a.voltage" ) ,
412+ make_channel( "group_a.current" ) ,
413+ make_channel( "group_b.value" ) ,
416414 ] ;
417- let rows = build_time_channel_rows ( & configs) ;
418- assert_eq ! ( rows. len( ) , 2 ) ;
419- assert_eq ! ( rows[ 0 ] . name, "sensor_0.0" ) ;
420- assert_eq ! ( rows[ 1 ] . name, "sensor_1.0" ) ;
415+ let woven = weave_time_channel_rows ( & data, & channels) ;
416+ let layout: Vec < ( & str , & str ) > = woven
417+ . iter ( )
418+ . map ( |c| ( c. name . as_str ( ) , c. description . as_str ( ) ) )
419+ . collect ( ) ;
420+ assert_eq ! (
421+ layout,
422+ vec![
423+ ( "group_a.time" , "[time]" ) ,
424+ ( "group_a.voltage" , "" ) ,
425+ ( "group_a.current" , "" ) ,
426+ ( "group_b.timestamp" , "[time]" ) ,
427+ ( "group_b.value" , "" ) ,
428+ ]
429+ ) ;
421430}
422431
423432#[ test]
424- fn build_time_channel_rows_compound_renders_dataset_dot_field ( ) {
425- let configs = vec ! [
433+ fn weave_compound_shows_dataset_dot_field_once_per_compound_dataset ( ) {
434+ let data = vec ! [
426435 make_data_config( "/measurements/run1" , "/measurements/run1" , 0 , Some ( "ts" ) ) ,
427436 make_data_config( "/measurements/run1" , "/measurements/run1" , 0 , Some ( "ts" ) ) ,
428437 make_data_config(
@@ -432,15 +441,27 @@ fn build_time_channel_rows_compound_renders_dataset_dot_field() {
432441 Some ( "timestamp" ) ,
433442 ) ,
434443 ] ;
435- let rows = build_time_channel_rows ( & configs) ;
436- assert_eq ! ( rows. len( ) , 2 ) ;
437- assert_eq ! ( rows[ 0 ] . name, "measurements.run1.ts" ) ;
438- assert_eq ! ( rows[ 0 ] . description, "[time]" ) ;
439- assert_eq ! ( rows[ 1 ] . name, "measurements.run2.timestamp" ) ;
444+ let channels = vec ! [
445+ make_channel( "measurements.run1.voltage" ) ,
446+ make_channel( "measurements.run1.current" ) ,
447+ make_channel( "measurements.run2.voltage" ) ,
448+ ] ;
449+ let woven = weave_time_channel_rows ( & data, & channels) ;
450+ let names: Vec < & str > = woven. iter ( ) . map ( |c| c. name . as_str ( ) ) . collect ( ) ;
451+ assert_eq ! (
452+ names,
453+ vec![
454+ "measurements.run1.ts" ,
455+ "measurements.run1.voltage" ,
456+ "measurements.run1.current" ,
457+ "measurements.run2.timestamp" ,
458+ "measurements.run2.voltage" ,
459+ ]
460+ ) ;
440461}
441462
442463#[ test]
443- fn build_time_channel_rows_empty_when_no_data_configs ( ) {
444- let rows = build_time_channel_rows ( & [ ] ) ;
445- assert ! ( rows . is_empty( ) ) ;
464+ fn weave_empty_returns_empty ( ) {
465+ let woven = weave_time_channel_rows ( & [ ] , & [ ] ) ;
466+ assert ! ( woven . is_empty( ) ) ;
446467}
0 commit comments