Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a783c8f

Browse files
JWittmeyerJWittmeyer
andauthoredNov 2, 2022
Reorders labelstudio import (#76)
* Reorders labelstudio import * Adds hex colors and colors for selections * Allows outlier slices to be exported * Websocket integration outlier slice Co-authored-by: JWittmeyer <jens.wittmeyer@onetask.ai>
1 parent ddecc46 commit a783c8f

File tree

4 files changed

+52
-20
lines changed

4 files changed

+52
-20
lines changed
 

‎controller/transfer/export_parser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from typing import Any, Dict, List, Optional, Tuple, Union
55
from submodules.model.business_objects import attribute, general, project, data_slice
6+
from .labelstudio import export_parser as ls_export_parser
67

78
import pandas as pd
89
import numpy as np
@@ -31,7 +32,6 @@ def parse(
3132
if str(col).endswith("__created_by"):
3233
df.drop(col, axis="columns", inplace=True)
3334
elif export_format == enums.RecordExportFormats.LABEL_STUDIO.value:
34-
from .labelstudio import export_parser as ls_export_parser
3535

3636
df = ls_export_parser.parse_dataframe_data(project_id, df)
3737
else:
@@ -61,7 +61,10 @@ def infer_file_name(
6161
row_option = export_options.get("rows")
6262
if row_option.get("type") == enums.RecordExportAmountTypes.SLICE.value:
6363
slice_item = data_slice.get(project_id, row_option.get("id"))
64-
amount_type_addition = slice_item.name
64+
if slice_item.slice_type == enums.SliceTypes.STATIC_OUTLIER.value:
65+
amount_type_addition = "outlier"
66+
else:
67+
amount_type_addition = slice_item.name
6568
else:
6669
amount_type_addition = row_option.get("type")
6770

‎controller/transfer/labelstudio/template_generator.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@
44

55
INDENT_SIZE = " "
66

7+
# tested a bit and text-color-400 seems to be the best case -> can be adjusted if necessary
8+
COLOR_LOOKUP = {
9+
"rose": "#fb7185",
10+
"pink": "#f472b6",
11+
"fuchsia": "#e879f9",
12+
"purple": "#c084fc",
13+
"violet": "#a78bfa",
14+
"indigo": "#818cf8",
15+
"blue": "#60a5fa",
16+
"sky": "#38bdf8",
17+
"cyan": "#22d3ee",
18+
"teal": "#2dd4bf",
19+
"emerald": "#34d399",
20+
"green": "#4ade80",
21+
"lime": "#a3e635",
22+
"yellow": "#facc15",
23+
"amber": "#fbbf24",
24+
"orange": "#fb923c",
25+
"red": "#f87171",
26+
}
27+
728

829
def generate_template(
930
project_id: str, labeling_task_ids: List[str], attribute_ids: List[str]
@@ -48,7 +69,7 @@ def __generate_extraction_task(
4869
f'{INDENT_SIZE}<Labels name="{task_data["name"]}" toName="{task_data["attribute_name"]}">'
4970
)
5071
values += [
51-
f'{INDENT_SIZE*2}<Label value="{label["name"]}" background="{label["color"]}"/>'
72+
f'{INDENT_SIZE*2}<Label value="{label["name"]}" background="{COLOR_LOOKUP[label["color"]]}" kern-color="{label["color"]}"/>'
5273
for label in task_data["labels"]
5374
]
5475
values.append(f"{INDENT_SIZE}</Labels>")
@@ -59,9 +80,9 @@ def __generate_extraction_task(
5980
# <View style="box-shadow: 2px 2px 5px #999; padding: 20px; margin-top: 2em; border-radius: 5px;">
6081
# <Header value="Choose text sentiment"/>
6182
# <Choices name="sentiment" toName="text" choice="single" showInLine="true">
62-
# <Choice value="Positive"/>
63-
# <Choice value="Negative"/>
64-
# <Choice value="Neutral"/>
83+
# <Choice value="Positive" style="background:#blue"/>
84+
# <Choice value="Negative" style="background:#blue"/>
85+
# <Choice value="Neutral" style="background:#blue"/>
6586
# </Choices>
6687
# </View>
6788
def __generate_classification_task(
@@ -84,7 +105,7 @@ def __generate_classification_task(
84105
f'{INDENT_SIZE*2}<Choices name="{task_data["name"]}" toName="{task_data["attribute_name"]}" choice="single" showInLine="true">'
85106
)
86107
values += [
87-
f'{INDENT_SIZE*3}<Choice value="{label["name"]}"/>'
108+
f'{INDENT_SIZE*3}<Choice value="{label["name"]}" style="background:{COLOR_LOOKUP[label["color"]]}50;margin:2px;outline: 2px solid {COLOR_LOOKUP[label["color"]]};outline-offset:-2px;" kern-color="{label["color"]}"/>'
88109
for label in task_data["labels"]
89110
]
90111
values.append(f"{INDENT_SIZE*2}</Choices>")

‎controller/transfer/record_export_manager.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def get_records_by_options_query_data(
8181
record_data_query = __get_record_data_query(project_id, row_options)
8282

8383
# task columns part
84-
classficiation_task_query = ""
84+
classification_task_query = ""
8585
if task_options and sources_options:
86-
classficiation_task_query += __columns_by_table_meta_data_query(
86+
classification_task_query += __columns_by_table_meta_data_query(
8787
project_id, tables_meta_data
8888
)
8989

@@ -96,7 +96,7 @@ def get_records_by_options_query_data(
9696
{select_part}
9797
{extraction_appends["SELECT"]}
9898
{record_data_query}
99-
{classficiation_task_query}
99+
{classification_task_query}
100100
{extraction_appends["FROM"]}
101101
WHERE basic_record.project_id = '{project_id}'
102102
"""
@@ -139,7 +139,7 @@ def __extract_table_meta_classification_data(
139139

140140
for source in sources_options:
141141
full_table_name = ""
142-
addtional_confidence_table_name = ""
142+
additional_confidence_table_name = ""
143143
tablename_dict = {}
144144
additional_confidence_table = {}
145145

@@ -163,8 +163,8 @@ def __extract_table_meta_classification_data(
163163
tablename_dict["table_type"] = "task_data"
164164

165165
if source.get("type") == enums.LabelSource.WEAK_SUPERVISION.value:
166-
addtional_confidence_table_name = f"{full_table_name}_CONFIDENCE"
167-
tables_mapping[addtional_confidence_table_name] = __create_alias()
166+
additional_confidence_table_name = f"{full_table_name}_CONFIDENCE"
167+
tables_mapping[additional_confidence_table_name] = __create_alias()
168168
additional_confidence_table["original_table"] = tables_mapping.get(
169169
full_table_name
170170
)
@@ -176,20 +176,20 @@ def __extract_table_meta_classification_data(
176176
alias = tables_mapping.get(full_table_name)
177177
tables_meta_data[alias] = tablename_dict
178178
if additional_confidence_table:
179-
tables_mapping[addtional_confidence_table_name] = __create_alias()
179+
tables_mapping[additional_confidence_table_name] = __create_alias()
180180
tables_meta_data[
181-
tables_mapping.get(addtional_confidence_table_name)
181+
tables_mapping.get(additional_confidence_table_name)
182182
] = additional_confidence_table
183183
if with_user_id:
184184
additional_created_by_table = {}
185185
additional_created_by_table["table_type"] = "user_data"
186186
additional_created_by_table["original_table"] = tables_mapping.get(
187187
full_table_name
188188
)
189-
addtional_created_by_name = full_table_name + "__created_by"
190-
tables_mapping[addtional_created_by_name] = __create_alias()
189+
additional_created_by_name = full_table_name + "__created_by"
190+
tables_mapping[additional_created_by_name] = __create_alias()
191191
tables_meta_data[
192-
tables_mapping.get(addtional_created_by_name)
192+
tables_mapping.get(additional_created_by_name)
193193
] = additional_created_by_table
194194
return tables_meta_data, tables_mapping
195195

@@ -243,7 +243,10 @@ def __record_data_by_type(project_id: str, row_options: Dict[str, Any]) -> str:
243243
def ___record_data_by_slice(project_id: str, slice_id: str) -> str:
244244
slice = data_slice.get(project_id, slice_id)
245245
slice_type = slice.slice_type
246-
if slice_type == enums.SliceTypes.STATIC_DEFAULT.value:
246+
if (
247+
slice_type == enums.SliceTypes.STATIC_DEFAULT.value
248+
or slice_type == enums.SliceTypes.STATIC_OUTLIER.value
249+
):
247250
return __record_data_by_static_slice_query(project_id, slice_id)
248251
elif slice_type == enums.SliceTypes.DYNAMIC_DEFAULT.value:
249252
if not slice.filter_data:

‎graphql_api/mutation/data_slice.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ def mutate(self, info, project_id, embedding_id):
109109
auth.check_demo_access(info)
110110
auth.check_project_access(info, project_id)
111111
user_id = auth.get_user_id_by_info(info)
112-
manager.create_outlier_slice(project_id, user_id, embedding_id)
112+
data_slice_item = manager.create_outlier_slice(
113+
project_id, user_id, embedding_id
114+
)
115+
notification.send_organization_update(
116+
project_id, f"data_slice_created:{str(data_slice_item.id)}"
117+
)
113118
return CreateOutlierSlice(ok=True)
114119

115120

0 commit comments

Comments
 (0)
Please sign in to comment.