
    	]j'                        d 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
 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 ddlmZmZ ddlmZmZ ddlmZ ddlmZ ddlm Z m!Z!  G d dejD                        Z# G d de      Z$ G d de      Z% G d dejD                        Z& G d dejD                        Z'ddgz  ddgz  ddgz  gZ( G d  d!ejR                        Z* G d" d#ejR                        Z+ G d$ d%ejR                        Z, G d& d'ejR                        Z- G d( d)e'      Z. G d* d+ejR                        Z/ G d, d-ee%      Z0 eejb                        Z2y).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.    )-replace_task_data_undefined_with_config_field)	load_func)
DataExportsettings)FSMStateField)is_video_object_tracking)extract_key_frames)InteractiveMixin)FlexFieldsModelSerializer)serializers)
AnnotationTask)AnnotationDraftSerializerPredictionSerializer)User)UserSimpleSerializer   )ConvertedFormatExportc                        e Zd Z G d d      Zy)CompletedBySerializerc                       e Zd ZeZg dZy)CompletedBySerializer.Meta)idemail
first_name	last_nameN)__name__
__module____qualname__r   modelfields     N/root/env/lib/python3.12/site-packages/label_studio/data_export/serializers.pyMetar      s    ;r%   r'   N)r   r    r!   r'   r$   r%   r&   r   r      s    < <r%   r   c                        e Zd Z ej                  d      Z ej                         Z ed      Z	 G d d      Z
 fdZd Z xZS )AnnotationSerializerT	read_onlyc                       e Zd ZeZdZdefiZy)AnnotationSerializer.Meta__all__completed_byN)r   r    r!   r   r"   r#   r   expandable_fieldsr$   r%   r&   r'   r-       s    +.C-EFr%   r'   c                     ddl m} ddlm} t        |   |      }|j                         } |d|      r
 |d|      s|j                  dd       |S )	zROverride to conditionally exclude FSM state field when feature flags are disabled.r   CurrentContextflag_set*fflag_feat_fit_568_finite_state_managementuser#fflag_feat_fit_710_fsm_state_fieldsstateN)core.current_requestr3   core.feature_flagsr5   superto_representationget_userpop)selfinstancer3   r5   retr8   	__class__s         r&   r>   z&AnnotationSerializer.to_representation%   sQ    7/g'1 &&(AM>TJGGGT"
r%   c                     |j                   rU| j                  j                  dd      r9t        |j                  j                               rt        |j                         S |j                   S )Ninterpolate_key_framesF)parsed_config)resultcontextgetr	   projectget_parsed_configr
   )rA   objs     r&   
get_resultzAnnotationSerializer.get_result6   sN     JJ  !95A(s{{7T7T7VW%cjj11zzr%   )r   r    r!   r   PrimaryKeyRelatedFieldr/   SerializerMethodFieldrH   r   r:   r'   r>   rN   __classcell__rD   s   @r&   r)   r)      sE    5;55EL.[..0FD)EG G
"r%   r)   c                        e Zd Z edd      Z ej                  d      Z ej                  dd      Z	 ej                  dd      Z
 ed      Z fdZ G d d      Z xZS )	BaseExportDataSerializerT)manyr+   file_upload_name)sourcer*   c                    ddl m} ddlm} t	        | dd       }||j
                  }t        | d|       |j                  }d| j                  v r6| j                  j                  dd      | j                  d   j                  d<   t        ||       t        | 5  |      }|j                         } |d|	      r
 |d
|	      s|j                  dd        |S )Nr   r2   r4   _projectannotationsrF   Fr6   r7   r9   r:   )r;   r3   r<   r5   getattrrK   setattrdatar#   rI   rJ   r   r=   r>   r?   r@   )	rA   taskr3   r5   rK   r]   rC   r8   rD   s	           r&   r>   z*BaseExportDataSerializer.to_representationI   s    7/ $
D1?llGD*g.yyDKK'KO<<K[K[(%LDKK&../GH 	6dGDg'- &&(AM>TJGGGT"
r%   c                   8    e Zd ZeZdZeddifeddifeddifdZ	y)BaseExportDataSerializer.Meta)overlap
is_labeledprecomputed_agreementrU   T)draftspredictionsrZ   N)
r   r    r!   r   r"   excluder   r   r)   r0   r$   r%   r&   r'   r`   g   s8    D064.A064.A064.A
r%   r'   )r   r    r!   r)   rZ   r   ReadOnlyFieldfile_uploadrO   rd   re   r   r:   r>   r'   rQ   rR   s   @r&   rT   rT   A   sc    &DDAK++++3EFK/[//TTJF4+44$$OKD)E<
 
r%   rT   c                   2     e Zd Z G d d      Z fdZ xZS )ConvertedFormatSerializerc                       e Zd ZeZg dZy)ConvertedFormatSerializer.Meta)r   statusexport_type	tracebackN)r   r    r!   r   r"   r#   r$   r%   r&   r'   rl   r   s    =r%   r'   c                 p    ddl m} t        |   |      }t	        |dd      s|j                  dd        |S )Nr   r   #SHOW_TRACEBACK_FOR_EXPORT_CONVERTERTro   )django.confr   r=   r>   r[   r@   )rA   rB   r   r]   rD   s       r&   r>   z+ConvertedFormatSerializer.to_representationv   s5    (w(2x!FMHH[$'r%   )r   r    r!   r'   r>   rQ   rR   s   @r&   rj   rj   q   s    > >	 	r%   rj   c                   F    e Zd Z G d d      Z ed      Z edd      Zy)ExportSerializerc                   $    e Zd ZeZg dZdgez   Zy)ExportSerializer.Meta)r   
created_by
created_atfinished_atrm   md5countersconverted_formatstitleN)r   r    r!   r   r"   r+   r#   r$   r%   r&   r'   rv      s    	
	 Y&r%   r'   F)requiredT)rU   r~   N)r   r    r!   r'   r   rw   rj   r|   r$   r%   r&   rt   rt      s%    ' ' &u5J1teLr%   rt      onlyrf   Nc                       e Zd Z ej                  dd      Z ej                  eddd      Z ej                  eddd      Z	 ej                  eddd      Z
 ej                  ddd	
      Zy)TaskFilterOptionsSerializerFz<Apply filters from the view ID (a tab from the Data Manager)r~   	help_textTzm`only` - include all tasks with skipped annotations<br>`exclude` - exclude all tasks with skipped annotations)choices
