-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chart_sdk): add regression distribution chart + utils to get buc…
…ket data fromatted
- Loading branch information
Showing
10 changed files
with
241 additions
and
149 deletions.
There are no files selected for viewing
This file contains 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
4 changes: 2 additions & 2 deletions
4
chart_sdk/radicalbit_platform_chart_sdk/charts/multi_classification/multi_class_chart.py
This file contains 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 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
7 changes: 7 additions & 0 deletions
7
chart_sdk/radicalbit_platform_chart_sdk/charts/regression/__init__.py
This file contains 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,7 @@ | ||
from .regression_chart import RegressionChart | ||
from .regression_chart_data import RegressionChartData | ||
|
||
__all__ = [ | ||
'RegressionChart', | ||
'RegressionChartData' | ||
] |
88 changes: 88 additions & 0 deletions
88
chart_sdk/radicalbit_platform_chart_sdk/charts/regression/regression_chart.py
This file contains 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,88 @@ | ||
from ipecharts import EChartsRawWidget | ||
from .regression_chart_data import RegressionChartData | ||
from ..utils import get_formatted_bucket_data | ||
|
||
|
||
class RegressionChart: | ||
def __init__(self) -> None: | ||
pass | ||
|
||
def distribution_chart(self, data: RegressionChartData) -> EChartsRawWidget: | ||
bucket_data_formatted = get_formatted_bucket_data(bucket_data=data.bucket_data) | ||
|
||
reference_json_data = data.model_dump().get('reference_data') | ||
current_data_json = data.model_dump().get('current_data') | ||
|
||
reference_series_data = { | ||
"title": "reference", | ||
"type": "bar", | ||
"itemStyle": { | ||
"color": "#9B99A1" | ||
}, | ||
"data": reference_json_data | ||
} | ||
|
||
current_series_data = { | ||
"title": "current", | ||
"type": "bar", | ||
"itemStyle": { | ||
"color": "#3695d9" | ||
}, | ||
"data": current_data_json | ||
} | ||
|
||
series = [reference_series_data] if not data.current_data else [ | ||
reference_series_data, current_series_data] | ||
|
||
option = { | ||
"grid": { | ||
"left": 0, | ||
"right": 20, | ||
"bottom": 0, | ||
"top": 10, | ||
"containLabel": True | ||
}, | ||
"xAxis": { | ||
"type": "category", | ||
"axisTick": { | ||
"show": False | ||
}, | ||
"axisLine": { | ||
"show": False | ||
}, | ||
"splitLine": { | ||
"show": False | ||
}, | ||
"axisLabel": { | ||
"fontSize": 12, | ||
"interval": 0, | ||
"color": "#9b99a1", | ||
"rotate": 20 | ||
}, | ||
"data":bucket_data_formatted, | ||
}, | ||
"yAxis": { | ||
"type": "value", | ||
"axisLabel": { | ||
"fontSize": 9, | ||
"color": "#9b99a1" | ||
}, | ||
"splitLine": { | ||
"lineStyle": { | ||
"color": "#9f9f9f54" | ||
} | ||
} | ||
}, | ||
"emphasis": { | ||
"disabled": True | ||
}, | ||
"barCategoryGap": "0", | ||
"barGap": "0", | ||
"itemStyle": { | ||
"borderWidth": 1, | ||
"borderColor": "rgba(201, 25, 25, 1)" | ||
}, | ||
"series": series | ||
} | ||
|
||
return EChartsRawWidget(option=option) |
9 changes: 9 additions & 0 deletions
9
chart_sdk/radicalbit_platform_chart_sdk/charts/regression/regression_chart_data.py
This file contains 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,9 @@ | ||
from typing import Optional, List | ||
from pydantic import BaseModel | ||
|
||
|
||
class RegressionChartData(BaseModel): | ||
title: str | ||
bucket_data: List[str] | ||
reference_data: List[float] | ||
current_data: Optional[List[float]] = None |
This file contains 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,15 @@ | ||
from typing import List | ||
|
||
|
||
|
||
def get_formatted_bucket_data(bucket_data:List[str]): | ||
bucket_data_formatted = [] | ||
bucket_data_len = len(bucket_data) -1 | ||
|
||
for idx, d in enumerate(bucket_data): | ||
close_bracket = ']' if idx == bucket_data_len - 1 else ')' | ||
if idx < bucket_data_len: | ||
element = '['+ d + ',' + bucket_data[ idx + 1 ] + close_bracket | ||
bucket_data_formatted.append(element) | ||
|
||
return bucket_data_formatted |
This file contains 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
Oops, something went wrong.