def get_program(self, params): """Parses params into history parser constructor arguments :param params: :type params: dict :return: :rtype: tuple(list, dict) """ pump_history_file_time = datetime.fromtimestamp(os.path.getmtime(params['pump-history'])) assert datetime.now() - pump_history_file_time < timedelta(minutes=5), 'History data is more than 5 minutes old' recent_glucose = _json_file(params['glucose']) if len(recent_glucose) > 0: glucose_file_time = datetime.fromtimestamp(os.path.getmtime(params['glucose'])) last_glucose_datetime = parse(glucose_data_tuple(recent_glucose[0])[0]) if last_glucose_datetime.utcoffset() is not None: last_glucose_datetime = make_naive(last_glucose_datetime) assert abs(glucose_file_time - last_glucose_datetime) < timedelta(minutes=15), \ 'Glucose data is more than 15 minutes old' args = ( _json_file(params['pump-history']), recent_glucose, int(params.get('insulin_action_curve', None) or _opt_json_file(params.get('settings', ''))['insulin_action_curve']), Schedule(_json_file(params['insulin_sensitivities'])['sensitivities']), Schedule(_json_file(params['carb_ratios'])['schedule']), ) return args, dict(basal_dosing_end=_opt_date(_opt_json_file(params.get('basal_dosing_end'))))
def get_program(self, params): """Parses params into history parser constructor arguments :param params: :type params: dict :return: :rtype: tuple(list, dict) """ pump_history_file_time = datetime.fromtimestamp(os.path.getmtime(params["pump-history"])) assert datetime.now() - pump_history_file_time < timedelta(minutes=5), "History data is more than 5 minutes old" recent_glucose = _json_file(params["glucose"]) if len(recent_glucose) > 0: glucose_file_time = datetime.fromtimestamp(os.path.getmtime(params["glucose"])) last_glucose_datetime, _ = glucose_data_tuple(recent_glucose[0]) assert abs(glucose_file_time - last_glucose_datetime) < timedelta( minutes=15 ), "Glucose data is more than 15 minutes old" args = ( _json_file(params["pump-history"]), recent_glucose, params.get("insulin_action_curve", None) or _opt_json_file(params.get("settings", ""))["insulin_action_curve"], Schedule(_json_file(params["insulin_sensitivities"])["sensitivities"]), Schedule(_json_file(params["carb_ratios"])["schedule"]), ) return args, dict(basal_dosing_end=_opt_date(_opt_json_file(params.get("basal_dosing_end"))))
def get_program(params): """Parses params into history parser constructor arguments :param params: :type params: dict :return: :rtype: tuple(list, dict) """ effect_files = params['effects'] if isinstance(effect_files, str): effect_files = ast.literal_eval(effect_files) recent_glucose = _json_file(params['glucose']) if len(recent_glucose) > 0: glucose_file_time = datetime.fromtimestamp( os.path.getmtime(params['glucose'])) last_glucose_datetime = parse( glucose_data_tuple(recent_glucose[0])[0]) if last_glucose_datetime.utcoffset() is not None: last_glucose_datetime = make_naive(last_glucose_datetime) assert abs(glucose_file_time - last_glucose_datetime) < timedelta(minutes=15), \ 'Glucose data is more than 15 minutes old' effects = [] for f in effect_files: file_time = datetime.fromtimestamp(os.path.getmtime(f)) assert datetime.now() - file_time < timedelta( minutes=5), '{} is more than 5 minutes old'.format(f) effects.append(_json_file(f)) args = (effects, recent_glucose) kwargs = {} momentum_file_name = params.get('momentum') if momentum_file_name: kwargs['momentum'] = _opt_json_file(params.get('momentum')) file_time = datetime.fromtimestamp( os.path.getmtime(params['momentum'])) assert datetime.now() - file_time < timedelta( minutes=5), '{} is more than 5 minutes old'.format() return args, kwargs
def get_program(params): """Parses params into history parser constructor arguments :param params: :type params: dict :return: :rtype: tuple(list, dict) """ effect_files = params['effects'] if isinstance(effect_files, str): effect_files = ast.literal_eval(effect_files) recent_glucose = _json_file(params['glucose']) if len(recent_glucose) > 0: glucose_file_time = datetime.fromtimestamp(os.path.getmtime(params['glucose'])) last_glucose_datetime = parse(glucose_data_tuple(recent_glucose[0])[0]) if last_glucose_datetime.utcoffset() is not None: last_glucose_datetime = make_naive(last_glucose_datetime) assert abs(glucose_file_time - last_glucose_datetime) < timedelta(minutes=15), \ 'Glucose data is more than 15 minutes old' effects = [] for f in effect_files: file_time = datetime.fromtimestamp(os.path.getmtime(f)) assert datetime.now() - file_time < timedelta(minutes=5), '{} is more than 5 minutes old'.format(f) effects.append(_json_file(f)) args = (effects, recent_glucose) kwargs = {} momentum_file_name = params.get('momentum') if momentum_file_name: kwargs['momentum'] = _opt_json_file(params.get('momentum')) file_time = datetime.fromtimestamp(os.path.getmtime(params['momentum'])) assert datetime.now() - file_time < timedelta(minutes=5), '{} is more than 5 minutes old'.format() return args, kwargs
def get_program(self, params): """Parses params into history parser constructor arguments :param params: :type params: dict :return: :rtype: tuple(list, dict) """ pump_history_file_time = datetime.fromtimestamp( os.path.getmtime(params['pump-history'])) assert datetime.now() - pump_history_file_time < timedelta( minutes=5), 'History data is more than 5 minutes old' recent_glucose = _json_file(params['glucose']) if len(recent_glucose) > 0: glucose_file_time = datetime.fromtimestamp( os.path.getmtime(params['glucose'])) last_glucose_datetime = parse( glucose_data_tuple(recent_glucose[0])[0]) if last_glucose_datetime.utcoffset() is not None: last_glucose_datetime = make_naive(last_glucose_datetime) assert abs(glucose_file_time - last_glucose_datetime) < timedelta(minutes=15), \ 'Glucose data is more than 15 minutes old' args = ( _json_file(params['pump-history']), recent_glucose, int( params.get('insulin_action_curve', None) or _opt_json_file( params.get('settings', ''))['insulin_action_curve']), Schedule( _json_file(params['insulin_sensitivities'])['sensitivities']), Schedule(_json_file(params['carb_ratios'])['schedule']), ) return args, dict(basal_dosing_end=_opt_date( _opt_json_file(params.get('basal_dosing_end'))))