<s> """<STR_LIT>""" <EOL> from openaps . uses . use import Use <EOL> from openaps . uses . registry import Registry <EOL> from openaps . glucose . convert import Convert as GlucoseConvert <EOL> import json <EOL> import argparse <EOL> def set_config ( args , device ) : <EOL> return device <EOL> def display_device ( device ) : <EOL> return '<STR_LIT>' <EOL> use = Registry ( ) <EOL> class ConvertInput ( Use ) : <EOL> def get_params ( self , args ) : <EOL> return dict ( input = args . input , to = args . to ) <EOL> def configure_app ( self , app , parser ) : <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT>' , choices = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> parser . add_argument ( '<STR_LIT:input>' , default = '<STR_LIT:->' ) <EOL> def get_program ( self , args ) : <EOL> params = self . get_params ( args ) <EOL> program = json . load ( argparse . FileType ( '<STR_LIT:r>' ) ( params . get ( '<STR_LIT:input>' ) ) ) <EOL> return program <EOL> CONVERTERS = { '<STR_LIT>' : GlucoseConvert . mg_dl_to_mmol_l <EOL> , '<STR_LIT>' : GlucoseConvert . mmol_l_to_mg_dl } <EOL> def set_converter ( self , args ) : <EOL> params = self . get_params ( args ) <EOL> converters = self . CONVERTERS <EOL> self . units = params . get ( '<STR_LIT:to>' ) <EOL> self . to_unit = converters . get ( self . units ) <EOL> def convert ( self , program ) : <EOL> raise NotImplementedError ( ) <EOL> def main ( self , args , app ) : <EOL> self . set_converter ( args ) <EOL> program = self . get_program ( args ) <EOL> results = self . convert ( program ) <EOL> return results <EOL> @ use ( ) <EOL> class bg_targets ( ConvertInput ) : <EOL> """<STR_LIT>""" <EOL> def convert ( self , bg_targets ) : <EOL> assert bg_targets [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if bg_targets [ '<STR_LIT>' ] != self . units : <EOL> for target in bg_targets [ '<STR_LIT>' ] : <EOL> target [ '<STR_LIT>' ] = self . to_unit ( target [ '<STR_LIT>' ] ) <EOL> target [ '<STR_LIT>' ] = self . to_unit ( target [ '<STR_LIT>' ] ) <EOL> bg_targets [ '<STR_LIT>' ] = bg_targets [ '<STR_LIT>' ] <EOL> bg_targets [ '<STR_LIT>' ] = self . units <EOL> return bg_targets <EOL> @ use ( ) <EOL> class insulin_sensitivities ( ConvertInput ) : <EOL> """<STR_LIT>""" <EOL> def convert ( self , insulin_sensitivities ) : <EOL> assert insulin_sensitivities [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if insulin_sensitivities [ '<STR_LIT>' ] != self . units : <EOL> for sens in insulin_sensitivities [ '<STR_LIT>' ] : <EOL> sens [ '<STR_LIT>' ] = self . to_unit ( sens [ '<STR_LIT>' ] ) <EOL> insulin_sensitivities [ '<STR_LIT>' ] = insulin_sensitivities [ '<STR_LIT>' ] <EOL> insulin_sensitivities [ '<STR_LIT>' ] = self . units <EOL> return insulin_sensitivities <EOL> def get_uses ( device , config ) : <EOL> all_uses = use . get_uses ( device , config ) <EOL> all_uses . sort ( key = lambda usage : getattr ( usage , '<STR_LIT>' , usage . __name__ ) ) <EOL> return all_uses </s>
