super-dev 2.0.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.
Files changed (61) hide show
  1. super_dev/__init__.py +11 -0
  2. super_dev/analyzer/__init__.py +34 -0
  3. super_dev/analyzer/analyzer.py +440 -0
  4. super_dev/analyzer/detectors.py +511 -0
  5. super_dev/analyzer/models.py +285 -0
  6. super_dev/cli.py +3257 -0
  7. super_dev/config/__init__.py +11 -0
  8. super_dev/config/frontend.py +557 -0
  9. super_dev/config/manager.py +281 -0
  10. super_dev/creators/__init__.py +26 -0
  11. super_dev/creators/creator.py +134 -0
  12. super_dev/creators/document_generator.py +2473 -0
  13. super_dev/creators/frontend_builder.py +371 -0
  14. super_dev/creators/implementation_builder.py +789 -0
  15. super_dev/creators/prompt_generator.py +289 -0
  16. super_dev/creators/requirement_parser.py +354 -0
  17. super_dev/creators/spec_builder.py +195 -0
  18. super_dev/deployers/__init__.py +20 -0
  19. super_dev/deployers/cicd.py +1269 -0
  20. super_dev/deployers/delivery.py +229 -0
  21. super_dev/deployers/migration.py +1032 -0
  22. super_dev/design/__init__.py +74 -0
  23. super_dev/design/aesthetics.py +530 -0
  24. super_dev/design/charts.py +396 -0
  25. super_dev/design/codegen.py +379 -0
  26. super_dev/design/engine.py +528 -0
  27. super_dev/design/generator.py +395 -0
  28. super_dev/design/landing.py +422 -0
  29. super_dev/design/tech_stack.py +524 -0
  30. super_dev/design/tokens.py +269 -0
  31. super_dev/design/ux_guide.py +391 -0
  32. super_dev/exceptions.py +119 -0
  33. super_dev/experts/__init__.py +19 -0
  34. super_dev/experts/service.py +161 -0
  35. super_dev/integrations/__init__.py +7 -0
  36. super_dev/integrations/manager.py +264 -0
  37. super_dev/orchestrator/__init__.py +12 -0
  38. super_dev/orchestrator/engine.py +958 -0
  39. super_dev/orchestrator/experts.py +423 -0
  40. super_dev/orchestrator/knowledge.py +352 -0
  41. super_dev/orchestrator/quality.py +356 -0
  42. super_dev/reviewers/__init__.py +17 -0
  43. super_dev/reviewers/code_review.py +471 -0
  44. super_dev/reviewers/quality_gate.py +964 -0
  45. super_dev/reviewers/redteam.py +881 -0
  46. super_dev/skills/__init__.py +7 -0
  47. super_dev/skills/manager.py +307 -0
  48. super_dev/specs/__init__.py +44 -0
  49. super_dev/specs/generator.py +264 -0
  50. super_dev/specs/manager.py +428 -0
  51. super_dev/specs/models.py +348 -0
  52. super_dev/specs/validator.py +415 -0
  53. super_dev/utils/__init__.py +11 -0
  54. super_dev/utils/logger.py +133 -0
  55. super_dev/web/api.py +1402 -0
  56. super_dev-2.0.0.dist-info/METADATA +252 -0
  57. super_dev-2.0.0.dist-info/RECORD +61 -0
  58. super_dev-2.0.0.dist-info/WHEEL +5 -0
  59. super_dev-2.0.0.dist-info/entry_points.txt +2 -0
  60. super_dev-2.0.0.dist-info/licenses/LICENSE +21 -0
  61. super_dev-2.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,396 @@
