o
    Ah
                     @   s:   d dl Z d dlmZmZ d dlZg dZG dd dZdS )    N)ListTuple)Jacoustic
aggressiveanthemicatmosphericbouncychilldarkdreamy
electronic	emotionalepicexperimental
futuristicgroovy	heartfelt
infectiousmelodicmellowpowerfulpsychedelicromanticsmooth
syncopated	upliftingafrobeatanimeballadzbedroom pop	bluegrassblues	classicalcountrycumbiadancezdelta blues
electropopdiscozdrum and bassedmemofolkfunkzfuture bassgospelgrungegrimezhip hophouseindiezj-popjazzzk-popz
kids musicmetalznew jack swingznew waveoperapunkragarapreggae	reggaetonrockrumbasalsasamba	sertanejosoulsynthpopswing	synthwavetechnotrapz	uk garagec                   @   sR   e Zd ZdddZdd Zded	eeeef  fd
dZ	ded	ee fddZ
dS )RedisTagManager	localhost  r   c                 C   s   t j|||dd| _d S )NT)hostportdbZdecode_responses)redisZRedisredis_client)selfrF   rG   rH    rL   //Users/zoeshleifer/deejay-suno/redis_manager.py__init__S   s   zRedisTagManager.__init__c              
   C   s   i }d}	 | j j|ddd\}}|D ]&}zt| j |pd}||t|tr*| n|< W q ttfy8   Y qw |dkr@	 |S q)Nr   T*i  )cursormatchcount)	rJ   scanintget
isinstancebytesdecode
ValueError	TypeError)rK   tagsrP   keyskeyZvotesrL   rL   rM   get_all_tagsW   s   zRedisTagManager.get_all_tagsnreturnc                 C   sl   |   }t| dd dd}t|dkr dd tt|D S t||k r0td| d	 |S |d
| S )z(Get the top N tags sorted by vote count.c                 S   s   | d S )N   rL   )xrL   rL   rM   <lambda>i   s    z.RedisTagManager.get_top_tags.<locals>.<lambda>T)r]   reverser   c                 S   s   g | ]}|d fqS r   rL   .0tagrL   rL   rM   
<listcomp>k       z0RedisTagManager.get_top_tags.<locals>.<listcomp>z********* sorted_tags: z
 *********N)r^   sorteditemslenrandomsampleRAND_TAG_LISTprint)rK   r_   r[   Zsorted_tagsrL   rL   rM   get_top_tagse   s   zRedisTagManager.get_top_tagsc                 C   s&   |  |}dd |D }| j  |S )z-Get top N tags and clear the entire database.c                 S   s   g | ]}|d  qS re   rL   rf   rL   rL   rM   ri   s   rj   z6RedisTagManager.get_and_reset_tags.<locals>.<listcomp>)rr   rJ   Zflushdb)rK   r_   Ztop_tagsZ	tag_namesrL   rL   rM   get_and_reset_tagsp   s   

z"RedisTagManager.get_and_reset_tagsN)rD   rE   r   )__name__
__module____qualname__rN   r^   rT   r   r   strrr   rs   rL   rL   rL   rM   rC   R   s
    
rC   )rI   typingr   r   rn   rp   rC   rL   rL   rL   rM   <module>   s
   M