<commit_before>module DTK; class Task
  module ActionResults
    module Mixin
      def add_action_results(result,action)
        unless action_results = CommandAndControl.node_action_results(result,action)
          Log.error_pp(["Unexpected that cannot find data in results:",result])
          return
        end
        # TODO: using task logs for storage; might introduce a new table
        rows = Array.new
        action_results.each_with_index do |action_result,pos|
          label = QualifiedIndex.string_form(self)
          el = {
            :content      => action_result,
            :ref          => "task_log-#{label}--#{pos.to_s}",
            :task_id      => id(),
            :display_name => label,
            :position     => pos
          }
          rows << el
        end
        Model.create_from_rows(child_model_handle(:task_log),rows,{:convert => true})
      end
    end

    def self.get_action_detail(assembly, action_label, opts={})
      ret = ''
      task_mh = assembly.model_handle(:task)
      unless task = Task.get_top_level_most_recent_task(task_mh,[:eq, :assembly_id, assembly.id()])
        raise ErrorUsage.new("No tasks found for '#{assembly.display_name_print_form()}'")
      end
      # TODO: more efficienct would be to be able to do withone call and filter on action_label in get_all_subtasks_with_logs()
      subtasks = task.get_all_subtasks_with_logs()
      task_log_mh = task_mh.createMH(:task_log)
      sp_hash = {
        :cols => [:id, :display_name, :content, :position],
        :filter => [:and, [:eq, :display_name, action_label], [:oneof, :task_id, subtasks.map{|t|t.id()}]]
      }      

      log_entries = Model.get_objs(task_log_mh,sp_hash)
      if log_entries.empty?
        raise ErrorUsage.new("Task action with identifier '#{action_label}' does not exist for this service instance.")
      end
      ordered_log_entries = log_entries.sort{|a,b|a[:position]||0 <=> b[:position]||0}
      ordered_log_entries.each do |l|
        content = l[:content]
        ret << "==============================================================\n"
        ret << "RUN: #{content[:description]} \n"
        ret << "STATUS: #{content[:status]} \n"
        ret << "STDOUT: #{content[:stdout]}\n\n" if content[:stdout] && !content[:stdout].empty?
        ret << "STDERR: #{content[:stderr]} \n" if content[:stderr] && !content[:stderr].empty?
      end
      ret
    end

  end
end; end<commit_msg>cleaned up logic for task-action-detail<commit_after>module DTK; class Task
  module ActionResults
    module Mixin
      def add_action_results(result,action)
        unless action_results = CommandAndControl.node_action_results(result,action)
          Log.error_pp(["Unexpected that cannot find data in results:",result])
          return
        end
        # TODO: using task logs for storage; might introduce a new table
        rows = Array.new
        action_results.each_with_index do |action_result,pos|
          label = QualifiedIndex.string_form(self)
          el = {
            :content      => action_result,
            :ref          => "task_log-#{label}--#{pos.to_s}",
            :task_id      => id(),
            :display_name => label,
            :position     => pos
          }
          rows << el
        end
        Model.create_from_rows(child_model_handle(:task_log),rows,{:convert => true})
      end
    end

    def self.get_action_detail(assembly, action_label, opts={})
      ret = ''
      task_mh = assembly.model_handle(:task)
      unless task = Task.get_top_level_most_recent_task(task_mh,[:eq, :assembly_id, assembly.id()])
        raise ErrorUsage.new("No tasks found for '#{assembly.display_name_print_form()}'")
      end
      # TODO: more efficienct would be to be able to do withone call and filter on action_label in get_all_subtasks_with_logs()
      subtasks = task.get_all_subtasks_with_logs()
      task_log_mh = task_mh.createMH(:task_log)
      sp_hash = {
        :cols => [:id, :display_name, :content, :position],
        :filter => [:and, [:eq, :display_name, action_label], [:oneof, :task_id, subtasks.map{|t|t.id()}]]
      }      

      log_entries = Model.get_objs(task_log_mh,sp_hash)
      if log_entries.empty?
        raise ErrorUsage.new("Task action with identifier '#{action_label}' does not exist for this service instance.")
      end
      ordered_log_entries = log_entries.sort{|a,b|(a[:position]||0) <=> (b[:position]||0)}
      ordered_log_entries.each do |l|
        content = l[:content]
        ret << "==============================================================\n"
        ret << "RUN: #{content[:description]} \n"
        ret << "STATUS: #{content[:status]} \n"
        ret << "STDOUT: #{content[:stdout]}\n\n" if content[:stdout] && !content[:stdout].empty?
        ret << "STDERR: #{content[:stderr]} \n" if content[:stderr] && !content[:stderr].empty?
      end
      ret
    end

  end
end; end
{'fraction_non_alphanumeric': 0.15066828675577157, 'fraction_numerical': 0.0008100445524503848, 'mean_word_length': 2.755893536121673, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1200663', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1476, 'n_words': 341}