1
+ """
2
+ 开发:Excellent(11964948@qq.com)
3
+ 功能:图表类型推荐引擎
4
+ 作用:根据数据类型和可视化需求推荐最佳图表类型
5
+ 创建时间:2025-01-04
6
+ 最后修改:2025-01-04
7
+ """
8
+
9
+ import csv
10
+ from dataclasses import dataclass
11
+ from enum import Enum
12
+ from pathlib import Path
13
+
14
+
15
+ class ChartCategory(str, Enum):
16
+ """图表类别"""
17
+ TIME_SERIES = "Time Series"
18
+ CATEGORICAL = "Categorical"
19
+ PROPORTION = "Proportion"
20
+ CORRELATION = "Correlation"
21
+ DISTRIBUTION = "Distribution"
22
+ HIERARCHICAL = "Hierarchical"
23
+ GEOGRAPHIC = "Geographic"
24
+ FINANCIAL = "Financial"
25
+ FLOW = "Flow"
26
+ MULTIVARIATE = "Multivariate"
27
+ STATISTICAL = "Statistical"
28
+
29
+
30
+ class DataType(str, Enum):
31
+ """数据类型"""
32
+ CONTINUOUS = "Continuous"
33
+ DISCRETE = "Discrete"
34
+ PART_TO_WHOLE = "Part-to-whale"
35
+ TWO_DIMENSIONAL = "Two-dimensional"
36
+ THREE_DIMENSIONAL = "Three-dimensional"
37
+ SEQUENTIAL = "Sequential"
38
+ SPATIAL = "Spatial"
39
+ SINGLE_VALUE = "Single-value"
40
+ DIRECTIONAL = "Directional"
41
+
42
+
43
+ @dataclass
44
+ class ChartType:
45
+ """图表类型"""
46
+ name: str
47
+ category: ChartCategory
48
+ data_type: DataType
49
+ description: str
50
+ best_libraries: list[str] # Chart.js, Recharts, D3.js, etc.
51
+ accessibility_notes: str
52
+ use_cases: list[str]
53
+ limitations: list[str]
54
+ keywords: list[str]
55
+
56
+
57
+ @dataclass
58
+ class ChartRecommendation:
59
+ """图表推荐"""
60
+ chart_type: ChartType
61
+ confidence: float # 0-1
62
+ reasoning: str
63
+ alternatives: list[ChartType]
64
+ library_recommendation: str
65
+ accessibility_considerations: list[str]
66
+
67
+
68
+ class ChartRecommender:
69
+ """图表类型推荐引擎"""
70
+
71
+ # 推荐的图表库
72
+ RECOMMENDED_LIBRARIES = {
73
+ "react": ["Recharts", "Chart.js", "Nivo"],
74
+ "vue": ["Chart.js", "ECharts", "ApexCharts"],
75
+ "svelte": ["Chart.js", "Plotly"],
76
+ "vanilla": ["Chart.js", "Plotly", "D3.js", "ECharts"],
77
+ "angular": ["Chart.js", "Ngx-Chart", "ECharts"],
78
+ "next": ["Recharts", "Chart.js", "Nivo", "Tremor"],
79
+ }
80
+
81
+ def __init__(self, data_dir: Path | None = None):
82
+ """
83
+ 初始化推荐引擎
84
+
85
+ Args:
86
+ data_dir: 数据目录路径
87
+ """
88
+ if data_dir is None:
89
+ data_dir = Path(__file__).parent.parent / "data" / "design"
90
+
91
+ self.data_dir = Path(data_dir)
92
+ self.chart_types: list[ChartType] = []
93
+ self._load_chart_types()
94
+
95
+ def _load_chart_types(self):
96
+ """从 CSV 加载图表类型数据"""
97
+ csv_path = self.data_dir / "chart_types.csv"
98
+
99
+ if not csv_path.exists():
100
+ self.chart_types = self._get_default_chart_types()
101
+ return
102
+
103
+ with open(csv_path, encoding='utf-8') as f:
104
+ reader = csv.DictReader(f)
105
+ for row in reader:
106
+ try:
107
+ chart_type = ChartType(
108
+ name=row["name"],
109
+ category=ChartCategory(row["category"]),
110
+ data_type=DataType(row["data_type"]),
111
+ description=row["description"],
112
+ best_libraries=row["best_libraries"].split(","),
113
+ accessibility_notes=row["accessibility_notes"],
114
+ use_cases=row["use_cases"].split(","),
115
+ limitations=row["limitations"].split(",") if row.get("limitations") else [],
116
+ keywords=row["keywords"].split(",") if row.get("keywords") else []
117
+ )
118
+ self.chart_types.append(chart_type)
119
+ except Exception as e:
120
+ print(f"Warning: Failed to parse chart type: {e}")
121
+
122
+ def _get_default_chart_types(self) -> list[ChartType]:
123
+ """获取默认图表类型(当 CSV 不存在时)"""
124
+ return [
125
+ ChartType(
126
+ name="Line Chart",
127
+ category=ChartCategory.TIME_SERIES,
128
+ data_type=DataType.CONTINUOUS,
129
+ description="Trends over time",
130
+ best_libraries=["Chart.js", "Recharts", "Highcharts"],
131
+ accessibility_notes="Provide data table as fallback",
132
+ use_cases=["Stock prices", "Weather", "Temperature"],
133
+ limitations=["Not for categorical data"],
134
+ keywords=["line", "trend", "time", "series"]
135
+ ),
136
+ ChartType(
137
+ name="Bar Chart",
138
+ category=ChartCategory.CATEGORICAL,
139
+ data_type=DataType.DISCRETE,
140
+ description="Comparing categories",
141
+ best_libraries=["Chart.js", "Recharts", "ECharts"],
142
+ accessibility_notes="Use sufficient color contrast",
143
+ use_cases=["Sales by region", "Survey results", "Population"],
144
+ limitations=["Not for many categories"],
145
+ keywords=["bar", "column", "compare", "categorical"]
146
+ ),
147
+ ChartType(
148
+ name="Pie Chart",
149
+ category=ChartCategory.PROPORTION,
150
+ data_type=DataType.PART_TO_WHOLE,
151
+ description="Showing proportions",
152
+ best_libraries=["Chart.js", "ECharts", "D3.js"],
153
+ accessibility_notes="Provide legend and percentages",
154
+ use_cases=["Market share", "Budget allocation", "Demographics"],
155
+ limitations=["Not for more than 5-7 categories"],
156
+ keywords=["pie", "proportion", "percentage"]
157
+ )
158
+ ]
159
+
160
+ def recommend(
161
+ self,
162
+ data_description: str,
163
+ framework: str = "react",
164
+ max_results: int = 3
165
+ ) -> list[ChartRecommendation]:
166
+ """
167
+ 推荐图表类型
168
+
169
+ Args:
170
+ data_description: 数据描述(如 "time series sales data")
171
+ framework: 前端框架
172
+ max_results: 最大结果数
173
+
174
+ Returns:
175
+ 推荐列表
176
+ """
177
+ desc_lower = data_description.lower()
178
+
179
+ # 分析数据描述
180
+ analysis = self._analyze_description(data_description)
181
+
182
+ # 评分和排序
183
+ scored_charts = []
184
+ for chart_type in self.chart_types:
185
+ score = 0
186
+ reasons = []
187
+
188
+ # 数据类型匹配
189
+ if chart_type.data_type.value.lower() in desc_lower:
190
+ score += 10
191
+ reasons.append(f"Matches {chart_type.data_type.value} data type")
192
+
193
+ # 类别匹配
194
+ if chart_type.category.value.lower() in desc_lower:
195
+ score += 8
196
+ reasons.append(f"Matches {chart_type.category.value} category")
197
+
198
+ # 关键词匹配
199
+ for keyword in chart_type.keywords:
200
+ if keyword.lower() in desc_lower:
201
+ score += 5
202
+ reasons.append(f"Keyword '{keyword}' matched")
203
+
204
+ # 用例匹配
205
+ for use_case in chart_type.use_cases:
206
+ if use_case.lower() in desc_lower:
207
+ score += 7
208
+ reasons.append(f"Use case '{use_case}' matched")
209
+
210
+ # 基于分析的其他匹配
211
+ if analysis.get("has_time_component") and chart_type.category == ChartCategory.TIME_SERIES:
212
+ score += 10
213
+ reasons.append("Time series data detected")
214
+
215
+ if analysis.get("has_comparison") and chart_type.category == ChartCategory.CATEGORICAL:
216
+ score += 8
217
+ reasons.append("Comparison data detected")
218
+
219
+ if analysis.get("has_proportions") and chart_type.category == ChartCategory.PROPORTION:
220
+ score += 8
221
+ reasons.append("Proportion data detected")
222
+
223
+ if score > 0:
224
+ # 计算置信度 (0-1)
225
+ confidence = min(score / 30, 1.0)
226
+
227
+ # 获取替代方案
228
+ alternatives = self._get_alternatives(chart_type, framework)
229
+
230
+ # 推荐库
231
+ lib_rec = self._recommend_library(chart_type, framework)
232
+
233
+ # 无障碍考虑
234
+ a11y_considerations = self._get_accessibility_considerations(chart_type)
235
+
236
+ scored_charts.append(ChartRecommendation(
237
+ chart_type=chart_type,
238
+ confidence=confidence,
239
+ reasoning="; ".join(reasons),
240
+ alternatives=alternatives[:2],
241
+ library_recommendation=lib_rec,
242
+ accessibility_considerations=a11y_considerations
243
+ ))
244
+
245
+ # 按置信度排序
246
+ scored_charts.sort(key=lambda x: x.confidence, reverse=True)
247
+
248
+ return scored_charts[:max_results]
249
+
250
+ def _analyze_description(self, description: str) -> dict[str, bool]:
251
+ """分析数据描述"""
252
+ desc_lower = description.lower()
253
+
254
+ return {
255
+ "has_time_component": any(word in desc_lower for word in [
256
+ "time", "date", "month", "year", "trend", "over time", "series"
257
+ ]),
258
+ "has_comparison": any(word in desc_lower for word in [
259
+ "compare", "vs", "versus", "between", "across", "by region", "by category"
260
+ ]),
261
+ "has_proportions": any(word in desc_lower for word in [
262
+ "percentage", "proportion", "share", "of total", "breakdown", "part of"
263
+ ]),
264
+ "has_correlation": any(word in desc_lower for word in [
265
+ "relationship", "correlation", "vs", "relationship between"
266
+ ]),
267
+ "has_distribution": any(word in desc_lower for word in [
268
+ "distribution", "frequency", "histogram", "spread", "range"
269
+ ]),
270
+ "has_geography": any(word in desc_lower for word in [
271
+ "map", "region", "country", "state", "location", "geographic"
272
+ ])
273
+ }
274
+
275
+ def _get_alternatives(self, chart_type: ChartType, framework: str) -> list[ChartType]:
276
+ """获取替代图表类型"""
277
+ alternatives = []
278
+
279
+ # 基于类别找替代方案
280
+ for other_chart in self.chart_types:
281
+ if other_chart.name == chart_type.name:
282
+ continue
283
+
284
+ # 同类别但不同类型
285
+ if other_chart.category == chart_type.category and other_chart.data_type != chart_type.data_type:
286
+ alternatives.append(other_chart)
287
+
288
+ # 相似的用例
289
+ if any(use_case in chart_type.use_cases for use_case in other_chart.use_cases):
290
+ alternatives.append(other_chart)
291
+
292
+ return alternatives[:5]
293
+
294
+ def _recommend_library(self, chart_type: ChartType, framework: str) -> str:
295
+ """推荐图表库"""
296
+ # 获取框架特定的推荐
297
+ framework_libs = self.RECOMMENDED_LIBRARIES.get(framework.lower(), self.RECOMMENDED_LIBRARIES["vanilla"])
298
+
299
+ # 找到图表类型支持的库
300
+ for lib in framework_libs:
301
+ if lib in chart_type.best_libraries:
302
+ return lib
303
+
304
+ # 如果没有完美匹配,返回第一个推荐的库
305
+ return chart_type.best_libraries[0] if chart_type.best_libraries else "Chart.js"
306
+
307
+ def _get_accessibility_considerations(self, chart_type: ChartType) -> list[str]:
308
+ """获取无障碍考虑事项"""
309
+ considerations = [chart_type.accessibility_notes]
310
+
311
+ # 基于类别的额外考虑
312
+ if chart_type.category == ChartCategory.TIME_SERIES:
313
+ considerations.append("Ensure color differences are distinguishable by all users")
314
+ considerations.append("Provide data table for screen reader users")
315
+
316
+ elif chart_type.category == ChartCategory.CATEGORICAL:
317
+ considerations.append("Use distinct colors or patterns for each category")
318
+ considerations.append("Ensure labels are readable")
319
+
320
+ elif chart_type.category == ChartCategory.PROPORTION:
321
+ considerations.append("Order segments consistently")
322
+ considerations.append("Include percentages in labels")
323
+
324
+ return considerations
325
+
326
+ def search(self, query: str, max_results: int = 5) -> list[ChartType]:
327
+ """
328
+ 搜索图表类型
329
+
330
+ Args:
331
+ query: 搜索查询
332
+ max_results: 最大结果数
333
+
334
+ Returns:
335
+ 匹配的图表类型列表
336
+ """
337
+ query_lower = query.lower()
338
+ scored_charts = []
339
+
340
+ for chart_type in self.chart_types:
341
+ score = 0
342
+
343
+ # 名称匹配
344
+ if query_lower in chart_type.name.lower():
345
+ score += 10
346
+
347
+ # 类别匹配
348
+ if query_lower in chart_type.category.value.lower():
349
+ score += 8
350
+
351
+ # 关键词匹配
352
+ for keyword in chart_type.keywords:
353
+ if query_lower in keyword.lower():
354
+ score += 5
355
+
356
+ # 用例匹配
357
+ for use_case in chart_type.use_cases:
358
+ if query_lower in use_case.lower():
359
+ score += 5
360
+
361
+ if score > 0:
362
+ scored_charts.append((chart_type, score))
363
+
364
+ # 按分数排序
365
+ scored_charts.sort(key=lambda x: x[1], reverse=True)
366
+
367
+ return [chart for chart, _ in scored_charts[:max_results]]
368
+
369
+ def get_chart_type(self, name: str) -> ChartType | None:
370
+ """
371
+ 获取指定名称的图表类型
372
+
373
+ Args:
374
+ name: 图表类型名称
375
+
376
+ Returns:
377
+ 图表类型对象或 None
378
+ """
379
+ for chart_type in self.chart_types:
380
+ if chart_type.name.lower() == name.lower():
381
+ return chart_type
382
+ return None
383
+
384
+ def list_categories(self) -> list[str]:
385
+ """列出所有类别"""
386
+ return list(set(c.category.value for c in self.chart_types))
387
+
388
+ def list_chart_types(self) -> list[str]:
389
+ """列出所有图表类型"""
390
+ return [c.name for c in self.chart_types]
391
+
392
+
393
+ # 便捷函数
394
+ def get_chart_recommender(data_dir: Path | None = None) -> ChartRecommender:
395
+ """获取图表推荐引擎实例"""
396
+ return ChartRecommender(data_dir)