%% Author: peo %% Created: 06.09.2006 %% Description: MOLAP cube data loading routines. -module( cube_load ). -export( [new/0, add/3, fill/2, prefilled/0, finalize/1] ). new() -> []. add( _Cube, [], Value ) -> Value; add( Cube, [Key | Keys], Value ) -> add_key( Cube, Key, Keys, Value ). add_key( [], Key, Keys, Value ) -> [ { Key, add( [], Keys, Value ) } | []]; add_key( [ Head | Tail ], Key, Keys, Value ) -> case Head of { Key, Data } -> [ { Key, add( Data, Keys, Value ) } | Tail ]; Other -> [ Other | add_key( Tail, Key, Keys, Value ) ] end. fill( Cube, [] ) -> Cube; fill( Cube, [ {Keys, Value} | Data ] ) -> fill( add( Cube, Keys, Value ), Data ). prefilled() -> fill( new(), [ {[2003, ch, desktop], 100.0} , {[2003, ch, notebook], 200.0} , {[2003, fr, desktop], 8000.0} , {[2004, fr, notebook], 9000.0} , {[2004, fr, desktop], 4000.0} ] ). finalize( Cube ) -> list_to_tuple( finalize_keys( lists:keysort( 1, Cube ))). finalize_keys( [] ) -> []; finalize_keys( [ {Key, SubCube} | Keys ] ) -> [ finalize_key( Key, SubCube ) | finalize_keys( Keys ) ]. finalize_key( Key, SubCube ) when is_list(SubCube) -> { Key, finalize( SubCube ) }; finalize_key( Key, Value ) -> { Key, Value }.