def previous(task):
 params = task.get_params()
 previous_params = {}
 previous_date_params = {}
 for (param_name, param_obj) in params:
  param_value = getattr(task, param_name)
  if isinstance(param_obj, parameter.DateParameter):
   previous_date_params[param_name] = (param_value - datetime.timedelta(days=1))
  elif isinstance(param_obj, parameter.DateSecondParameter):
   previous_date_params[param_name] = (param_value - datetime.timedelta(seconds=1))
  elif isinstance(param_obj, parameter.DateMinuteParameter):
   previous_date_params[param_name] = (param_value - datetime.timedelta(minutes=1))
  elif isinstance(param_obj, parameter.DateHourParameter):
   previous_date_params[param_name] = (param_value - datetime.timedelta(hours=1))
  elif isinstance(param_obj, parameter.DateIntervalParameter):
   previous_date_params[param_name] = param_value.prev()
  else:
   previous_params[param_name] = param_value
 previous_params.update(previous_date_params)
 if (len(previous_date_params) == 0):
  raise NotImplementedError("No task parameter - can't determine previous task")
 elif (len(previous_date_params) > 1):
  raise NotImplementedError("Too many date-related task parameters - can't determine previous task")
 else:
  return task.clone(**previous_params)

def previous ( task ) : params = task . get_params ( ) previous_params = { } previous_date_params = { } for ( param_name , param_obj ) in params : param_value = getattr ( task , param_name ) if isinstance ( param_obj , parameter . DateParameter ) : previous_date_params [ param_name ] = ( param_value - datetime . timedelta ( days = 1 ) ) elif isinstance ( param_obj , parameter . DateSecondParameter ) : previous_date_params [ param_name ] = ( param_value - datetime . timedelta ( seconds = 1 ) ) elif isinstance ( param_obj , parameter . DateMinuteParameter ) : previous_date_params [ param_name ] = ( param_value - datetime . timedelta ( minutes = 1 ) ) elif isinstance ( param_obj , parameter . DateHourParameter ) : previous_date_params [ param_name ] = ( param_value - datetime . timedelta ( hours = 1 ) ) elif isinstance ( param_obj , parameter . DateIntervalParameter ) : previous_date_params [ param_name ] = param_value . prev ( ) else : previous_params [ param_name ] = param_value previous_params . update ( previous_date_params ) if ( len ( previous_date_params ) == 0 ) : raise NotImplementedError ( "No task parameter - can't determine previous task" ) elif ( len ( previous_date_params ) > 1 ) : raise NotImplementedError ( "Too many date-related task parameters - can't determine previous task" ) else : return task . clone ( ** previous_params )
return a previous task of the same family .