<commit_before>##########################################
#
# Module WFMStat
#
##########################################
module WFMStat

  ##########################################
  #
  # Class StatusEngine
  #
  ##########################################
  class StatusEngine

    require 'workflowmgr/workflowdoc'
    require 'workflowmgr/workflowdb'
    require 'workflowmgr/cycledef'
    require "workflowmgr/cycle"
    require 'workflowmgr/dependency'

    require 'workflowmgr/workflowconfig'
    require 'workflowmgr/launchserver'
    require 'workflowmgr/dbproxy'
    require 'workflowmgr/workflowioproxy'

    ##########################################
    #
    # initialize
    #
    ##########################################
    def initialize(options)

      # Get command line options
      @options=options

      # Get configuration file options
      @config=WorkflowMgr::WorkflowYAMLConfig.new

      # Get the base directory of the WFM installation
      @wfmdir=File.dirname(File.dirname(File.expand_path(File.dirname(__FILE__))))

      # Set up an object to serve the workflow database (but do not open the database)
      @dbServer=WorkflowMgr::DBProxy.new(@options.database,@config)

    end  # initialize


    ##########################################
    #
    # wfmstat
    #
    ##########################################
    def wfmstat

      begin

        # Open/Create the database
        @dbServer.dbopen

        # Set up an object to serve file stat info
        @workflowIOServer=WorkflowMgr::WorkflowIOProxy.new(@dbServer,@config)        

        # Open the workflow document
        @workflowdoc = WorkflowMgr::WorkflowXMLDoc.new(@options.workflowdoc,@workflowIOServer)

        # Print a cycle summary report if requested
        if @options.summary
          print_summary
        else
          print_status
        end
    
      ensure
  
        # Make sure we release the workflow lock in the database and shutdown the dbserver
        unless @dbServer.nil?
          @dbServer.unlock_workflow if @locked
          @dbServer.stop! if @config.DatabaseServer
        end
  
        # Make sure to shut down the workflow file stat server
        unless @workflowIOServer.nil?
          @workflowIOServer.stop! if @config.WorkflowIOServer
        end
  
      end  # ensure

    end  # wfmstat


    ##########################################
    #
    # checkTask
    #
    ##########################################
    def checkTask

      begin

        # Open/Create the database
        @dbServer.dbopen

        # Set up an object to serve file stat info
        @workflowIOServer=WorkflowMgr::WorkflowIOProxy.new(@dbServer,@config)        

        # Open the workflow document
        @workflowdoc = WorkflowMgr::WorkflowXMLDoc.new(@options.workflowdoc,@workflowIOServer)

        # Get cycle time and task name options
        cycletime=@options.cycles.first
        taskname=@options.tasks.first

        # Get the cycle
        cycle=@dbServer.get_cycles( {:start=>cycletime, :end=>cycletime } ).first || WorkflowMgr::Cycle.new(cycletime)

        # Get the task
        task=@workflowdoc.tasks[taskname]    
        task=task.localize(cycletime) unless task.nil?

        # Get the job (if there is one)
        jobcycles=[cycletime]
        @workflowdoc.taskdep_cycle_offsets.each do |offset|
          jobcycles << cycletime + offset
        end
        jobs=@dbServer.get_jobs(jobcycles)
        if jobs[taskname].nil?
          job=nil
        else
          job=jobs[taskname][cycletime]
        end

        # Print the task information
        print_taskinfo(task)

        # Query and print task dependency info
        unless task.nil?
          unless task.dependency.nil?
            printf "%2s%s\n", "","dependencies"
            print_deps(task.dependency.query(cycle.cycle,jobs,@workflowIOServer),0)
          end
          unless task.hangdependency.nil?
            printf "%2s%s\n", "","hang dependencies"
            print_deps(task.hangdependency.query(cycle.cycle,jobs,@workflowIOServer),0)
          end
        end<commit_msg>Bug Fix:  Geez!  Couldn't get it right the first time.  Or the second time.  Maybe the third time will work.           Dependencies for jobs that hadn't started yet could not be checked and resulted in a rocotocheck crash.           Need better testing....on the list, but too swamped with fires to do it.<commit_after>##########################################
