
    	]j              	           U d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZ  ej                  e      Z e       Zd Zdd	Zd
 Zd Zeej,                  dddddeddgZee   ed<   y)zThis file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
    N)AllPermissions)start_job_async_or_sync)DataManagerAction)LabelInterface)
Annotation
PredictionTaskc                 >   |d   }|j                  dd      j                         }|dv sJ d       |dk(  rt        nt        }|j                  d      xs |j                  d      }|j                  dd	      j                         d
k(  }t	        | j
                        }|j                  d      D 	ci c]  }	|	j                  |	 }
}	|dk(  rd}nd}|dk(  s|d }| d}n| d| }t        |j                  d            }t        j                  dt        |       d|        |D ]  }g }|j                  j                  |      j                  d      }|D ]   }t        |||
      }|j!                  |       " |rSdj#                  t%        t'        |      D cg c]  }| d|j)                  |        c}            |j*                  |<   dj#                  t%        t        t'        |                        |j*                  |<    t,        j                  j/                  |dgd       t,        j                  j                  |j1                         j2                        }| j4                  j7                  |g       ddt        |       ddS c c}	w c c}w )Nrequest_datasourceannotations)r   predictionsz)Source must be annotations or predictionscustom_control_tagcontrol_tagwith_countersYesyescontrolcachecache_predictionsALL_all_datazCache labels for z tasks and control tag )taskresultz, z: i  )fields
batch_size)id   zUpdated z tasks)response_codedetail)getlowerr   r   r   label_config	find_tagsnamelistonlyloggerinfolenobjectsfilterextract_labelsextendjoinsortedsetcountr   r	   bulk_updatefirstr   summaryupdate_data_columns)projectquerysetkwargsr   r   source_classr   r   label_interfacetaglabel_interface_tagscolumn_nametasksr   task_labelsr   
annotationlabelslabel
first_tasks                       X/root/env/lib/python3.12/site-packages/label_studio/data_manager/actions/cache_labels.pycache_labels_jobrH      s   .)Lh6<<>F33`5``3!'=!8:jL""#78[L<L<L]<[K $$_e<BBDMM$W%9%9:O5D5N5Ny5YZcCHHcMZZ) e{2$T*$Q{m4v&'E
KK#CJ</F{mTU O"**11t1<AA(K% 	'J#J=QRFv&	' %)YYCP[L\]55'K$5$5e$<#=>]^&DIIk"
 &*YYvd3{;K6L/M%NDIIk"O" 	LLUF8E!!X^^%5%8%8!9JOO''5 hs5zl&,IJJK [8 ^s   1JJc                 V   g }| j                   D ]  }|	|d   |k(  sd|v s|d   D ]  }|d   |   st        |d   |   t              s#|dk(  rd}d}|G|d   |v r@||d      }|j                  j	                  dd      }|j                  j	                  dd      }|dk(  r"|d   |   D ]  }	|j                  |	d	           n^|d   |   D ]"  }	|j                  |j                  |	             $ n0t        |d   |   d
   t              r|j                  |d   |             |S )N	from_namevaluetaxonomytrue/showFullPathfalsepathSeparatorr   )	r   
isinstancer(   attrr#   appendr1   strr0   )
rC   r   r?   rD   regionkeyrO   rQ   label_interface_tagelemss
             rG   r/   r/   @   sl   F## 6+#6+#E7V\K\ g '?3'Jvgs7KT,Rj('-(+/;{@SWk@k2FvkGZ2[/+>+C+C+G+GX_+`L,?,D,D,H,HZ],^M'72)/)= 9 &eBi 89 *0)= I &m.@.@.G HI $F7OC$8$;SAfWoc&:;/: M    c                 \    t        t        | || j                  |j                  d       ddiS )z6Cache labels from annotations to a new column in tasksiPF  )organization_idr   job_timeoutr!   r    )r   rH   r]   r   )r9   r:   requestr;   s       rG   cache_labelsr`   b   s3    //\\ S!!r[   c           	          |j                         }dg}|j                         D ]  \  }}|j                  |        dddd|dddd	d
dddddgddddddgdgdgS )Nr      selectr   zChoose a control tag)typer'   rE   optionsinputr   z.Custom control tag if it's not in label config)rd   r'   rE   r   zWith countersr   Nor   SourceAnnotationsPredictions)columnCountr   )get_parsed_configitemsrU   )userr9   rD   control_tagsrX   r   s         rG   cache_labels_formrp   o   s    &&(F7L,,. !QC !
  %)3+	 $0M %+, %t}	 %$% -}=	%	
 r[   zCache Labelsrb   TzConfirm that you want to add a new task.data field with cached labels from annotations. This field will help you to quickly filter or order tasks by labels. After this operation you must refresh the Data Manager page fully to see the new column!confirm)textrd   form)entry_point
permissiontitleorderexperimentaldialogactions)N)__doc__loggingcore.permissionsr   
core.redisr   data_manager.actionsr    label_studio_sdk.label_interfacer   tasks.modelsr   r   r	   	getLogger__name__r*   all_permissionsrH   r/   r`   rp   projects_changerz   r(   __annotations__ r[   rG   <module>r      s     + . 2 ; 5 5			8	$ "-K`D
"#P $%55g %
$	  r[   