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}")
@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
@logger.debug("Analyzing data structure...")
results[:structure] = analyze_data_structure(results[:data])
if ['standard', 'comprehensive'].include?(analysis_type)
@logger.debug("Generating insights...")
results[:insights] = generate_insights(results[:data], results[:structure], options)
end
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
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
|