2
2
import json
3
3
import logging
4
4
import time
5
+ import warnings
5
6
from collections import namedtuple
6
7
from datetime import datetime , timezone
7
8
from pathlib import Path
37
38
logger = logging .getLogger (__name__ )
38
39
39
40
40
- class QueueMode (enum .Enum ):
41
- Batch = "Batch"
42
- Dataset = "Dataset"
43
-
44
-
45
41
class Project (DbObject , Updateable , Deletable ):
46
42
""" A Project is a container that includes a labeling frontend, an ontology,
47
43
datasets and labels.
@@ -89,9 +85,12 @@ class Project(DbObject, Updateable, Deletable):
89
85
benchmarks = Relationship .ToMany ("Benchmark" , False )
90
86
ontology = Relationship .ToOne ("Ontology" , True )
91
87
92
- def update (self , ** kwargs ):
88
+ class QueueMode (enum .Enum ):
89
+ Batch = "Batch"
90
+ Dataset = "Dataset"
93
91
94
- mode : Optional [QueueMode ] = kwargs .pop ("queue_mode" , None )
92
+ def update (self , ** kwargs ):
93
+ mode : Optional [Project .QueueMode ] = kwargs .pop ("queue_mode" , None )
95
94
if mode :
96
95
self ._update_queue_mode (mode )
97
96
@@ -570,7 +569,7 @@ def setup(self, labeling_frontend, labeling_frontend_options) -> None:
570
569
self .update (setup_complete = timestamp )
571
570
572
571
def create_batch (self , name : str , data_rows : List [str ], priority : int = 5 ):
573
- """Create a new batch for a project
572
+ """Create a new batch for a project. Batches is in Beta and subject to change
574
573
575
574
Args:
576
575
name: a name for the batch, must be unique within a project
@@ -580,18 +579,17 @@ def create_batch(self, name: str, data_rows: List[str], priority: int = 5):
580
579
"""
581
580
582
581
# @TODO: make this automatic?
583
- if self .queue_mode () != QueueMode .Batch :
582
+ if self .queue_mode () != Project . QueueMode .Batch :
584
583
raise ValueError ("Project must be in batch mode" )
585
584
586
585
dr_ids = []
587
586
for dr in data_rows :
588
-
589
587
if isinstance (dr , Entity .DataRow ):
590
588
dr_ids .append (dr .uid )
591
589
elif isinstance (dr , str ):
592
590
dr_ids .append (dr )
593
591
else :
594
- raise ValueError ("Must pass " )
592
+ raise ValueError ("You can DataRow ids or DataRow objects " )
595
593
596
594
if len (dr_ids ) > 25_000 :
597
595
raise ValueError (
@@ -618,8 +616,10 @@ def create_batch(self, name: str, data_rows: List[str], priority: int = 5):
618
616
}
619
617
}
620
618
621
- res = self .client .execute (query_str , params ,
622
- experimental = True )["project" ][method ]
619
+ res = self .client .execute (
620
+ query_str , params , experimental = True
621
+ )["project" ][method ]
622
+
623
623
res ['size' ] = len (dr_ids )
624
624
return Entity .Batch (self .client , res )
625
625
@@ -628,9 +628,9 @@ def _update_queue_mode(self, mode: QueueMode) -> QueueMode:
628
628
if self .queue_mode () == mode :
629
629
return mode
630
630
631
- if mode == QueueMode .Batch :
631
+ if mode == Project . QueueMode .Batch :
632
632
status = "ENABLED"
633
- elif mode == QueueMode .Dataset :
633
+ elif mode == Project . QueueMode .Dataset :
634
634
status = "DISABLED"
635
635
else :
636
636
raise ValueError (
@@ -666,9 +666,9 @@ def queue_mode(self) -> QueueMode:
666
666
query_str , {'projectId' : self .uid })["project" ]["tagSetStatus" ]
667
667
668
668
if status == "ENABLED" :
669
- return QueueMode .Batch
669
+ return Project . QueueMode .Batch
670
670
elif status == "DISABLED" :
671
- return QueueMode .Dataset
671
+ return Project . QueueMode .Dataset
672
672
else :
673
673
raise ValueError ("Status not known" )
674
674
@@ -939,7 +939,7 @@ class LabelingParameterOverride(DbObject):
939
939
940
940
LabelerPerformance = namedtuple (
941
941
"LabelerPerformance" , "user count seconds_per_label, total_time_labeling "
942
- "consensus average_benchmark_agreement last_activity_time" )
942
+ "consensus average_benchmark_agreement last_activity_time" )
943
943
LabelerPerformance .__doc__ = (
944
944
"Named tuple containing info about a labeler's performance." )
945
945
0 commit comments