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}")
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
data = load_data(data_source)
validate_data_for_analysis(data, analysis_type, parameters)
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
|