Class: SharedTools::Tools::CompositeAnalysisTool

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/shared_tools/tools/composite_analysis_tool.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ CompositeAnalysisTool

Returns a new instance of CompositeAnalysisTool.



47
48
49
# File 'lib/shared_tools/tools/composite_analysis_tool.rb', line 47

def initialize(logger: nil)
  @logger = logger || RubyLLM.logger
end

Class Method Details

.nameObject



8
# File 'lib/shared_tools/tools/composite_analysis_tool.rb', line 8

def self.name = "composite_analysis"

Instance Method Details

#execute(data_source:, analysis_type: "standard", **options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/shared_tools/tools/composite_analysis_tool.rb', line 51

def execute(data_source:, analysis_type: "standard", **options)
  results = {}
  analysis_start = Time.now

  begin
    @logger.info("CompositeAnalysisTool#execute data_source=#{data_source} analysis_type=#{analysis_type}")

    # Step 1: Fetch data using appropriate method
    @logger.debug("Fetching data from source...")
    if data_source.start_with?('http://', 'https://')
      results[:data] = fetch_web_data(data_source)
      results[:source_type] = 'web'
    else
      results[:data] = read_file_data(data_source)
      results[:source_type] = 'file'
    end

    # Step 2: Analyze data structure
    @logger.debug("Analyzing data structure...")
    results[:structure] = analyze_data_structure(results[:data])

    # Step 3: Generate insights based on analysis type
    if ['standard', 'comprehensive'].include?(analysis_type)
      @logger.debug("Generating insights...")
      results[:insights] = generate_insights(results[:data], results[:structure], options)
    end

    # Step 4: Create visualization suggestions
    if results[:structure][:numeric_columns]&.any?
      @logger.debug("Suggesting visualizations...")
      viz_limit = options[:visualization_limit] || 5
      results[:visualizations] = suggest_visualizations(results[:structure], viz_limit)
    end

    # Step 5: Perform correlation analysis for comprehensive mode
    if analysis_type == 'comprehensive' && results[:structure][:numeric_columns]&.length.to_i > 1
      include_corr = options[:include_correlations].nil? ? true : options[:include_correlations]
      if include_corr
        @logger.debug("Performing correlation analysis...")
        results[:correlations] = perform_correlation_analysis(results[:data], results[:structure])
      end
    end

    analysis_duration = (Time.now - analysis_start).round(3)
    @logger.info("Analysis completed in #{analysis_duration}s")

    {
      success: true,
      analysis: results,
      data_source: data_source,
      analysis_type: analysis_type,
      analyzed_at: Time.now.iso8601,
      duration_seconds: analysis_duration
    }
  rescue => e
    @logger.error("Analysis failed: #{e.message}")
    {
      success: false,
      error: e.message,
      error_type: e.class.name,
      data_source: data_source,
      partial_results: results
    }
  end
end