Ë
    	]j¸  ã                   ó^   — d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ  G d„ de«      Zy	)
z<Tests for projects.models (Project model and related logic).é    )ÚTestCase)ÚProjectFactory)ÚTask)ÚAnnotationFactoryÚTaskFactory)Úmock_feature_flagc                   óv   — e Zd ZdZ eddd¬«      d„ «       Z eddd¬«      d„ «       Z eddd¬«      d	„ «       Zy
)ÚTestRearrangeOverlapCohorta!  
    Tests for Project._rearrange_overlap_cohort().

    Covers overlap cohort assignment when overlap_cohort_percentage < 100:
    correct cohort size, deterministic vs random tie-breaking (feature flag),
    and prioritization of tasks with more annotations (progress preservation).
    Ú+fflag_feat_utc_563_randomize_overlap_cohortTzprojects.models)Úparent_modulec                 ó²  — d}d}t        ||z  dz  dz   «      }t        d|¬«      }t        j                  ||¬«       t	        «       }t        d«      D ]n  }|j                  «        t        t        j                  j                  |d	¬
«      j                  dd¬«      «      }t        |«      |k(  sJ ‚|j                  |«       Œp t        |«      dk\  sJ d«       ‚y)a$  
        With fflag_feat_utc_563_randomize_overlap_cohort on, cohort selection
        varies across runs because tie-breaking within same annotation count
        is random. Expected: at least 2 distinct cohort ID sets over 10 runs,
        and cohort size always equals must_tasks.
        é   é   éd   ç      à?é   ©Úmaximum_annotationsÚoverlap_cohort_percentage©Úprojecté
   é   ©r   Úoverlap__gtÚidT©ÚflatzLRandom tie-breaking should produce at least 2 different cohorts over 10 runsN)Úintr   r   Úcreate_batchÚsetÚrangeÚ_rearrange_overlap_cohortÚ	frozensetr   ÚobjectsÚfilterÚvalues_listÚlenÚadd)ÚselfÚ	num_tasksÚoverlap_cohort_pctÚexpected_cohort_sizer   Úcohorts_seenÚ_Ú
cohort_idss           úQ/root/env/lib/python3.12/site-packages/label_studio/projects/tests/test_models.pyÚtest_randomize_when_flag_onz6TestRearrangeOverlapCohort.test_randomize_when_flag_on   sß   € ð ˆ	ØÐÜ" 9Ð/AÑ#AÀCÑ#GÈ#Ñ#MÓNÐÜ Ø !Ø&8ô
ˆô 	× Ñ  °GÕ<ä“uˆÜr“ò 	)ˆAØ×-Ñ-Ô/Ü"¤4§<¡<×#6Ñ#6¸wÐTUÐ#6Ó#V×#bÑ#bÐcgÐnrÐ#bÓ#sÓtˆJÜz“?Ð&:Ò:Ð:Ð:Ø×Ñ˜ZÕ(ð		)ô
 <Ó  AÒ%ÐuÐ'uÓuÑ%ó    Fc                 óÖ  — d}d}t        ||z  dz  dz   «      }t        d|¬«      }t        j                  ||¬«       |j	                  «        t        t        j                  j                  |d¬	«      j                  d
d¬«      «      }|j	                  «        t        t        j                  j                  |d¬	«      j                  d
d¬«      «      }t        |«      |k(  sJ ‚||k(  sJ ‚y)zÏ
        With fflag_feat_utc_563_randomize_overlap_cohort off, cohort selection
        is deterministic. Expected: two consecutive runs yield the same cohort
        ID set and correct cohort size.
        r   r   r   r   r   r   r   r   r   r   Tr   N)r   r   r   r    r#   r$   r   r%   r&   r'   r(   )r*   r+   r,   r-   r   Úcohort_firstÚcohort_seconds          r1   Ú test_deterministic_when_flag_offz;TestRearrangeOverlapCohort.test_deterministic_when_flag_off+   sè   € ð ˆ	ØÐÜ" 9Ð/AÑ#AÀCÑ#GÈ#Ñ#MÓNÐÜ Ø !Ø&8ô
ˆô 	× Ñ  °GÕ<à×)Ñ)Ô+Ü ¤§¡×!4Ñ!4¸WÐRSÐ!4Ó!T×!`Ñ!`ÐaeÐlpÐ!`Ó!qÓrˆØ×)Ñ)Ô+Ü!¤$§,¡,×"5Ñ"5¸gÐSTÐ"5Ó"U×"aÑ"aÐbfÐmqÐ"aÓ"rÓsˆÜ<Ó Ð$8Ò8Ð8Ð8Ø˜}Ò,Ð,Ñ,r3   c           
      óÄ  — d}d}t        ||z  dz  dz   «      }t        d|¬«      }t        j                  ||¬«      }|dd D ]  }t	        ||d	d
giddd	dœgdd¬«       Œ |j                  «        t        t        j                  j                  |d¬«      j                  dd¬«      «      }t        |«      |k(  sJ ‚|d   j                  |v sJ ‚|d   j                  |v sJ ‚y)zë
        Tasks with more finished annotations are prioritized into the cohort
        (progress preserved). With flag on, only tie-breaking is random.
        Expected: tasks that already have one annotation are in the cohort.
        r   é   r   r   r   r   r   NÚchoicesÚAÚ
text_classÚtext)ÚvalueÚ	from_nameÚto_nameÚtypeF)Útaskr   ÚresultÚwas_cancelledÚground_truthr   r   r   Tr   r   )r   r   r   r    r   r#   r!   r   r%   r&   r'   r(   r   )r*   r+   r,   r-   r   ÚtasksÚtr0   s           r1   Ú$test_preserves_progress_when_flag_onz?TestRearrangeOverlapCohort.test_preserves_progress_when_flag_onB   s  € ð ˆ	ØÐÜ" 9Ð/AÑ#AÀCÑ#GÈ#Ñ#MÓNÐÜ Ø !Ø&8ô
ˆô ×(Ñ(¨¸GÔDˆØr˜ò 	ˆAÜØØð #,¨c¨UÐ!3Ø%1Ø#)Ø )ñ	ðð $Ø"öð	ð  	×)Ñ)Ô+äœŸ™×,Ñ,°WÈ!Ð,ÓL×XÑXÐY]ÐdhÐXÓiÓjˆ
Ü:‹Ð"6Ò6Ð6Ð6ØQ‰x{‰{˜jÑ(Ð(Ð(ØQ‰x{‰{˜jÑ(Ð(Ñ(r3   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r2   r7   rH   © r3   r1   r
   r
   	   si   „ ññ ÐDÀdÐZkÔlñvó mðvñ0 ÐDÀeÐ[lÔmñ-ó nð-ñ, ÐDÀdÐZkÔlñ#)ó mñ#)r3   r
   N)rL   Údjango.testr   Úprojects.tests.factoriesr   Útasks.modelsr   Útasks.tests.factoriesr   r   Útests.utilsr   r
   rM   r3   r1   ú<module>rS      s%   ðÙ BÝ  Ý 3Ý ß @Ý )ô]) õ ])r3   