// // Copyright 2019 SenX S.A.S. // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, version 3. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see // # Documenting the macro { 'name' 'senx/python/GTStoPickledDict' 'since' '1.2.4' 'deprecated' '' 'deleted' '' 'version' 'all' 'tags' [ 'gts' ] 'desc' <' Convert a GTS into a pickled map of lists. Contrary to macro ListGTStoPickledDict, the list of ticks is ordered as in the GTS and can have duplicates. '> 'sig' [ [ [ 'withSelector:BOOLEAN' 'gts:GTS' ] [ 'result:MAP' ] ] ] 'params' { 'gts' 'The single GTS to convert' 'withSelector' 'Whether to use selector (true) or classname (false) for the keys of the resulting map' 'result' 'A pickled map of lists. The lists are the ticks, the values, and if any, the latitudes, longitudes and elevations. The lists are ordered as in the GTS' } 'related' [ 'ListGTStoPickledDict' '->PICKLE' ] 'examples' [ <' NEWGTS 'randGTS' RENAME 1 10 <% h RAND RAND NaN RAND ADDVALUE %> FOR false @senx/python/GTStoPickledDict '> ] 'conf' [ ] } '.info' STORE <% !$.info INFO SAVE 'context' STORE # Check there is two arguments on the stack <% DEPTH 2 < %> <% 'Macro takes two arguments' MSGFAIL %> IFT # Check that top is a boolean indicating whether to use GTS classname or selector <% 1 PICK TYPEOF 'BOOLEAN' != %> <% 'First argument must be a boolean indicating whether to use GTS selector (true) or classname (false)' MSGFAIL %> IFT # Check that second argument is a GTS <% 2 PICK TYPEOF 'GTS' != %> <% 'Second argument must be a GTS' MSGFAIL %> IFT # Store the arguments 'withSelector' STORE 'gts' STORE # Make name $gts <% $withSelector %> <% TOSELECTOR %> <% NAME %> IFTE 'name' STORE # macro: check not all NaN (for locations and elevations) <% UNIQUE DUP SIZE 1 == SWAP 0 GET ISNaN && %> 'isAllNaN' STORE # Return pickled dict for pandas { # ticks 'timestamps' $gts TICKLIST # locations $gts LOCATIONS 'lon' STORE 'lat' STORE <% $lat @isAllNaN ! %> <% $name '.lat' + $lat %> IFT <% $lon @isAllNaN ! %> <% $name '.lon' + $lon %> IFT # elevations $gts ELEVATIONS 'elev' STORE <% $elev @isAllNaN ! %> <% $name '.elev' + $elev %> IFT # values $name $gts VALUES } ->PICKLE $context RESTORE %>