22import json
33import logging
44import time
5+ import warnings
56from collections import namedtuple
67from datetime import datetime , timezone
78from pathlib import Path
3738logger = logging .getLogger (__name__ )
3839
3940
40- class QueueMode (enum .Enum ):
41- Batch = "Batch"
42- Dataset = "Dataset"
43-
44-
4541class Project (DbObject , Updateable , Deletable ):
4642 """ A Project is a container that includes a labeling frontend, an ontology,
4743 datasets and labels.
@@ -89,9 +85,12 @@ class Project(DbObject, Updateable, Deletable):
8985 benchmarks = Relationship .ToMany ("Benchmark" , False )
9086 ontology = Relationship .ToOne ("Ontology" , True )
9187
92- def update (self , ** kwargs ):
88+ class QueueMode (enum .Enum ):
89+ Batch = "Batch"
90+ Dataset = "Dataset"
9391
94- mode : Optional [QueueMode ] = kwargs .pop ("queue_mode" , None )
92+ def update (self , ** kwargs ):
93+ mode : Optional [Project .QueueMode ] = kwargs .pop ("queue_mode" , None )
9594 if mode :
9695 self ._update_queue_mode (mode )
9796
@@ -570,7 +569,7 @@ def setup(self, labeling_frontend, labeling_frontend_options) -> None:
570569 self .update (setup_complete = timestamp )
571570
572571 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
574573
575574 Args:
576575 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):
580579 """
581580
582581 # @TODO: make this automatic?
583- if self .queue_mode () != QueueMode .Batch :
582+ if self .queue_mode () != Project . QueueMode .Batch :
584583 raise ValueError ("Project must be in batch mode" )
585584
586585 dr_ids = []
587586 for dr in data_rows :
588-
589587 if isinstance (dr , Entity .DataRow ):
590588 dr_ids .append (dr .uid )
591589 elif isinstance (dr , str ):
592590 dr_ids .append (dr )
593591 else :
594- raise ValueError ("Must pass " )
592+ raise ValueError ("You can DataRow ids or DataRow objects " )
595593
596594 if len (dr_ids ) > 25_000 :
597595 raise ValueError (
@@ -618,8 +616,10 @@ def create_batch(self, name: str, data_rows: List[str], priority: int = 5):
618616 }
619617 }
620618
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+
623623 res ['size' ] = len (dr_ids )
624624 return Entity .Batch (self .client , res )
625625
@@ -628,9 +628,9 @@ def _update_queue_mode(self, mode: QueueMode) -> QueueMode:
628628 if self .queue_mode () == mode :
629629 return mode
630630
631- if mode == QueueMode .Batch :
631+ if mode == Project . QueueMode .Batch :
632632 status = "ENABLED"
633- elif mode == QueueMode .Dataset :
633+ elif mode == Project . QueueMode .Dataset :
634634 status = "DISABLED"
635635 else :
636636 raise ValueError (
@@ -666,9 +666,9 @@ def queue_mode(self) -> QueueMode:
666666 query_str , {'projectId' : self .uid })["project" ]["tagSetStatus" ]
667667
668668 if status == "ENABLED" :
669- return QueueMode .Batch
669+ return Project . QueueMode .Batch
670670 elif status == "DISABLED" :
671- return QueueMode .Dataset
671+ return Project . QueueMode .Dataset
672672 else :
673673 raise ValueError ("Status not known" )
674674
@@ -939,7 +939,7 @@ class LabelingParameterOverride(DbObject):
939939
940940LabelerPerformance = namedtuple (
941941 "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" )
943943LabelerPerformance .__doc__ = (
944944 "Named tuple containing info about a labeler's performance." )
945945
0 commit comments