o
    %Ki                     @   s   d dl mZmZ d dlmZmZ d dl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 edd	gd
ZeddefddZedde	fddZdS )    )	APIRouterHTTPException)DictListN)StartHumanOSRequestAnswerHumanOSRequest)human_os_questionshuman_os_scoring)human_os_module)loggerz/goalskill-sales/api/human_osHumanOS)prefixtagsz/startrequestc              
      s   z*t | j t }|stddd|d }|d |d |d |d d	t|d
W S  tyG } zt	d|  tdt
|dd }~ww )N  zNo questions availablestatus_codedetailr   idtypetextoptions   question_idquestion_typequestion_textr   currenttotalzHumanOS Start Error: )r
   clear_session_logs
session_idr   get_all_questionsr   len	Exceptionr   errorstr)r   all_questionsfirst_questione r)   =/home/air/goalskill_sales/back/app/routers/human_os_router.pystart_human_os   s&   r+   z/answerc              
      s&  zu| j }d|v r|dd  }tj| j| j|| jd t| j}t	
 }t|}||krZt| j}t|\}}t|}tj|dd}	t| j|	| dd|dd	W S || }
d
|
d |
d |
d |
d |d t|ddW S  ty } ztd|  tdt|dd }~ww )N:r   )r    r   selected_optionvalueF)ensure_ascii	completedu%   HumanOS診断が完了しました。)summaryscores)statusresultcontinuer   r   r   r   r   r   )r3   next_questionzHumanOS Answer Error: r   r   )r-   splitstripr
   save_answerr    r   r.   get_answer_countr   r!   r"   get_all_answersr	   calculate_human_osformat_for_dbjsondumpssave_or_update_outputr#   r   r$   r   r%   )r   
option_valanswered_countr&   total_questionsanswersaxis_resultoverall_score	db_resultnode_score_jsonr6   r(   r)   r)   r*   answer_human_os)   sP   
	rI   )fastapir   r   typingr   r   r>   app.schemas.human_os_schemar   r   app.servicesr   r	   
app.modelsr
   app.core.configr   routerpostr+   rI   r)   r)   r)   r*   <module>   s    