Skip to content

Commit 0033d17

Browse files
committed
set scale to 0.0 and 1.0 ... if someone wants something else they can use an expression!
1 parent a814302 commit 0033d17

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

countess/plugins/score_scale.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
ChoiceParam,
1010
ColumnChoiceParam,
1111
ColumnOrNoneChoiceParam,
12-
FloatParam,
1312
NumericColumnChoiceParam,
1413
StringParam,
1514
TabularMultiParam,
@@ -24,7 +23,6 @@ class ScaleClassParam(TabularMultiParam):
2423
col = ColumnChoiceParam("Column")
2524
op = ChoiceParam("Operation", "Equals", ["Equals", "Starts With", "Ends With", "Contains", "Matches"])
2625
st = StringParam("Value")
27-
score = FloatParam("Scaled Score")
2826

2927
def filter(self):
3028
col = duckdb_escape_identifier(self.col.value)
@@ -53,6 +51,13 @@ class ScoreScalingPlugin(DuckdbSimplePlugin):
5351
classifiers = ArrayParam("Variant Classifiers", ScaleClassParam("Class"), min_size=2, max_size=2, read_only=True)
5452
group_col = ColumnOrNoneChoiceParam("Group By")
5553

54+
def __init__(self, *a, **k):
55+
super().__init__(*a, **k)
56+
57+
# override classifiers labels
58+
self.classifiers[0].label = 'Scale to 0.0'
59+
self.classifiers[1].label = 'Scale to 1.0'
60+
5661
def execute(
5762
self, ddbc: DuckDBPyConnection, source: DuckDBPyRelation, row_limit: Optional[int] = None
5863
) -> Optional[DuckDBPyRelation]:
@@ -67,11 +72,9 @@ def execute(
6772
group_col_id = "1" # dummy value for one big group.
6873

6974
c0, c1 = self.classifiers
70-
scale_0 = duckdb_escape_literal(c0.score.value)
71-
scale_1 = duckdb_escape_literal(c1.score.value)
7275

7376
sql = f"""
74-
select {all_columns}, T1.score_0, T1.score_1, ({scale_1} - {scale_0}) * ({score_col_id} - T1.score_0) / (T1.score_1 - T1.score_0) + {scale_0} as {scaled_col_id}
77+
select {all_columns}, ({score_col_id} - T1.score_0) / (T1.score_1 - T1.score_0) as {scaled_col_id}
7578
from {source.alias} T0 join (
7679
select {group_col_id} as score_group,
7780
median({score_col_id}) filter ({c0.filter()}) as score_0,

0 commit comments

Comments
 (0)