aiecs 1.1.0__py3-none-any.whl → 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aiecs might be problematic. Click here for more details.

Files changed (58) hide show
  1. aiecs/__init__.py +1 -1
  2. aiecs/config/config.py +2 -0
  3. aiecs/domain/__init__.py +95 -0
  4. aiecs/domain/community/__init__.py +159 -0
  5. aiecs/domain/community/agent_adapter.py +516 -0
  6. aiecs/domain/community/analytics.py +465 -0
  7. aiecs/domain/community/collaborative_workflow.py +99 -7
  8. aiecs/domain/community/communication_hub.py +649 -0
  9. aiecs/domain/community/community_builder.py +322 -0
  10. aiecs/domain/community/community_integration.py +365 -12
  11. aiecs/domain/community/community_manager.py +481 -5
  12. aiecs/domain/community/decision_engine.py +459 -13
  13. aiecs/domain/community/exceptions.py +238 -0
  14. aiecs/domain/community/models/__init__.py +36 -0
  15. aiecs/domain/community/resource_manager.py +1 -1
  16. aiecs/domain/community/shared_context_manager.py +621 -0
  17. aiecs/domain/context/context_engine.py +37 -33
  18. aiecs/main.py +2 -2
  19. aiecs/scripts/aid/VERSION_MANAGEMENT.md +97 -0
  20. aiecs/scripts/aid/__init__.py +15 -0
  21. aiecs/scripts/aid/version_manager.py +224 -0
  22. aiecs/scripts/dependance_check/download_nlp_data.py +1 -0
  23. aiecs/tools/__init__.py +23 -23
  24. aiecs/tools/docs/__init__.py +5 -2
  25. aiecs/tools/docs/ai_document_orchestrator.py +39 -26
  26. aiecs/tools/docs/ai_document_writer_orchestrator.py +61 -38
  27. aiecs/tools/docs/content_insertion_tool.py +48 -28
  28. aiecs/tools/docs/document_creator_tool.py +47 -29
  29. aiecs/tools/docs/document_layout_tool.py +35 -20
  30. aiecs/tools/docs/document_parser_tool.py +56 -36
  31. aiecs/tools/docs/document_writer_tool.py +115 -62
  32. aiecs/tools/schema_generator.py +56 -56
  33. aiecs/tools/statistics/__init__.py +82 -0
  34. aiecs/tools/statistics/ai_data_analysis_orchestrator.py +581 -0
  35. aiecs/tools/statistics/ai_insight_generator_tool.py +473 -0
  36. aiecs/tools/statistics/ai_report_orchestrator_tool.py +629 -0
  37. aiecs/tools/statistics/data_loader_tool.py +518 -0
  38. aiecs/tools/statistics/data_profiler_tool.py +599 -0
  39. aiecs/tools/statistics/data_transformer_tool.py +531 -0
  40. aiecs/tools/statistics/data_visualizer_tool.py +460 -0
  41. aiecs/tools/statistics/model_trainer_tool.py +470 -0
  42. aiecs/tools/statistics/statistical_analyzer_tool.py +426 -0
  43. aiecs/tools/task_tools/chart_tool.py +2 -1
  44. aiecs/tools/task_tools/image_tool.py +43 -43
  45. aiecs/tools/task_tools/office_tool.py +39 -36
  46. aiecs/tools/task_tools/pandas_tool.py +37 -33
  47. aiecs/tools/task_tools/report_tool.py +67 -56
  48. aiecs/tools/task_tools/research_tool.py +32 -31
  49. aiecs/tools/task_tools/scraper_tool.py +53 -46
  50. aiecs/tools/task_tools/search_tool.py +1123 -0
  51. aiecs/tools/task_tools/stats_tool.py +20 -15
  52. {aiecs-1.1.0.dist-info → aiecs-1.2.0.dist-info}/METADATA +5 -1
  53. {aiecs-1.1.0.dist-info → aiecs-1.2.0.dist-info}/RECORD +57 -36
  54. {aiecs-1.1.0.dist-info → aiecs-1.2.0.dist-info}/entry_points.txt +1 -0
  55. aiecs/tools/task_tools/search_api.py +0 -7
  56. {aiecs-1.1.0.dist-info → aiecs-1.2.0.dist-info}/WHEEL +0 -0
  57. {aiecs-1.1.0.dist-info → aiecs-1.2.0.dist-info}/licenses/LICENSE +0 -0
  58. {aiecs-1.1.0.dist-info → aiecs-1.2.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,460 @@
1
+ """
2
+ Data Visualizer Tool - Smart data visualization and chart generation
3
+
4
+ This tool provides intelligent visualization capabilities with:
5
+ - Auto chart type recommendation
6
+ - Multiple chart types support
7
+ - Interactive and static visualizations
8
+ - Export in multiple formats
9
+ """
10
+
11
+ import os
12
+ import logging
13
+ import tempfile
14
+ from typing import Dict, Any, List, Optional, Union
15
+ from enum import Enum
16
+
17
+ import pandas as pd
18
+ import numpy as np
19
+ from pydantic import BaseModel, Field, ValidationError, ConfigDict
20
+
21
+ from aiecs.tools.base_tool import BaseTool
22
+ from aiecs.tools import register_tool
23
+
24
+
25
+ class ChartType(str, Enum):
26
+ """Supported chart types"""
27
+ # Basic charts
28
+ LINE = "line"
29
+ BAR = "bar"
30
+ SCATTER = "scatter"
31
+ HISTOGRAM = "histogram"
32
+ BOX = "box"
33
+ VIOLIN = "violin"
34
+
35
+ # Advanced charts
36
+ HEATMAP = "heatmap"
37
+ CORRELATION_MATRIX = "correlation_matrix"
38
+ PAIR_PLOT = "pair_plot"
39
+ PARALLEL_COORDINATES = "parallel_coordinates"
40
+
41
+ # Statistical charts
42
+ DISTRIBUTION = "distribution"
43
+ QQ_PLOT = "qq_plot"
44
+ RESIDUAL_PLOT = "residual_plot"
45
+
46
+ # Time series
47
+ TIME_SERIES = "time_series"
48
+
49
+ # Auto-detect
50
+ AUTO = "auto"
51
+
52
+
53
+ class VisualizationStyle(str, Enum):
54
+ """Visualization styles"""
55
+ STATIC = "static"
56
+ INTERACTIVE = "interactive"
57
+ ANIMATED = "animated"
58
+
59
+
60
+
61
+
62
+ class DataVisualizerError(Exception):
63
+ """Base exception for DataVisualizer errors"""
64
+ pass
65
+
66
+
67
+ class VisualizationError(DataVisualizerError):
68
+ """Raised when visualization fails"""
69
+ pass
70
+
71
+
72
+ @register_tool('data_visualizer')
73
+ class DataVisualizerTool(BaseTool):
74
+ """
75
+ Intelligent data visualization tool that can:
76
+ 1. Auto-recommend appropriate chart types
77
+ 2. Generate interactive visualizations
78
+ 3. Create multi-dimensional plots
79
+ 4. Export in multiple formats
80
+
81
+ Integrates with chart_tool for core visualization operations.
82
+ """
83
+
84
+ # Configuration schema
85
+ class Config(BaseModel):
86
+ """Configuration for the data visualizer tool"""
87
+ model_config = ConfigDict(env_prefix="DATA_VISUALIZER_")
88
+
89
+ default_style: str = Field(
90
+ default="static",
91
+ description="Default visualization style"
92
+ )
93
+ default_output_dir: str = Field(
94
+ default=tempfile.gettempdir(),
95
+ description="Default directory for output files"
96
+ )
97
+ default_dpi: int = Field(
98
+ default=100,
99
+ description="Default DPI for image exports"
100
+ )
101
+ default_figsize: List[int] = Field(
102
+ default=[10, 6],
103
+ description="Default figure size in inches (width, height)"
104
+ )
105
+ enable_auto_recommendation: bool = Field(
106
+ default=True,
107
+ description="Whether to enable automatic chart type recommendation"
108
+ )
109
+
110
+ def __init__(self, config: Optional[Dict[str, Any]] = None):
111
+ """
112
+ Initialize DataVisualizerTool with settings.
113
+
114
+ Args:
115
+ config: Optional configuration overrides
116
+ """
117
+ super().__init__(config)
118
+
119
+ # Parse configuration
120
+ self.config = self.Config(**(config or {}))
121
+
122
+ self.logger = logging.getLogger(__name__)
123
+ if not self.logger.handlers:
124
+ handler = logging.StreamHandler()
125
+ handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
126
+ self.logger.addHandler(handler)
127
+ self.logger.setLevel(logging.INFO)
128
+
129
+ # Initialize external tools
130
+ self._init_external_tools()
131
+
132
+ def _init_external_tools(self):
133
+ """Initialize external task tools"""
134
+ self.external_tools = {}
135
+
136
+ # Initialize ChartTool for visualization operations
137
+ try:
138
+ from aiecs.tools.task_tools.chart_tool import ChartTool
139
+ self.external_tools['chart'] = ChartTool()
140
+ self.logger.info("ChartTool initialized successfully")
141
+ except ImportError:
142
+ self.logger.warning("ChartTool not available")
143
+ self.external_tools['chart'] = None
144
+
145
+ # Schema definitions
146
+ class VisualizeSchema(BaseModel):
147
+ """Schema for visualize operation"""
148
+ data: Union[Dict[str, Any], List[Dict[str, Any]]] = Field(description="Data to visualize")
149
+ chart_type: ChartType = Field(default=ChartType.AUTO, description="Type of chart")
150
+ x: Optional[str] = Field(default=None, description="X-axis column")
151
+ y: Optional[str] = Field(default=None, description="Y-axis column")
152
+ hue: Optional[str] = Field(default=None, description="Hue/color column")
153
+ style: VisualizationStyle = Field(default=VisualizationStyle.STATIC, description="Visualization style")
154
+ title: Optional[str] = Field(default=None, description="Chart title")
155
+ output_path: Optional[str] = Field(default=None, description="Output file path")
156
+
157
+ class AutoVisualizeDatasetSchema(BaseModel):
158
+ """Schema for auto_visualize_dataset operation"""
159
+ data: Union[Dict[str, Any], List[Dict[str, Any]]] = Field(description="Dataset to visualize")
160
+ max_charts: int = Field(default=10, description="Maximum number of charts to generate")
161
+ focus_areas: Optional[List[str]] = Field(default=None, description="Areas to focus on")
162
+
163
+ class RecommendChartTypeSchema(BaseModel):
164
+ """Schema for recommend_chart_type operation"""
165
+ data: Union[Dict[str, Any], List[Dict[str, Any]]] = Field(description="Data for recommendation")
166
+ x: Optional[str] = Field(default=None, description="X column")
167
+ y: Optional[str] = Field(default=None, description="Y column")
168
+
169
+ def visualize(
170
+ self,
171
+ data: Union[Dict[str, Any], List[Dict[str, Any]], pd.DataFrame],
172
+ chart_type: ChartType = ChartType.AUTO,
173
+ x: Optional[str] = None,
174
+ y: Optional[str] = None,
175
+ hue: Optional[str] = None,
176
+ style: VisualizationStyle = VisualizationStyle.STATIC,
177
+ title: Optional[str] = None,
178
+ output_path: Optional[str] = None
179
+ ) -> Dict[str, Any]:
180
+ """
181
+ Create visualization with auto chart type recommendation.
182
+
183
+ Args:
184
+ data: Data to visualize
185
+ chart_type: Type of chart (auto-recommended if AUTO)
186
+ x: X-axis column name
187
+ y: Y-axis column name
188
+ hue: Column for color encoding
189
+ style: Visualization style
190
+ title: Chart title
191
+ output_path: Path to save the chart
192
+
193
+ Returns:
194
+ Dict containing:
195
+ - chart_info: Information about generated chart
196
+ - chart_type: Type of chart created
197
+ - recommendation_reason: Reason for chart type choice
198
+ - output_path: Path to saved chart (if saved)
199
+
200
+ Raises:
201
+ VisualizationError: If visualization fails
202
+ """
203
+ try:
204
+ df = self._to_dataframe(data)
205
+
206
+ # Auto-recommend chart type if needed
207
+ if chart_type == ChartType.AUTO:
208
+ chart_type, reason = self._recommend_chart_type(df, x, y)
209
+ self.logger.info(f"Auto-recommended chart type: {chart_type.value} - {reason}")
210
+ else:
211
+ reason = "User specified"
212
+
213
+ # Generate output path if not provided
214
+ if output_path is None:
215
+ output_path = os.path.join(
216
+ self.config.default_output_dir,
217
+ f"chart_{chart_type.value}_{pd.Timestamp.now().strftime('%Y%m%d_%H%M%S')}.png"
218
+ )
219
+
220
+ # Create visualization using chart_tool if available
221
+ if self.external_tools.get('chart'):
222
+ chart_result = self._create_chart_with_tool(df, chart_type, x, y, hue, title, output_path)
223
+ else:
224
+ chart_result = self._create_chart_matplotlib(df, chart_type, x, y, hue, title, output_path)
225
+
226
+ return {
227
+ 'chart_info': chart_result,
228
+ 'chart_type': chart_type.value,
229
+ 'recommendation_reason': reason,
230
+ 'output_path': output_path,
231
+ 'style': style.value
232
+ }
233
+
234
+ except Exception as e:
235
+ self.logger.error(f"Error creating visualization: {e}")
236
+ raise VisualizationError(f"Visualization failed: {e}")
237
+
238
+ def auto_visualize_dataset(
239
+ self,
240
+ data: Union[Dict[str, Any], List[Dict[str, Any]], pd.DataFrame],
241
+ max_charts: int = 10,
242
+ focus_areas: Optional[List[str]] = None
243
+ ) -> Dict[str, Any]:
244
+ """
245
+ Automatically generate a comprehensive visualization suite.
246
+
247
+ Args:
248
+ data: Dataset to visualize
249
+ max_charts: Maximum number of charts to generate
250
+ focus_areas: Specific areas to focus on (distributions, correlations, outliers)
251
+
252
+ Returns:
253
+ Dict containing information about all generated charts
254
+ """
255
+ try:
256
+ df = self._to_dataframe(data)
257
+
258
+ generated_charts = []
259
+ chart_count = 0
260
+
261
+ # Default focus areas
262
+ if focus_areas is None:
263
+ focus_areas = ['distributions', 'correlations', 'outliers']
264
+
265
+ # Generate distribution charts
266
+ if 'distributions' in focus_areas and chart_count < max_charts:
267
+ numeric_cols = df.select_dtypes(include=[np.number]).columns[:5]
268
+ for col in numeric_cols:
269
+ if chart_count >= max_charts:
270
+ break
271
+ chart_info = self.visualize(df, ChartType.HISTOGRAM, x=col, title=f"Distribution of {col}")
272
+ generated_charts.append(chart_info)
273
+ chart_count += 1
274
+
275
+ # Generate correlation matrix
276
+ if 'correlations' in focus_areas and chart_count < max_charts:
277
+ numeric_cols = df.select_dtypes(include=[np.number]).columns
278
+ if len(numeric_cols) >= 2:
279
+ chart_info = self.visualize(df, ChartType.CORRELATION_MATRIX, title="Correlation Matrix")
280
+ generated_charts.append(chart_info)
281
+ chart_count += 1
282
+
283
+ # Generate box plots for outlier detection
284
+ if 'outliers' in focus_areas and chart_count < max_charts:
285
+ numeric_cols = df.select_dtypes(include=[np.number]).columns[:3]
286
+ for col in numeric_cols:
287
+ if chart_count >= max_charts:
288
+ break
289
+ chart_info = self.visualize(df, ChartType.BOX, y=col, title=f"Box Plot of {col}")
290
+ generated_charts.append(chart_info)
291
+ chart_count += 1
292
+
293
+ return {
294
+ 'generated_charts': generated_charts,
295
+ 'total_charts': len(generated_charts),
296
+ 'focus_areas': focus_areas
297
+ }
298
+
299
+ except Exception as e:
300
+ self.logger.error(f"Error in auto visualization: {e}")
301
+ raise VisualizationError(f"Auto visualization failed: {e}")
302
+
303
+ def recommend_chart_type(
304
+ self,
305
+ data: Union[Dict[str, Any], List[Dict[str, Any]], pd.DataFrame],
306
+ x: Optional[str] = None,
307
+ y: Optional[str] = None
308
+ ) -> Dict[str, Any]:
309
+ """
310
+ Recommend appropriate chart type based on data characteristics.
311
+
312
+ Args:
313
+ data: Data for analysis
314
+ x: X column name
315
+ y: Y column name
316
+
317
+ Returns:
318
+ Dict containing recommended chart type and reasoning
319
+ """
320
+ try:
321
+ df = self._to_dataframe(data)
322
+ chart_type, reason = self._recommend_chart_type(df, x, y)
323
+
324
+ return {
325
+ 'recommended_chart': chart_type.value,
326
+ 'reason': reason,
327
+ 'confidence': 'high'
328
+ }
329
+
330
+ except Exception as e:
331
+ self.logger.error(f"Error recommending chart type: {e}")
332
+ raise VisualizationError(f"Chart recommendation failed: {e}")
333
+
334
+ # Internal helper methods
335
+
336
+ def _to_dataframe(self, data: Union[Dict, List, pd.DataFrame]) -> pd.DataFrame:
337
+ """Convert data to DataFrame"""
338
+ if isinstance(data, pd.DataFrame):
339
+ return data
340
+ elif isinstance(data, list):
341
+ return pd.DataFrame(data)
342
+ elif isinstance(data, dict):
343
+ return pd.DataFrame([data])
344
+ else:
345
+ raise VisualizationError(f"Unsupported data type: {type(data)}")
346
+
347
+ def _recommend_chart_type(self, df: pd.DataFrame, x: Optional[str], y: Optional[str]) -> tuple:
348
+ """Recommend chart type based on data characteristics"""
349
+ # If no columns specified, recommend based on data structure
350
+ if x is None and y is None:
351
+ numeric_cols = df.select_dtypes(include=[np.number]).columns
352
+ if len(numeric_cols) >= 2:
353
+ return ChartType.CORRELATION_MATRIX, "Multiple numeric columns detected"
354
+ elif len(numeric_cols) == 1:
355
+ return ChartType.HISTOGRAM, "Single numeric column detected"
356
+ else:
357
+ return ChartType.BAR, "Categorical data detected"
358
+
359
+ # Determine column types
360
+ x_is_numeric = x and df[x].dtype in ['int64', 'float64'] if x in df.columns else False
361
+ y_is_numeric = y and df[y].dtype in ['int64', 'float64'] if y in df.columns else False
362
+
363
+ # Both numeric: scatter or line
364
+ if x_is_numeric and y_is_numeric:
365
+ # Check if x looks like time series
366
+ if x and 'date' in x.lower() or 'time' in x.lower():
367
+ return ChartType.TIME_SERIES, "Time series data detected"
368
+ return ChartType.SCATTER, "Two numeric variables"
369
+
370
+ # One numeric, one categorical: bar or box
371
+ if (x_is_numeric and not y_is_numeric) or (not x_is_numeric and y_is_numeric):
372
+ return ChartType.BAR, "Mix of numeric and categorical"
373
+
374
+ # Both categorical: bar
375
+ if x and y and not x_is_numeric and not y_is_numeric:
376
+ return ChartType.BAR, "Two categorical variables"
377
+
378
+ # Single numeric: histogram
379
+ if (x_is_numeric and y is None) or (y_is_numeric and x is None):
380
+ return ChartType.HISTOGRAM, "Single numeric variable distribution"
381
+
382
+ # Default
383
+ return ChartType.BAR, "Default chart type"
384
+
385
+ def _create_chart_with_tool(self, df: pd.DataFrame, chart_type: ChartType, x: Optional[str],
386
+ y: Optional[str], hue: Optional[str], title: Optional[str],
387
+ output_path: str) -> Dict[str, Any]:
388
+ """Create chart using chart_tool"""
389
+ chart_tool = self.external_tools['chart']
390
+
391
+ # Convert chart type to chart_tool format
392
+ chart_config = {
393
+ 'data': df.to_dict('records'),
394
+ 'chart_type': chart_type.value,
395
+ 'x': x,
396
+ 'y': y,
397
+ 'title': title or f"{chart_type.value.title()} Chart",
398
+ 'output_path': output_path
399
+ }
400
+
401
+ try:
402
+ result = chart_tool.run('create_chart', **chart_config)
403
+ return result
404
+ except Exception as e:
405
+ self.logger.warning(f"chart_tool failed, falling back to matplotlib: {e}")
406
+ return self._create_chart_matplotlib(df, chart_type, x, y, hue, title, output_path)
407
+
408
+ def _create_chart_matplotlib(self, df: pd.DataFrame, chart_type: ChartType, x: Optional[str],
409
+ y: Optional[str], hue: Optional[str], title: Optional[str],
410
+ output_path: str) -> Dict[str, Any]:
411
+ """Create chart using matplotlib as fallback"""
412
+ import matplotlib.pyplot as plt
413
+
414
+ fig, ax = plt.subplots(figsize=self.config.default_figsize)
415
+
416
+ if chart_type == ChartType.HISTOGRAM and x:
417
+ ax.hist(df[x].dropna(), bins=30, edgecolor='black')
418
+ ax.set_xlabel(x)
419
+ ax.set_ylabel('Frequency')
420
+ elif chart_type == ChartType.SCATTER and x and y:
421
+ ax.scatter(df[x], df[y], alpha=0.6)
422
+ ax.set_xlabel(x)
423
+ ax.set_ylabel(y)
424
+ elif chart_type == ChartType.BAR and x and y:
425
+ df_grouped = df.groupby(x)[y].mean()
426
+ df_grouped.plot(kind='bar', ax=ax)
427
+ ax.set_xlabel(x)
428
+ ax.set_ylabel(y)
429
+ elif chart_type == ChartType.CORRELATION_MATRIX:
430
+ numeric_df = df.select_dtypes(include=[np.number])
431
+ if len(numeric_df.columns) >= 2:
432
+ corr = numeric_df.corr()
433
+ im = ax.imshow(corr, cmap='coolwarm', aspect='auto')
434
+ ax.set_xticks(range(len(corr.columns)))
435
+ ax.set_yticks(range(len(corr.columns)))
436
+ ax.set_xticklabels(corr.columns, rotation=45, ha='right')
437
+ ax.set_yticklabels(corr.columns)
438
+ plt.colorbar(im, ax=ax)
439
+ elif chart_type == ChartType.BOX and y:
440
+ df.boxplot(column=y, ax=ax)
441
+ else:
442
+ # Default: simple line plot
443
+ if x and y:
444
+ ax.plot(df[x], df[y])
445
+ elif x:
446
+ ax.plot(df[x])
447
+
448
+ if title:
449
+ ax.set_title(title)
450
+
451
+ plt.tight_layout()
452
+ plt.savefig(output_path, dpi=self.config.default_dpi, bbox_inches='tight')
453
+ plt.close()
454
+
455
+ return {
456
+ 'status': 'success',
457
+ 'output_path': output_path,
458
+ 'chart_type': chart_type.value
459
+ }
460
+