#
# Module WFMStat
#
##########################################
module WFMStat

  ##########################################
  #
  # Class StatusEngine
  #
  ##########################################
  class StatusEngine

    require 'workflowmgr/workflowdoc'
    require 'workflowmgr/workflowdb'
    require 'workflowmgr/cycledef'
    require "workflowmgr/cycle"
    require 'workflowmgr/dependency'

    require 'workflowmgr/workflowconfig'
    require 'workflowmgr/launchserver'
    require 'workflowmgr/dbproxy'
    require 'workflowmgr/workflowioproxy'

    ##########################################
    #
    # initialize
    #
    ##########################################
    def initialize(options)

      # Get command line options
      @options=options

      # Get configuration file options
      @config=WorkflowMgr::WorkflowYAMLConfig.new

      # Get the base directory of the WFM installation
      @wfmdir=File.dirname(File.dirname(File.expand_path(File.dirname(__FILE__))))

      # Set up an object to serve the workflow database (but do not open the database)
      @dbServer=WorkflowMgr::DBProxy.new(@options.database,@config)

    end  # initialize


    ##########################################
    #
    # wfmstat
    #
    ##########################################
    def wfmstat

      begin

        # Open/Create the database
        @dbServer.dbopen

        # Set up an object to serve file stat info
        @workflowIOServer=WorkflowMgr::WorkflowIOProxy.new(@dbServer,@config)        

        # Open the workflow document
        @workflowdoc = WorkflowMgr::WorkflowXMLDoc.new(@options.workflowdoc,@workflowIOServer)

        # Print a cycle summary report if requested
        if @options.summary
          print_summary
        else
          print_status
        end
    
      ensure
  
        # Make sure we release the workflow lock in the database and shutdown the dbserver
        unless @dbServer.nil?
          @dbServer.unlock_workflow if @locked
          @dbServer.stop! if @config.DatabaseServer
        end
  
        # Make sure to shut down the workflow file stat server
        unless @workflowIOServer.nil?
          @workflowIOServer.stop! if @config.WorkflowIOServer
        end
  
      end  # ensure

    end  # wfmstat


    ##########################################
    #
    # checkTask
    #
    ##########################################
    def checkTask

      begin

        # Open/Create the database
        @dbServer.dbopen

        # Set up an object to serve file stat info
        @workflowIOServer=WorkflowMgr::WorkflowIOProxy.new(@dbServer,@config)        

        # Open the workflow document
        @workflowdoc = WorkflowMgr::WorkflowXMLDoc.new(@options.workflowdoc,@workflowIOServer)

        # Get cycle time and task name options
        cycletime=@options.cycles.first
        taskname=@options.tasks.first

        # Get the cycle
        cycle=@dbServer.get_cycles( {:start=>cycletime, :end=>cycletime } ).first || WorkflowMgr::Cycle.new(cycletime)

        # Get the task
        task=@workflowdoc.tasks[taskname]    
        task=task.localize(cycletime) unless task.nil?

        # Get the job (if there is one)
        jobcycles=[cycletime]
        @workflowdoc.taskdep_cycle_offsets.each do |offset|
          jobcycles << cycletime + offset
        end
        jobs=@dbServer.get_jobs(jobcycles)
        if jobs[taskname].nil?
          job=nil
        else
          job=jobs[taskname][cycletime]
        end

        # Print the task information
        print_taskinfo(task)

        # Query and print task dependency info
        dependencies=nil
        hangdependencies=nil
        unless task.nil?
          unless task.dependency.nil?
            dependencies=task.dependency.query(cycle.cycle,jobs,@workflowIOServer)
            printf "%2s%s\n", "","dependencies"
            print_deps(dependencies,0)
          end
          unless task.hangdependency.nil?
            hangdependencies=task.hangdependency.query(cycle.cycle,jobs,@workflowIOServer)
            printf "%2s%s\n", "","hang dependencies"
            print_deps(hangdependencies,0)
          end
        end
{'fraction_non_alphanumeric': 0.16732146984053617, 'fraction_numerical': 0.0009244280101687081, 'mean_word_length': 2.6047480216576426, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1332521', 'n_tokens_mistral': 2434, 'n_tokens_neox': 2328, 'n_words': 546}