<s> from __future__ import division <EOL> from builtins import object <EOL> import ast , datetime <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> class Scheduler ( object ) : <EOL> def __init__ ( self , conf_dict_str ) : <EOL> self . conf = self . _parse_conf_dict_str ( conf_dict_str ) <EOL> mandatory_vars = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> for var in mandatory_vars : <EOL> if var not in self . conf : <EOL> raise ImproperlyConfigured ( "<STR_LIT>" + var ) <EOL> def _parse_conf_dict_str ( self , conf_dict_str ) : <EOL> try : <EOL> conf = conf_dict_str . strip ( '<STR_LIT:U+002CU+0020>' ) <EOL> conf = conf . replace ( '<STR_LIT:\r\n>' , '<STR_LIT>' ) <EOL> conf = ast . literal_eval ( "<STR_LIT:{>" + conf + "<STR_LIT:}>" ) <EOL> except SyntaxError : <EOL> raise ImproperlyConfigured ( "<STR_LIT>" + conf_dict_str ) <EOL> return conf <EOL> def calc_next_action_time ( self , action_successful , next_action_factor , num_zero_actions ) : <EOL> if not next_action_factor : <EOL> next_action_factor = self . conf [ '<STR_LIT>' ] <EOL> if action_successful : <EOL> num_zero_actions = <NUM_LIT:0> <EOL> next_action_factor = next_action_factor / self . conf [ '<STR_LIT>' ] <EOL> else : <EOL> num_zero_actions += <NUM_LIT:1> <EOL> if ( num_zero_actions >= self . conf [ '<STR_LIT>' ] ) : <EOL> num_zero_actions = <NUM_LIT:0> <EOL> next_action_factor = next_action_factor * self . conf [ '<STR_LIT>' ] <EOL> time_delta = round ( self . conf [ '<STR_LIT>' ] * next_action_factor , <NUM_LIT:0> ) <EOL> next_action_factor = round ( next_action_factor , <NUM_LIT:3> ) <EOL> time_delta = max ( time_delta , self . conf [ '<STR_LIT>' ] ) <EOL> time_delta = min ( time_delta , self . conf [ '<STR_LIT>' ] ) <EOL> time_delta = datetime . timedelta ( minutes = int ( time_delta ) ) <EOL> result = ( time_delta , next_action_factor , num_zero_actions ) <EOL> return result </s>
