U
    ¿d!                     @   sb   d Z ddlmZ e Zdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd ZdS )a;  
Appraise evaluation framework

See LICENSE for usage details

Keeps a registry of deprecated methods.

Use @add_deprecated_method decorator to mark method as deprecated. This
needs to be placed closest relative to the deprecated method for now.

Use get_deprecated_methods() to retrieve set of deprecated methods.
    )Setc                 C   s   t | j | S )z,
    Add deprecated method to registry.
    )_DEPRECATED_METHOD_REGISTRYadd__name__)func r   9/var/www/rival/public_html/translation-eval/deprecated.pyadd_deprecated_method   s    r	   c                   C   s   t S )z/
    Get deprecated methods from registry.
    )r   r   r   r   r   get_deprecated_methods   s    r
   c                 C   s   t  }ddi}|t t  }tjjdd}t  }g }|dD ]j}|j	 j
jj}|j	 j
jj}	|j }
|j }||j||	|
td|
 d |td| d f qFt  }|||| || || || fd	| jkd
 t| d|S )
    Appraise system status page.

    Used to be @login_required method in Dashboard.views.
    Method has been deprecated on 7/08/2019.
    active_pagesystem-status%   )Zid__gteidd   g      @g      y@debugtask_statusdebug_timestemplate_debugDashboard/metrics-status.html)datetimenowupdateBASE_CONTEXTDirectAssessmentTaskobjectsfilterorder_byitemsfirstmetadatamarketsourceLanguageCodetargetLanguageCode
assignedTocount$evaldata_directassessmentresult_taskappendr   roundGETrenderrequest_t1context_t2Z	task_data_t3r   taskZsource_languageZtarget_languageZ
annotatorsresults_t4r   r   r   fe17_status#   s<    


r5   c           
   
   C   s   t  }ddi}|t t  }t }t  }g }|D ]$}|||| d || d f q:t|dd dd}t  }	|t|t	d	d
 |D t	dd
 |D || || |	| |	| fd| j
kd t| d|S )z
    Appraise group status page.

    Used to be @login_required method in Dashboard.views.
    Method has been deprecated on 7/08/2019.
    r   group-statusr      c                 S   s   | d S Nr7   r   xr   r   r   <lambda>c       zgroup_status.<locals>.<lambda>Tkeyreversec                 S   s   g | ]}|d  qS r7   r   .0r:   r   r   r   
<listcomp>i   s     z group_status.<locals>.<listcomp>c                 S   s   g | ]}|d  qS    r   rA   r   r   r   rC   j   s     r   group_statusZsum_completedZ	sum_totalr   r   Dashboard/group-status.html)r   r   r   r   DirectAssessmentResultcompute_accurate_group_statusr(   sortedlistsumr*   r+   
r-   r.   r/   r0   Z
group_datar1   Z_group_statusgroupsorted_statusr4   r   r   r   rG   O   s(    
"
rG   c                 C   s  t  }ddi}|t t  }tjjdd tdD d}t  }g }|dD ]j}|j	
 jjj}|j	
 jjj}	|j }
|j }||j||	|
td|
 d	 |td| d
 f qTt  }|||| || || || fd| jkd t| d|S )r   r   r   c                 S   s   g | ]}|d  qS )i3  r   rA   r   r   r   rC      s     z"metrics_status.<locals>.<listcomp>0   )Zid__inr   r   g      .@g     h@r   r   r   )r   r   r   r   r   r   r   ranger   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r   r)   r*   r+   r,   r   r   r   metrics_statuss   s@    


rS   c           
   
   C   s   t  }ddi}|t t  }t }t  }g }|D ]$}|||| d || d f q:t|dd dd}t  }	|t|t	d	d
 |D t	dd
 |D || || |	| |	| fd| j
kd t| d|S )z
    Appraise group status page.

    Used to be @login_required method in Dashboard.views.
    Method has been deprecated on 7/08/2019.

    r   r6   r   r7   c                 S   s   | d S r8   r   r9   r   r   r   r;      r<   z#multimodal_status.<locals>.<lambda>Tr=   c                 S   s   g | ]}|d  qS r@   r   rA   r   r   r   rC      s     z%multimodal_status.<locals>.<listcomp>c                 S   s   g | ]}|d  qS rD   r   rA   r   r   r   rC      s     r   rF   rH   )r   r   r   r   MultiModalAssessmentResultrJ   r(   rK   rL   rM   r*   r+   rN   r   r   r   multimodal_status   s(    
"
rU   c              	   C   s   t  }ddi}|t t  }tjdd}t  }g }d}|D ]@}|| sPqB|| D ](}	|||	d |	d f ||	d 7 }qXqBt  }
||||| || |
| |
| fd| jkd t| d|S 	r   r   r   r7   )
sort_indexr   r   )system_statustotal_completedr   r   zDashboard/system-status.html)	r   r   r   r   rT   get_system_statusr(   r*   r+   r-   r.   r/   r0   system_datar1   rP   rY   codedatar4   r   r   r   multimodal_systems   s.    
	r_   c                 C   s   ddl m} |jj|d}|jj|d}| jj|d}|  }||_|j|_|  |j D ]}|j	
| q\|j	 D ]}|j	
| qx|  t|j }	|	|j	  t|j	 }
|	|
fS )z
    Reassigns tasks in TaskAgenda for old user to new user.

    Used to be @classmethod in EvalData.models.TaskAgenda.
    Method has been deprecated on 5/27/2019.
    r   )User)username)user)django.contrib.auth.modelsr`   r   getrb   campaignsave_completed_tasksall_open_tasksr   rL   extend)clsold_usernamenew_usernamer`   Zold_userZnew_userZ
old_agendaZ
new_agendaZ_tZ	old_tasksZ	new_tasksr   r   r   reassign_tasks   s"    rn   c              	   C   s   t  }ddi}|t t  }tjdd}t  }g }d}|D ]@}|| sPqB|| D ](}	|||	d |	d f ||	d 7 }qXqBt  }
||||| || |
| |
| fd| jkd t| d|S rV   )	r   r   r   r   rI   rZ   r(   r*   r+   r[   r   r   r   rX     s.    
	rX   N)__doc__typingr   setr   r	   r
   r5   rG   rS   rU   r_   rn   rX   r   r   r   r   <module>   s   ,$.%'