a
    C7f5                     @   s   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 e Zejded	eeeeeed
ddZdS )    )	APIRouter)Dict)TfidfVectorizer)AgglomerativeClustering)determine_cluster_keyword)get_data_from_webmaster)SIMILARITY_THRESHOLDz/clusterize)response_model)userhostsaccess_tokenquery_indicatororder_byreturnc                    s   t | ||||}g }|D ]}||d  qt }||}	t}
td dd|
d}||	 }i }t||D ].\}}t	|}||vrg ||< || | ql|S )N	processedZcosineZaverage)Z
n_clustersZaffinitylinkageZdistance_threshold)
r   appendr   Zfit_transformr   r   Zfit_predictZtoarrayzipint)r
   r   r   r   r   dataZkey_stringsrowZ
vectorizerZtfidf_matrix	thresholdZ
clusteringZcluster_labelsZclustered_dataZ
cluster_idZ
data_pointZcluster_id_int r   8D:\eodhd\seo\seo_app\app\api\routes\public\v1\cluster.pymake_clusters   s     
r   N)fastapir   typingr   Zsklearn.feature_extraction.textr   Zsklearn.clusterr   Z1app.core.internal_funcs.determine_cluster_keywordr   Z/app.core.internal_funcs.get_data_from_webmasterr   Zapp.core.enumr   routergetstrr   r   r   r   r   <module>   s   