allow_nullr~   r   za`only` - include all finished tasks (is_labeled = true)<br>`exclude` - exclude all finished tasksz`only` - include all tasks with at least one not skipped annotation<br>`exclude` - exclude all tasks with at least one not skipped annotation defaultr~   r   N)r   r    r!   r   IntegerFieldviewChoiceFieldONLY_OR_EXCLUDE_CHOICEskippedfinished	annotatedBooleanFieldonly_with_annotationsr$   r%   r&   r   r      s    #;##"`D &k%%&A	G '{&&&u	H (''&Q	I 5K44UU^`ar%   r   c                       e Zd Z ej                  dddd      Z ej                  ddd      Z ej                  ddd      Zy)	!AnnotationFilterOptionsSerializerTFz4Include not skipped and not ground truth annotations)r   r~   r   r   z Include ground truth annotations)r   r~   r   zInclude skipped annotationsN)r   r    r!   r   r   usualground_truthr   r$   r%   r&   r   r      sS    $K$$%AwE ,;++%3UL 'k&&$RopGr%   r   c                       e Zd Z G d dej                        Z edd      Z edd      Z ej                  ddd      Z	 edd      Z
 ej                  ej                  dd      Zy	)
SerializationOptionsSerializerc                   6    e Zd Z ej                  ddd      Zy)2SerializationOptionsSerializer.SerializationOptionFz$Include a full json body or IDs onlyr   N)r   r    r!   r   r   only_idr$   r%   r&   SerializationOptionr      s    *+**E5[
r%   r   FzJSON dict with parametersr   zInclude annotation historyr   r   r~   zInterpolate video key framesN)r   r    r!   r   
Serializerr   rd   re   r   include_annotation_historyannotations__completed_byr   INTERPOLATE_KEY_FRAMESrF   r$   r%   r&   r   r      s}    
k44 

 !%;VWF%u@[\K!9!9!9!=" !4UNi j5[55//;Ydir%   r   c                   `    e Zd Z ej                  d      Z ej                  dd      Zd Zy)ExportConvertSerializerExport file format.)r    Download resources in converter.Fr   r~   c                     | j                   j                  d      }t        j                  |      D cg c]  }|d   	 }}||vrt	        j
                  | d      |S c c}w )NrK   namez is not supported export format)rI   rJ   r   get_export_formatsr   ValidationError)rA   valuerK   fexport_formatss        r&   validate_export_typez,ExportConvertSerializer.validate_export_type   sd    ,,""9--7-J-J7-ST!F)TT&--7V.WXX Us   AN)	r   r    r!   r   	CharFieldrn   r   download_resourcesr   r$   r%   r&   r   r      s1    '+''2GHK111<^inor%   r   c                   r    e Zd Z G d dej                        Z edd      Z edd      Z e	dd      Z
y)ExportCreateSerializerc                   B    e Zd Zej                  j
                  g dz   Zy)ExportCreateSerializer.Meta)task_filter_optionsannotation_filter_optionsserialization_optionsN)r   r    r!   rt   r'   r#   r$   r%   r&   r'   r      s    !&&-- 1
 
r%   r'   FN)r~   r   )r   r    r!   rt   r'   r   r   r   r   r   r   r$   r%   r&   r   r      s@    
$$ 
 6udS A5Z^ _:ESWXr%   r   c                      e Zd Z ej                  ej                  dd      Z ej                  ej                  dd      Z	 ej                  ddd      Z ej                  dd      Z ej                  ddd      Zy	)
ExportParamSerializerzInterpolate video key frames.Fr   r   JSONr   r   z$Download all tasks or only finished.N)r   r    r!   r   r   r   r   rF   CONVERTER_DOWNLOAD_RESOURCESr   r   rn   
exportTypedownload_all_tasksr$   r%   r&   r   r      s    5[55//;Zej 21155Acns (+''BWbghK&&&1FQVWJ111!GRWr%   r   c                       e Zd Zy)&BaseExportDataSerializerForInteractiveN)r   r    r!   r$   r%   r&   r   r      s    r%   r   )3__doc__core.label_configr   core.utils.commonr   data_export.modelsr   rr   r   fsm.serializer_fieldsr   Alabel_studio_sdk._extensions.label_studio_tools.core.label_configr	   Dlabel_studio_sdk._extensions.label_studio_tools.postprocessing.videor
   	ml.mixinsr   rest_flex_fieldsr   rest_frameworkr   tasks.modelsr   r   tasks.serializersr   r   users.modelsr   users.serializersr   modelsr   r   ModelSerializerr   r)   rT   rj   rt   r   r   r   r   r   r   r   r   r   EXPORT_DATA_SERIALIZERExportDataSerializerr$   r%   r&   <module>r      sA   l K ' )   / f c & 6 & ) M  2 +<K77 <#4 #L-
8 -
` ; ; "M{22 M( LOJ b+"8"8 b6q(>(> q[%;%; "	k44 	
Y- 
YK22 	-=?W 	 !!@!@A r%   