Class: SharedTools::Tools::DataScienceKit

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

Constant Summary collapse

VALID_ANALYSIS_TYPES =
[
  "statistical_summary",
  "correlation_analysis",
  "time_series",
  "clustering",
  "prediction"
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ DataScienceKit



81
82
83
# File 'lib/shared_tools/tools/data_science_kit.rb', line 81

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

Class Method Details

.nameObject



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

def self.name = "data_science_kit"

Instance Method Details

#execute(analysis_type:, data_source:, **parameters) ⇒ Object



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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/shared_tools/tools/data_science_kit.rb', line 85

def execute(analysis_type:, data_source:, **parameters)
  analysis_start = Time.now

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

    # Validate analysis type
    unless VALID_ANALYSIS_TYPES.include?(analysis_type)
      return {
        success: false,
        error: "Invalid analysis type: #{analysis_type}",
        valid_types: VALID_ANALYSIS_TYPES,
        analysis_type: analysis_type
      }
    end

    # Load and validate data
    data = load_data(data_source)
    validate_data_for_analysis(data, analysis_type, parameters)

    # Perform analysis
    result = case analysis_type
    when "statistical_summary"
      generate_statistical_summary(data, parameters)
    when "correlation_analysis"
      perform_correlation_analysis(data, parameters)
    when "time_series"
      analyze_time_series(data, parameters)
    when "clustering"
      perform_clustering(data, parameters)
    when "prediction"
      generate_predictions(data, parameters)
    end

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

    {
      success: true,
      analysis_type: analysis_type,
      result: result,
      data_summary: summarize_data(data),
      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,
      analysis_type: analysis_type,
      data_source: data_source
    }
  end
end