def _generate_states_report(sorted_data):
 states = []
 for (state, data) in sorted_data:
  (module, stateid, name, function) = [x.rstrip('_').lstrip('-') for x in state.split('|')]
  module_function = '.'.join((module, function))
  result = data.get('result', '')
  single = [{'function': module_function}, {'name': name}, {'result': result}, {'duration': data.get('duration', 0.0)}, {'comment': data.get('comment', '')}]
  if (not result):
   style = 'failed'
  else:
   changes = data.get('changes', {})
   if (changes and isinstance(changes, dict)):
    single.append({'changes': _dict_to_name_value(changes)})
    style = 'changed'
   else:
    style = 'unchanged'
  started = data.get('start_time', '')
  if started:
   single.append({'started': started})
  states.append({stateid: single, '__style__': style})
 return states

def _generate_states_report ( sorted_data ) : states = [ ] for ( state , data ) in sorted_data : ( module , stateid , name , function ) = [ x . rstrip ( '_' ) . lstrip ( '-' ) for x in state . split ( '|' ) ] module_function = '.' . join ( ( module , function ) ) result = data . get ( 'result' , '' ) single = [ { 'function' : module_function } , { 'name' : name } , { 'result' : result } , { 'duration' : data . get ( 'duration' , 0.0 ) } , { 'comment' : data . get ( 'comment' , '' ) } ] if ( not result ) : style = 'failed' else : changes = data . get ( 'changes' , { } ) if ( changes and isinstance ( changes , dict ) ) : single . append ( { 'changes' : _dict_to_name_value ( changes ) } ) style = 'changed' else : style = 'unchanged' started = data . get ( 'start_time' , '' ) if started : single . append ( { 'started' : started } ) states . append ( { stateid : single , '__style__' : style } ) return states
generate states report .