-
Notifications
You must be signed in to change notification settings - Fork 0
Add visualization recommender, UI controls and chart-job fallback #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class VizRecommendation: | ||
| intent: str | ||
| chart_types: list[str] | ||
| reason: str | ||
|
|
||
|
|
||
| _INTENT_RULES: list[tuple[tuple[str, ...], VizRecommendation]] = [ | ||
| ( | ||
| ("추이", "트렌드", "변화", "시계열", "trend", "over time"), | ||
| VizRecommendation( | ||
| intent="trend", | ||
| chart_types=["line", "scatter"], | ||
| reason="시간/순서 기반 변화 파악에는 선형 추세와 분포 확인이 유리합니다.", | ||
| ), | ||
| ), | ||
| ( | ||
| ("비교", "랭킹", "상위", "하위", "compare", "ranking"), | ||
| VizRecommendation( | ||
| intent="comparison", | ||
| chart_types=["bar", "boxplot"], | ||
| reason="그룹 간 크기 비교에는 막대, 분산 비교에는 박스플롯이 적합합니다.", | ||
| ), | ||
| ), | ||
| ( | ||
| ("관계", "상관", "영향", "relationship", "correlation"), | ||
| VizRecommendation( | ||
| intent="relationship", | ||
| chart_types=["scatter", "histogram"], | ||
| reason="변수 간 관계는 산점도로, 단일 변수 분포는 히스토그램으로 확인합니다.", | ||
| ), | ||
| ), | ||
| ( | ||
| ("비율", "구성", "점유", "composition", "ratio"), | ||
| VizRecommendation( | ||
| intent="composition", | ||
| chart_types=["bar"], | ||
| reason="구성 비교는 범주형 막대 차트로 읽기 쉽고 왜곡이 적습니다.", | ||
| ), | ||
| ), | ||
| ( | ||
| ("결측", "누락", "품질", "이상치", "missing", "quality", "outlier"), | ||
| VizRecommendation( | ||
| intent="quality", | ||
| chart_types=["missing", "boxplot"], | ||
| reason="데이터 품질 확인에는 결측 막대와 이상치 확인용 박스플롯이 효과적입니다.", | ||
| ), | ||
| ), | ||
| ] | ||
|
|
||
| _DEFAULT = VizRecommendation( | ||
| intent="overview", | ||
| chart_types=["histogram", "bar", "scatter"], | ||
| reason="일반 탐색 질문으로 판단되어 분포/범주/관계를 함께 확인하는 구성을 추천합니다.", | ||
| ) | ||
|
|
||
|
|
||
| def recommend_chart_types(question: str) -> dict[str, object]: | ||
| text = (question or "").strip().lower() | ||
| if not text: | ||
| rec = _DEFAULT | ||
| else: | ||
| rec = next((rule for keywords, rule in _INTENT_RULES if any(k in text for k in keywords)), _DEFAULT) | ||
|
|
||
| return { | ||
| "intent": rec.intent, | ||
| "recommended_chart_types": rec.chart_types, | ||
| "reason": rec.reason, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reuses
appState.vizRecommendationif it exists, so after a user fetches recommendations once and then edits the question,startChartsJob()still sends the oldselected_chart_types. Because/api/charts/jobsonly auto-recommends whenselected_chart_typesis empty, the stale list overrides the new question and can generate charts for the wrong intent.Useful? React with 👍 / 👎.