
    	]j                     R    d dl mZ d dlmZ d dlmZ d dlmZmZ dZ	dZ
d Zd Zd	 Zy
)    )settings)transaction)LabelStreamHistory)
AnnotationTasktaskIdannotationIdc                 @   | 
t        j                         5  t        j                  j	                  ||      \  }}t
        | j                  t        d i}|r	|g|_        nt        |j                  D cg c]  }|t
            c}      }| j                  |vr|j                  j                  |       t        |      dz   t        j                  kD  r#|j                  t        j                   d  |_        |j                          d d d        y y c c}w # 1 sw Y   y xY w)N)userproject   )r   atomicr   objectsget_or_createTASK_ID_KEYidANNOTATION_ID_KEYdatasetappendlenr   LABEL_STREAM_HISTORY_LIMITsave)	next_taskr   r   historycreatednew_history_datahtask_idss           X/root/env/lib/python3.12/site-packages/label_studio/projects/functions/stream_history.pyadd_stream_historyr!   
   s    ! 	199GGT[bGcGW +Y\\;LdS 01E1+EF<<x/LL''(89x=1$x'J'JJ#*<<1T1T0T0V#WGLLLN	 	   F	 	s   AD3D
BDDDc                 "   | j                   j                  |j                        j                         }|rY|j                  rL|j                  D ],  }|t
           |j                  k(  s|j                  |t        <   . |j                          y y y )Nr   )		historiesfilterr   firstr   r   r   r   r   )r   task
annotationr   items        r    fill_history_annotationr*      st    nn##DLL#9??AG7<<LL 	8DK DGG+*4--&'	8 		  w    c                 0   g }t        j                         5  | j                  j                  |      j	                         }||cd d d        S |j
                  }t        |j
                  D cg c]  }|t            c}      }t        |j
                  D cg c]  }|t            c}      }t        t        j                  j                  |      j                  dd            }t        t        j                  j                  |      j                  dd            }	g }|D ]3  }
|
t           |vr|
t           |	vr	d |
t        <   |j                  |
       5 ||_        |j                  dg       d d d        |S c c}w c c}w # 1 sw Y   |S xY w)Nr#   )pk__inr   T)flatr   )update_fields)r   r   r$   r%   r&   r   r   r   r   r   r   values_listr   r   r   )r   r   resultr   r   r   r   annotation_idsexisting_task_idsexisting_annotation_idsr)   s              r    get_label_stream_historyr5   #   sv   F				 -..'''8>>@?- -
 ||=1+=>GLLIqa 12IJ 3 38 3 D P PQU\` P ab"%j&8&8&?&?~&?&V&b&bcgnr&b&s"t 	 DK (99%&.EE*.&'MM$	  F8,)-, M >I-, Ms0   .FF.F
>FF
(CF
FFN)django.confr   	django.dbr   projects.modelsr   tasks.modelsr   r   r   r   r!   r*   r5    r+   r    <module>r;      s+      ! . )"  r+   